Skip to content

Commit

Permalink
fix: added websocket notifier in REST controller handlers
Browse files Browse the repository at this point in the history
- Part of hyperledger-archives#471

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Feb 26, 2020
1 parent e4d0b76 commit 3d64347
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/aries-js-worker/index.html
Expand Up @@ -106,7 +106,7 @@
document.getElementById("mode-label").innerHTML = `Running in ${mode} mode`

if (src == "rest"){
document.getElementById("opts").innerHTML = `{"assetsPath": "/dist/assets", "agent-rest-url": "http://localhost:8082", "agent-rest-wshook":"ws://localhost:8881"}`
document.getElementById("opts").innerHTML = `{"assetsPath": "/dist/assets", "agent-rest-url": "http://localhost:8082", "agent-rest-wshook":"ws://localhost:8082/ws"}`
} else {
document.getElementById("opts").innerHTML = `{"assetsPath": "/dist/assets", "agent-default-label":"dem-js-agent","http-resolver-url":[],"auto-accept":true,"outbound-transport":["ws","http"],"transport-return-route":"all","log-level":"debug"}`
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/aries-js-worker/src/worker-impl-rest.js
Expand Up @@ -84,7 +84,7 @@ const wsnotifier = class {
this.socket.addEventListener('message', function (event) {
// TODO REST agents are not currently revealing topic information on incoming messages,
// Once REST supports this feature, topic value will be dynamic. [Issue #1323]
postMsg(newResponse(Math.random().toString(36).slice(2), event.data, "", "all"));
postMsg(newResponse(Math.random().toString(36).slice(2), JSON.parse(event.data), "", "all"));
});
}
stop(){
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/controller.go
Expand Up @@ -122,11 +122,16 @@ func GetRESTHandlers(ctx *context.Provider, opts ...Opt) ([]rest.Handler, error)
allHandlers = append(allHandlers, routeOp.GetRESTHandlers()...)
allHandlers = append(allHandlers, verifiablecmd.GetRESTHandlers()...)

nhp, ok := notifier.(handlerProvider)
if ok {
allHandlers = append(allHandlers, nhp.GetRESTHandlers()...)
}

return allHandlers, nil
}

type handlerProvider interface {
GetHandlers() []command.Handler
GetRESTHandlers() []rest.Handler
}

// GetCommandHandlers returns all command handlers provided by controller.
Expand Down Expand Up @@ -177,10 +182,5 @@ func GetCommandHandlers(ctx *context.Provider, opts ...Opt) ([]command.Handler,
allHandlers = append(allHandlers, routecmd.GetHandlers()...)
allHandlers = append(allHandlers, verifiablecmd.GetHandlers()...)

nhp, ok := notifier.(handlerProvider)
if ok {
allHandlers = append(allHandlers, nhp.GetHandlers()...)
}

return allHandlers, nil
}

0 comments on commit 3d64347

Please sign in to comment.