From 19a90571f68496f38a90f97a73149159916b9dff Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 22 Jul 2025 17:11:52 -0400 Subject: [PATCH] Down Socket Reconnects --- .../src/contexts/SocketIO/socketProvider.jsx | 62 +------------------ 1 file changed, 1 insertion(+), 61 deletions(-) diff --git a/client/src/contexts/SocketIO/socketProvider.jsx b/client/src/contexts/SocketIO/socketProvider.jsx index 78917df03..b7e5daed3 100644 --- a/client/src/contexts/SocketIO/socketProvider.jsx +++ b/client/src/contexts/SocketIO/socketProvider.jsx @@ -32,7 +32,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { const socketRef = useRef(null); const [clientId, setClientId] = useState(null); const [isConnected, setIsConnected] = useState(false); - const [socketInitialized, setSocketInitialized] = useState(false); const notification = useNotification(); const userAssociationId = bodyshop?.associations?.[0]?.id; const { t } = useTranslation(); @@ -148,13 +147,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { onError: (err) => console.error("MARK_ALL_NOTIFICATIONS_READ error:", err) }); - const checkAndReconnect = () => { - if (socketRef.current && !socketRef.current.connected) { - console.log("Attempting manual reconnect due to event trigger"); - socketRef.current.connect(); - } - }; - useEffect(() => { const initializeSocket = async (token) => { if (!bodyshop || !bodyshop.id || socketRef.current) return; @@ -173,7 +165,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { }); socketRef.current = socketInstance; - setSocketInitialized(true); const handleBodyshopMessage = (message) => { if (!message || !message.type) return; @@ -261,7 +252,7 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { break; } }; - + const handleConnect = () => { socketInstance.emit("join-bodyshop-room", bodyshop.id); setClientId(socketInstance.id); @@ -558,57 +549,6 @@ const SocketProvider = ({ children, bodyshop, navigate, currentUser }) => { t ]); - useEffect(() => { - if (!socketInitialized) return; - - const onVisibilityChange = () => { - if (document.visibilityState === "visible") { - checkAndReconnect(); - } - }; - - const onFocus = () => { - checkAndReconnect(); - }; - - const onOnline = () => { - checkAndReconnect(); - }; - - const onPageShow = (event) => { - if (event.persisted) { - checkAndReconnect(); - } - }; - - document.addEventListener("visibilitychange", onVisibilityChange); - window.addEventListener("focus", onFocus); - window.addEventListener("online", onOnline); - window.addEventListener("pageshow", onPageShow); - - // Sleep/wake detection using timer - let lastTime = Date.now(); - const intervalMs = 1000; // Check every second - const thresholdMs = 2000; // If more than 2 seconds elapsed, assume sleep/wake - - const sleepCheckInterval = setInterval(() => { - const currentTime = Date.now(); - if (currentTime > lastTime + intervalMs + thresholdMs) { - console.log("Detected potential wake from sleep/hibernate"); - checkAndReconnect(); - } - lastTime = currentTime; - }, intervalMs); - - return () => { - document.removeEventListener("visibilitychange", onVisibilityChange); - window.removeEventListener("focus", onFocus); - window.removeEventListener("online", onOnline); - window.removeEventListener("pageshow", onPageShow); - clearInterval(sleepCheckInterval); - }; - }, [socketInitialized]); - return (