Handle case when socket not opened

If the socket is not already opened, listen for ‘open’ event before sending the `outputDone` data.
This commit is contained in:
emizzle 2018-09-24 11:10:19 +10:00 committed by Pascal Precht
parent 91d1e5a85e
commit 1c27c3465b
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 6 additions and 1 deletions

View File

@ -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');
});
});
});