landing
This commit is contained in:
@@ -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();
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user