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

Commit 62d6b23

Browse files
authored
fix(livereload): on project build all pages connected should reload. (#513)
1 parent 7f8a0c3 commit 62d6b23

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/dev-server/notification-server.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ export function createNotificationServer(config: ServeConfig) {
1515
// queue up all messages to the client
1616
function queueMessageSend(msg: WsMessage) {
1717
msgToClient.push(msg);
18-
drainMessageQueue();
18+
drainMessageQueue({
19+
broadcast: true
20+
});
1921
}
2022

2123
// drain the queue messages when the server is ready
22-
function drainMessageQueue() {
23-
if (wsServer) {
24+
function drainMessageQueue(options = { broadcast: false }) {
25+
let sendMethod = wsServer.send;
26+
if (options.hasOwnProperty('broadcast') && options.broadcast) {
27+
sendMethod = wss.broadcast;
28+
}
29+
if (wss.clients.length > 0) {
2430
let msg: any;
2531
while (msg = msgToClient.shift()) {
2632
try {
27-
wsServer.send(JSON.stringify(msg));
33+
sendMethod(JSON.stringify(msg));
2834
} catch (e) {
2935
if (e.message !== 'not opened') {
3036
Logger.error(`error sending client ws - ${e.message}`);
@@ -64,7 +70,11 @@ export function createNotificationServer(config: ServeConfig) {
6470

6571
// create web socket server
6672
const wss = new WebSocketServer({ port: config.notificationPort });
67-
73+
wss.broadcast = function broadcast(data: any) {
74+
wss.clients.forEach(function each(client: any) {
75+
client.send(data);
76+
});
77+
};
6878
wss.on('connection', (ws: any) => {
6979
// we've successfully connected
7080
wsServer = ws;

0 commit comments

Comments
 (0)