From 1c27c3465b6b978515e14986ddce3f1f37ecd373 Mon Sep 17 00:00:00 2001 From: emizzle Date: Mon, 24 Sep 2018 11:10:19 +1000 Subject: [PATCH] Handle case when socket not opened MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the socket is not already opened, listen for ‘open’ event before sending the `outputDone` data. --- lib/modules/webserver/server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index fcd0a83c6..239677a44 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -42,8 +42,13 @@ class Server { this.app.ws('/', function(ws, _req) { self.events.on('outputDone', () => { if (ws.readyState === WEB_SOCKET_STATE_OPEN) { - ws.send('outputDone'); + return ws.send('outputDone'); } + // if the socket wasn't yet opened, listen for the 'open' event, + // then send the 'outputDone' data + ws.addEventListener('open', _event => { + ws.send('outputDone'); + }); }); });