mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-11 22:34:24 +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');
|
const fs = require('../../core/fs');
|
||||||
require('http-shutdown').extend();
|
require('http-shutdown').extend();
|
||||||
|
|
||||||
const WEB_SOCKET_STATE_OPEN = 1;
|
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.buildDir = options.buildDir;
|
this.buildDir = options.buildDir;
|
||||||
@ -33,22 +31,18 @@ class Server {
|
|||||||
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
||||||
|
|
||||||
this.app = express();
|
this.app = express();
|
||||||
expressWebSocket(this.app);
|
const expressWs = expressWebSocket(this.app);
|
||||||
|
|
||||||
this.app.use(main);
|
this.app.use(main);
|
||||||
this.app.use('/coverage', coverage);
|
this.app.use('/coverage', coverage);
|
||||||
this.app.use(coverageStyle);
|
this.app.use(coverageStyle);
|
||||||
|
|
||||||
this.app.ws('/', function(ws, _req) {
|
this.app.ws('/', (_ws, _req) => {});
|
||||||
|
const wss = expressWs.getWss('/');
|
||||||
|
|
||||||
self.events.on('outputDone', () => {
|
self.events.on('outputDone', () => {
|
||||||
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
|
wss.clients.forEach(function (client) {
|
||||||
return ws.send('outputDone');
|
client.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');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user