From 28462cc6bcabd22af6da133f2043d11c01bedc9a Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 21 Jan 2026 19:32:49 +0100 Subject: [PATCH] missions finition --- hooks/use-rocketchat-calls.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hooks/use-rocketchat-calls.ts b/hooks/use-rocketchat-calls.ts index 04ec119..ba07a5f 100644 --- a/hooks/use-rocketchat-calls.ts +++ b/hooks/use-rocketchat-calls.ts @@ -17,6 +17,7 @@ export function useRocketChatCalls() { const [incomingCall, setIncomingCall] = useState(null); const currentCallRoomIdRef = useRef(null); const callTimeoutRef = useRef(null); + const lastCallEventTimeRef = useRef(null); /** * Get RocketChat credentials for the current user @@ -146,6 +147,7 @@ export function useRocketChatCalls() { setIncomingCall(null); currentCallRoomIdRef.current = null; + lastCallEventTimeRef.current = null; } else { console.log('[useRocketChatCalls] ⏭️ Ignoring call ended event - different room', { endedRoomId: callEvent.roomId, @@ -182,23 +184,26 @@ export function useRocketChatCalls() { // Track the current call's roomId so we can match it when the call ends currentCallRoomIdRef.current = callEvent.roomId; + lastCallEventTimeRef.current = Date.now(); // Set a safety timeout to clear the notification if no call-ended event is received // This handles cases where RocketChat doesn't send the call-ended event - // Reduced to 45 seconds - if the call hasn't ended by then, it's likely the caller hung up + // Reduced to 20 seconds - typical call ringing duration, if no answer/reject, caller likely hung up if (callTimeoutRef.current) { clearTimeout(callTimeoutRef.current); } callTimeoutRef.current = setTimeout(() => { - console.log('[useRocketChatCalls] ⏰ Safety timeout: clearing call notification after 45 seconds', { + console.log('[useRocketChatCalls] ⏰ Safety timeout: clearing call notification after 20 seconds', { roomId: callEvent.roomId, + timeSinceCallStart: Date.now() - (lastCallEventTimeRef.current || 0), }); if (currentCallRoomIdRef.current === callEvent.roomId) { setIncomingCall(null); currentCallRoomIdRef.current = null; + lastCallEventTimeRef.current = null; } callTimeoutRef.current = null; - }, 45000); // 45 seconds safety timeout (reduced from 2 minutes) + }, 20000); // 20 seconds safety timeout - typical max ringing duration console.log('[useRocketChatCalls] 📞 Incoming call notification UI set', { from: callEvent.from.username, @@ -269,6 +274,8 @@ export function useRocketChatCalls() { callTimeoutRef.current = null; } + currentCallRoomIdRef.current = null; + lastCallEventTimeRef.current = null; initializedRef.current = false; }; }, [session?.user?.id, initializeListener]); @@ -284,6 +291,7 @@ export function useRocketChatCalls() { } setIncomingCall(null); currentCallRoomIdRef.current = null; + lastCallEventTimeRef.current = null; }, []); return {