potentially solving disconnection on idling

This commit is contained in:
talksik
2022-06-12 13:55:38 -05:00
parent 438d5e0b80
commit 607c7a98a1
@@ -19,7 +19,8 @@ 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: Socket) => {
socketConnection.on('connect', () => { socketConnection.on('connect', () => {
toast.success('sockets connected'); toast.success('sockets connected');
}); });
@@ -27,6 +28,9 @@ export function SocketProvider({ children }: { children: React.ReactNode }) {
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');
socketConnection.disconnect();
set$ws(undefined);
}); });
// client-side errors // client-side errors
@@ -34,7 +38,9 @@ export function SocketProvider({ children }: { children: React.ReactNode }) {
console.error(`SOCKETS | ${err.message}`); console.error(`SOCKETS | ${err.message}`);
toast.error('sorry...this is our bad...please refresh with cmd + r'); toast.error('sorry...this is our bad...please refresh with cmd + r');
}); });
}, []); },
[set$ws],
);
useEffect(() => { useEffect(() => {
if (!jwtToken) { if (!jwtToken) {