Skip to content

Commit

Permalink
wip: add grace period for socketio offline warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Nov 24, 2023
1 parent 48ebbee commit 9d2f38e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions panel/src/layout/MainShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function MainShell() {
}
});


const socketStateChangeCounter = useRef(0);
const setIsSocketOffline = useSetOfflineWarning();
const setGlobalStatus = useSetGlobalStatus();

Expand All @@ -37,7 +37,15 @@ export default function MainShell() {
});
socket.on('disconnect', (message) => {
console.log("Main Socket.IO Disonnected:", message);
setIsSocketOffline(true);
//Grace period of 500ms to allow for quick reconnects
//Tracking the state change ID for the timeout not to overwrite a reconnection
const newId = socketStateChangeCounter.current + 1;
socketStateChangeCounter.current = newId;
setTimeout(() => {
if(socketStateChangeCounter.current === newId){
setIsSocketOffline(true);
}
}, 500);
});
socket.on('error', (error) => {
console.log('Main Socket.IO', error);
Expand Down

0 comments on commit 9d2f38e

Please sign in to comment.