fix: high CPU usage

This commit is contained in:
mrxiaozhuox committed 2022-01-26 00:21:40 +08:00
1 parent 2c0b0460c9
commit 20977a49f0
2 files changed
+37 -43

No files matched your search

+6 -11
View File
@@ -5,21 +5,16 @@
var poll_interval = 2000;
var reload_upon_connect = () => {
window.setTimeout(() => {
var ws = new WebSocket(url);
ws.onopen = () => window.location.reload();
ws.onclose = reload_upon_connect;
}, poll_interval);
};
var ws = new WebSocket(url);
ws.onmessage = (ev) => {
ws.addEventListener("message", (ev) => {
if (ev.data == "reload") {
window.location.reload();
}
};
});
ws.addEventListener("open", () => {
ws.send("init");
});
ws.onclose = reload_upon_connect;
})();