From 6c1c2e2927a0b7124143f1cadb845cea47f1a8b0 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 10 Mar 2018 13:12:22 -0500 Subject: [PATCH] add dashboard endpoint --- lib/modules/webserver/server.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 0420b319..65adfaab 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -37,10 +37,26 @@ class Server { self.events.on("log", function(logLevel, logMsg) { ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {}); }); - ws.on('message', function(msg) { - console.dir("got message"); - console.dir(msg); - ws.send(msg, () => {}); + }); + + app.ws('/dashboard', function(ws, req) { + let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] }; + + self.events.on('contractsState', (contracts) => { + dashboardState.contractsState = []; + + contracts.forEach(function (row) { + dashboardState.contractsState.push({contractName: row[0], address: row[1], status: row[2]}); + }); + ws.send(dashboardState); + }); + self.events.on('status', (status) => { + dashboardState.status = status; + ws.send(dashboardState); + }); + self.events.on('servicesState', (servicesState) => { + dashboardState.availableServices = servicesState; + ws.send(dashboardState); }); });