Reconnection Logic (#2743)

* reconnection logic

* prettier state.js

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
This commit is contained in:
Yummy-Yums 2024-03-01 00:21:35 +00:00 committed by GitHub
parent 93fc269860
commit 7725c48fb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -325,6 +325,17 @@ export const connect = async (
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.
socket.current.on("connect", () => {
setConnectErrors([]);
@ -345,6 +356,8 @@ export const connect = async (
queueEvents(update.events, socket);
}
});
document.addEventListener("visibilitychange", checkVisibility);
};
/**