diff --git a/src/pages/agent-office/hooks/useAgentManager.js b/src/pages/agent-office/hooks/useAgentManager.js index 1bc4282..70b35ae 100644 --- a/src/pages/agent-office/hooks/useAgentManager.js +++ b/src/pages/agent-office/hooks/useAgentManager.js @@ -12,6 +12,7 @@ export function useAgentManager() { const wsRef = useRef(null); const reconnectRef = useRef(null); + const connectRef = useRef(null); const connect = useCallback(() => { const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; @@ -68,12 +69,16 @@ export function useAgentManager() { ws.onclose = () => { setConnected(false); - reconnectRef.current = setTimeout(connect, WS_RECONNECT_DELAY); + reconnectRef.current = setTimeout(() => connectRef.current?.(), WS_RECONNECT_DELAY); }; ws.onerror = () => ws.close(); }, []); + useEffect(() => { + connectRef.current = connect; + }, [connect]); + useEffect(() => { connect(); return () => {