mirror of https://github.com/embarklabs/embark.git
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) {
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue