From 3d64347263afc2f90d4d960420454086fe3d47d7 Mon Sep 17 00:00:00 2001 From: "sudesh.shetty" Date: Wed, 26 Feb 2020 17:20:23 -0500 Subject: [PATCH] fix: added websocket notifier in REST controller handlers - Part of #471 Signed-off-by: sudesh.shetty --- cmd/aries-js-worker/index.html | 2 +- cmd/aries-js-worker/src/worker-impl-rest.js | 2 +- pkg/controller/controller.go | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/aries-js-worker/index.html b/cmd/aries-js-worker/index.html index 1b69829b84..e37a44b408 100644 --- a/cmd/aries-js-worker/index.html +++ b/cmd/aries-js-worker/index.html @@ -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"}` } diff --git a/cmd/aries-js-worker/src/worker-impl-rest.js b/cmd/aries-js-worker/src/worker-impl-rest.js index 1f12fdcc1c..29d0093b57 100644 --- a/cmd/aries-js-worker/src/worker-impl-rest.js +++ b/cmd/aries-js-worker/src/worker-impl-rest.js @@ -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(){ diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 3449f41df0..aa3b74e14c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -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. @@ -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 }