From 4b8196848208634b4ce852f413bfba1430fad543 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 19 Sep 2018 19:19:37 -0400 Subject: [PATCH] restore ws functionality to webserver --- lib/modules/blockchain_process/blockchain.js | 2 +- lib/modules/webserver/server.js | 20 +++++++------- npm-shrinkwrap.json | 26 ++++++++++++------ package.json | 28 ++++++++++---------- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/lib/modules/blockchain_process/blockchain.js b/lib/modules/blockchain_process/blockchain.js index 97b68aae..4397d810 100644 --- a/lib/modules/blockchain_process/blockchain.js +++ b/lib/modules/blockchain_process/blockchain.js @@ -343,7 +343,7 @@ Blockchain.prototype.initChainAndGetAddress = function(callback) { }; var BlockchainClient = function(blockchainConfig, client, env, onReadyCallback, onExitCallback) { - const isDev = !!blockchainConfig.isDev; + const isDev = Boolean(blockchainConfig.isDev); // TODO add other clients at some point if (client === 'geth') { return new Blockchain({blockchainConfig, client: GethCommands, env, isDev, onReadyCallback, onExitCallback}); diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index abbc71e8..d10c9165 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -1,10 +1,10 @@ const async = require('async'); let serveStatic = require('serve-static'); const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host'); +const expressWebSocket = require('express-ws'); const express = require('express'); const fs = require('../../core/fs'); require('http-shutdown').extend(); -const webSocket = require('ws'); class Server { constructor(options) { @@ -18,6 +18,7 @@ class Server { } start(callback) { + const self = this; if (this.server && this.server.listening) { let message = __("a webserver is already running at") + " " + ("http://" + canonicalHost(this.hostname) + @@ -33,17 +34,14 @@ class Server { this.app.use(main); this.app.use('/coverage', coverage); this.app.use(coverageStyle); - - //this.wss = new webSocket.Server({server: this.server}); - //this.events.on('outputDone', () => { - // this.wss.clients.forEach((ws) => { - // if (ws.readyState === webSocket.OPEN) { - // ws.send('outputDone'); - // } - // }); - //}); - const self = this; + expressWebSocket(this.app); + + this.app.ws('/', function(ws, _req) { + self.events.on('outputDone', () => { + ws.send('outputDone'); + }); + }); async.waterfall([ function createPlaceholderPage(next) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 17a44b16..8ae55ed0 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3489,6 +3489,24 @@ } } }, + "express-ws": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz", + "integrity": "sha512-KEyUw8AwRET2iFjFsI1EJQrJ/fHeGiJtgpYgEWG3yDv4l/To/m3a2GaYfeGyB3lsWdvbesjF5XCMx+SVBgAAYw==", + "requires": { + "ws": "^5.2.0" + }, + "dependencies": { + "ws": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz", + "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==", + "requires": { + "async-limiter": "~1.0.0" + } + } + } + }, "extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -11076,14 +11094,6 @@ } } }, - "ws": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.0.0.tgz", - "integrity": "sha512-c2UlYcAZp1VS8AORtpq6y4RJIkJ9dQz18W32SpR/qXGfLDZ2jU4y4wKvvZwqbi7U6gxFQTeE+urMbXU/tsDy4w==", - "requires": { - "async-limiter": "~1.0.0" - } - }, "xhr": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/xhr/-/xhr-2.5.0.tgz", diff --git a/package.json b/package.json index cc333506..2c2a8983 100644 --- a/package.json +++ b/package.json @@ -46,20 +46,20 @@ "eth-ens-namehash": "2.0.8", "eth-lib": "0.2.8", "ethereumjs-wallet": "0.6.0", - "express": "4.16.3", - "file-loader": "1.1.11", - "finalhandler": "1.1.1", - "flatted": "0.2.3", - "follow-redirects": "1.5.7", - "fs-extra": "2.1.2", - "ganache-cli": "6.1.8", - "glob": "7.1.3", - "globule": "1.2.1", - "hard-source-webpack-plugin": "0.11.2", - "hosted-git-info": "2.7.1", - "http-proxy": "1.17.0", - "http-shutdown": "1.2.0", - "i18n": "0.8.3", + "express": "^4.16.3", + "express-ws": "^4.0.0", + "file-loader": "^1.1.5", + "finalhandler": "^1.1.1", + "flatted": "^0.2.3", + "follow-redirects": "^1.2.4", + "fs-extra": "^2.0.0", + "ganache-cli": "^6.1.6", + "glob": "^7.1.2", + "globule": "^1.1.0", + "hard-source-webpack-plugin": "^0.11.1", + "http-proxy": "^1.17.0", + "http-shutdown": "^1.2.0", + "i18n": "^0.8.3", "ipfs-api": "17.2.4", "is-valid-domain": "0.0.5", "istanbul": "0.4.5",