Revert "fix: faster WebSocket reconnect on iOS PWA"
This reverts commit c21b6c441c.
This commit is contained in:
parent
c21b6c441c
commit
9f8b2cc987
|
|
@ -607,26 +607,17 @@ export function buildHTML(nonce: string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ws, timer, connectTimer;
|
var ws, timer;
|
||||||
function connect() {
|
function connect() {
|
||||||
if (ws && (ws.readyState === 0 || ws.readyState === 1)) return;
|
|
||||||
clearTimeout(connectTimer);
|
|
||||||
var wsProtocol = location.protocol === "https:" ? "wss:" : "ws:";
|
var wsProtocol = location.protocol === "https:" ? "wss:" : "ws:";
|
||||||
ws = new WebSocket(wsProtocol + "//" + location.host + "/ws");
|
ws = new WebSocket(wsProtocol + "//" + location.host + "/ws");
|
||||||
|
|
||||||
// If not connected within 4s, close and retry immediately
|
|
||||||
connectTimer = setTimeout(function () {
|
|
||||||
if (ws && ws.readyState !== 1) { ws.close(); }
|
|
||||||
}, 4000);
|
|
||||||
|
|
||||||
ws.onopen = function () {
|
ws.onopen = function () {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
clearTimeout(connectTimer);
|
|
||||||
updateStatus(true);
|
updateStatus(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = function () {
|
ws.onclose = function () {
|
||||||
clearTimeout(connectTimer);
|
|
||||||
updateStatus(false);
|
updateStatus(false);
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
timer = setTimeout(connect, 2000);
|
timer = setTimeout(connect, 2000);
|
||||||
|
|
@ -726,14 +717,6 @@ export function buildHTML(nonce: string): string {
|
||||||
});
|
});
|
||||||
|
|
||||||
connect();
|
connect();
|
||||||
|
|
||||||
// Reconnect immediately when app comes back to foreground (e.g. iOS PWA resume)
|
|
||||||
document.addEventListener("visibilitychange", function () {
|
|
||||||
if (document.visibilityState === "visible") {
|
|
||||||
clearTimeout(timer);
|
|
||||||
if (!ws || ws.readyState === 2 || ws.readyState === 3) connect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue