Reconnection Logic (#2743)
* reconnection logic * prettier state.js --------- Co-authored-by: Masen Furer <m_github@0x26.net>
This commit is contained in:
parent
93fc269860
commit
7725c48fb7
@ -325,6 +325,17 @@ export const connect = async (
|
|||||||
autoUnref: false,
|
autoUnref: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkVisibility() {
|
||||||
|
if (document.visibilityState === "visible") {
|
||||||
|
if (!socket.current.connected) {
|
||||||
|
console.log("Socket is disconnected, attempting to reconnect ");
|
||||||
|
socket.current.connect();
|
||||||
|
} else {
|
||||||
|
console.log("Socket is reconnected ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Once the socket is open, hydrate the page.
|
// Once the socket is open, hydrate the page.
|
||||||
socket.current.on("connect", () => {
|
socket.current.on("connect", () => {
|
||||||
setConnectErrors([]);
|
setConnectErrors([]);
|
||||||
@ -345,6 +356,8 @@ export const connect = async (
|
|||||||
queueEvents(update.events, socket);
|
queueEvents(update.events, socket);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", checkVisibility);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user