potentially solving disconnection on idling

This commit is contained in:
talksik
2022-06-12 13:55:38 -05:00
parent 438d5e0b80
commit 607c7a98a1
@@ -19,22 +19,28 @@ export function SocketProvider({ children }: { children: React.ReactNode }) {
const [$ws, set$ws] = useState<Socket>(null); const [$ws, set$ws] = useState<Socket>(null);
const initiateSocketStabilityListeners = useCallback((socketConnection: Socket) => { const initiateSocketStabilityListeners = useCallback(
socketConnection.on('connect', () => { (socketConnection: Socket) => {
toast.success('sockets connected'); socketConnection.on('connect', () => {
}); toast.success('sockets connected');
});
socketConnection.io.on('close', () => { socketConnection.io.on('close', () => {
console.error('SOCKET | connection closed likely due to idling or manual disconnect'); console.error('SOCKET | connection closed likely due to idling or manual disconnect');
toast('unplugging'); toast('unplugging');
});
// client-side errors socketConnection.disconnect();
socketConnection.on('connect_error', (err) => { set$ws(undefined);
console.error(`SOCKETS | ${err.message}`); });
toast.error('sorry...this is our bad...please refresh with cmd + r');
}); // client-side errors
}, []); socketConnection.on('connect_error', (err) => {
console.error(`SOCKETS | ${err.message}`);
toast.error('sorry...this is our bad...please refresh with cmd + r');
});
},
[set$ws],
);
useEffect(() => { useEffect(() => {
if (!jwtToken) { if (!jwtToken) {