Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
fix(livereload): on project build all pages connected should reload. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jthoms1 authored Dec 6, 2016
1 parent 7f8a0c3 commit 62d6b23
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/dev-server/notification-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ export function createNotificationServer(config: ServeConfig) {
// queue up all messages to the client
function queueMessageSend(msg: WsMessage) {
msgToClient.push(msg);
drainMessageQueue();
drainMessageQueue({
broadcast: true
});
}

// drain the queue messages when the server is ready
function drainMessageQueue() {
if (wsServer) {
function drainMessageQueue(options = { broadcast: false }) {
let sendMethod = wsServer.send;
if (options.hasOwnProperty('broadcast') && options.broadcast) {
sendMethod = wss.broadcast;
}
if (wss.clients.length > 0) {
let msg: any;
while (msg = msgToClient.shift()) {
try {
wsServer.send(JSON.stringify(msg));
sendMethod(JSON.stringify(msg));
} catch (e) {
if (e.message !== 'not opened') {
Logger.error(`error sending client ws - ${e.message}`);
Expand Down Expand Up @@ -64,7 +70,11 @@ export function createNotificationServer(config: ServeConfig) {

// create web socket server
const wss = new WebSocketServer({ port: config.notificationPort });

wss.broadcast = function broadcast(data: any) {
wss.clients.forEach(function each(client: any) {
client.send(data);
});
};
wss.on('connection', (ws: any) => {
// we've successfully connected
wsServer = ws;
Expand Down

0 comments on commit 62d6b23

Please sign in to comment.