-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatcher.js
27 lines (22 loc) · 870 Bytes
/
watcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var wsReloader;
var LAST_SUCCESS_BUILD_STAMP = (localStorage.getItem('LAST_SUCCESS_BUILD_STAMP') || 0)
var WS_PORT = 9999; // configurable
function setUpWebScoket() {
if (wsReloader == null || wsReloader.readyState !== 1) {
try {
wsReloader = new WebSocket(`ws://localhost:${WS_PORT}`)
wsReloader.onmessage = (msg) => {
var newData = JSON.parse(msg.data).LAST_SUCCESS_BUILD_STAMP
if (newData > LAST_SUCCESS_BUILD_STAMP) {
LAST_SUCCESS_BUILD_STAMP = newData
localStorage.setItem('LAST_SUCCESS_BUILD_STAMP', LAST_SUCCESS_BUILD_STAMP)
location.reload(true)
}
}
} catch (exn) {
console.error("web socket failed connect")
}
}
};
setUpWebScoket();
setInterval(setUpWebScoket, 2000);