mirror of https://github.com/embarklabs/embark.git
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:
parent
734638a8a3
commit
ce44e286c2
|
@ -42,8 +42,13 @@ class Server {
|
||||||
this.app.ws('/', function(ws, _req) {
|
this.app.ws('/', function(ws, _req) {
|
||||||
self.events.on('outputDone', () => {
|
self.events.on('outputDone', () => {
|
||||||
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue