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 Andre Medeiros
parent 734638a8a3
commit ce44e286c2
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');
});
});
});