Use broadcast to avoid useless send

This commit is contained in:
Anthony Laibe 2018-09-27 11:16:55 +01:00 committed by Pascal Precht
parent 28a1484bf5
commit 684839b5aa
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 7 additions and 13 deletions

View File

@ -6,8 +6,6 @@ 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;
@ -33,22 +31,18 @@ class Server {
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
this.app = express();
expressWebSocket(this.app);
const expressWs = expressWebSocket(this.app);
this.app.use(main);
this.app.use('/coverage', coverage);
this.app.use(coverageStyle);
this.app.ws('/', function(ws, _req) {
self.events.on('outputDone', () => {
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
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');
});
this.app.ws('/', (_ws, _req) => {});
const wss = expressWs.getWss('/');
self.events.on('outputDone', () => {
wss.clients.forEach(function (client) {
client.send('outputDone');
});
});