mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 14:34:40 +00:00
Use broadcast to avoid useless send
This commit is contained in:
parent
28a1484bf5
commit
684839b5aa
@ -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) {
|
||||
this.app.ws('/', (_ws, _req) => {});
|
||||
const wss = expressWs.getWss('/');
|
||||
|
||||
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');
|
||||
});
|
||||
wss.clients.forEach(function (client) {
|
||||
client.send('outputDone');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user