add dashboard endpoint

This commit is contained in:
Iuri Matias 2018-03-10 13:12:22 -05:00 committed by Pascal Precht
parent 8bf344e4a0
commit be68625c01
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 20 additions and 4 deletions

View File

@ -71,10 +71,26 @@ class Server {
self.events.on("log", function(logLevel, logMsg) { self.events.on("log", function(logLevel, logMsg) {
ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {}); ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {});
}); });
ws.on('message', function(msg) { });
console.dir("got message");
console.dir(msg); app.ws('/dashboard', function(ws, req) {
ws.send(msg, () => {}); 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);
}); });
}); });