This commit is contained in:
Zakhar
2026-05-21 12:49:45 +02:00
parent 1a5a10a854
commit ad851551d1
21 changed files with 958 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
(() => {
const socketUrl = 'ws://192.168.1.138:9878';
let socket = new WebSocket(socketUrl);
socket.addEventListener('close', () => {
const interAttemptTimeoutMilliseconds = 100;
const maxDisconnectedTimeMilliseconds = 3000;
const maxAttempts = Math.round(
maxDisconnectedTimeMilliseconds / interAttemptTimeoutMilliseconds,
);
let attempts = 0;
const reloadIfCanConnect = () => {
attempts++;
if (attempts > maxAttempts) {
console.error('Could not reconnect to dev server.');
return;
}
socket = new WebSocket(socketUrl);
socket.addEventListener('error', () => {
setTimeout(reloadIfCanConnect, interAttemptTimeoutMilliseconds);
});
socket.addEventListener('open', () => {
location.reload();
});
};
reloadIfCanConnect();
});
})();