diff --git a/cmd/dashboard/dashboard.js b/cmd/dashboard/dashboard.js index 12715b78..79a318cc 100644 --- a/cmd/dashboard/dashboard.js +++ b/cmd/dashboard/dashboard.js @@ -27,6 +27,35 @@ class Dashboard { monitor = new Monitor({env: this.env, events: this.events}); this.logger.logFunction = monitor.logEntry; + let plugin = this.plugins.createPlugin('dashboard', {}); + plugin.registerAPICall( + 'ws', + '/embark/dashboard', + (ws, req) => { + let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] }; + + // TODO: doesn't feel quite right, should be refactored into a shared + // dashboard state + self.events.request('setDashboardState'); + + 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(JSON.stringify(dashboardState)); + }); + self.events.on('status', (status) => { + dashboardState.status = status; + ws.send(JSON.stringify(dashboardState)); + }); + self.events.on('servicesState', (servicesState) => { + dashboardState.availableServices = servicesState; + ws.send(JSON.stringify(dashboardState)); + }); + } + ); this.events.on('contractsState', monitor.setContracts); this.events.on('status', monitor.setStatus.bind(monitor)); diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 5871479e..e9f4c1fc 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -73,30 +73,10 @@ class Server { }); }); - app.ws('/embark/dashboard', function(ws, req) { - let dashboardState = { contractsState: [], environment: "", status: "", availableServices: [] }; - - // TODO: doesn't feel quite right, should be refactored into a shared - // dashboard state - self.events.request('setDashboardState'); - - 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(JSON.stringify(dashboardState)); - }); - self.events.on('status', (status) => { - dashboardState.status = status; - ws.send(JSON.stringify(dashboardState)); - }); - self.events.on('servicesState', (servicesState) => { - dashboardState.availableServices = servicesState; - ws.send(JSON.stringify(dashboardState)); - }); - }); + let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls"); + for (let apiCall of apiCalls) { + app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]); + } this.app.ws('/', function(ws, _req) { self.events.on('outputDone', () => { diff --git a/test_apps/contracts_app/contracts/another_storage.sol b/test_apps/contracts_app/contracts/another_storage.sol index e84d2e35..c3140a92 100644 --- a/test_apps/contracts_app/contracts/another_storage.sol +++ b/test_apps/contracts_app/contracts/another_storage.sol @@ -1,6 +1,5 @@ pragma solidity ^0.4.24; contract AnotherStorage { - address public simpleStorageAddress; address simpleStorageAddress2; address ens;