missions finition
This commit is contained in:
parent
7b022add81
commit
28462cc6bc
@ -17,6 +17,7 @@ export function useRocketChatCalls() {
|
||||
const [incomingCall, setIncomingCall] = useState<IncomingCall | null>(null);
|
||||
const currentCallRoomIdRef = useRef<string | null>(null);
|
||||
const callTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const lastCallEventTimeRef = useRef<number | null>(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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user