Fix websocket not open

Make sure the connection is open before
sending the event
This commit is contained in:
Anthony Laibe 2018-09-21 10:44:46 +01:00 committed by Pascal Precht
parent 4b81968482
commit 91d1e5a85e
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,8 @@ const express = require('express');
const fs = require('../../core/fs');
require('http-shutdown').extend();
const WEB_SOCKET_STATE_OPEN = 1;
class Server {
constructor(options) {
this.buildDir = options.buildDir;
@ -31,15 +33,17 @@ class Server {
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
this.app = express();
expressWebSocket(this.app);
this.app.use(main);
this.app.use('/coverage', coverage);
this.app.use(coverageStyle);
expressWebSocket(this.app);
this.app.ws('/', function(ws, _req) {
self.events.on('outputDone', () => {
ws.send('outputDone');
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
ws.send('outputDone');
}
});
});