Fix websocket not open
Make sure the connection is open before sending the event
This commit is contained in:
parent
4b81968482
commit
91d1e5a85e
|
@ -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');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue