missions finition

This commit is contained in:
alma 2026-01-21 15:56:27 +01:00
parent 2e54f3ce89
commit d6055d9faa
2 changed files with 96 additions and 36 deletions

View File

@ -122,11 +122,20 @@ export function useRocketChatCalls() {
from: callEvent.from.username, from: callEvent.from.username,
}); });
// Only remove notification if it matches the current call's roomId // Remove notification if:
// This prevents removing notifications from other calls // 1. It matches the current call's roomId, OR
if (currentCallRoomIdRef.current === callEvent.roomId || !currentCallRoomIdRef.current) { // 2. The call-ended event has no roomId (generic end event), OR
// 3. There's no current call tracked (shouldn't happen, but safety check)
const shouldRemove =
currentCallRoomIdRef.current === callEvent.roomId ||
!callEvent.roomId || // Generic call-ended event (no roomId) - match any active call
!currentCallRoomIdRef.current;
if (shouldRemove) {
console.log('[useRocketChatCalls] ✅ Removing notification for ended call', { console.log('[useRocketChatCalls] ✅ Removing notification for ended call', {
roomId: callEvent.roomId, roomId: callEvent.roomId,
currentCallRoomId: currentCallRoomIdRef.current,
isGenericEnd: !callEvent.roomId,
}); });
// Clear the safety timeout since we received the call-ended event // Clear the safety timeout since we received the call-ended event
@ -176,11 +185,12 @@ export function useRocketChatCalls() {
// Set a safety timeout to clear the notification if no call-ended event is received // 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 // 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
if (callTimeoutRef.current) { if (callTimeoutRef.current) {
clearTimeout(callTimeoutRef.current); clearTimeout(callTimeoutRef.current);
} }
callTimeoutRef.current = setTimeout(() => { callTimeoutRef.current = setTimeout(() => {
console.log('[useRocketChatCalls] ⏰ Safety timeout: clearing call notification after 2 minutes', { console.log('[useRocketChatCalls] ⏰ Safety timeout: clearing call notification after 45 seconds', {
roomId: callEvent.roomId, roomId: callEvent.roomId,
}); });
if (currentCallRoomIdRef.current === callEvent.roomId) { if (currentCallRoomIdRef.current === callEvent.roomId) {
@ -188,7 +198,7 @@ export function useRocketChatCalls() {
currentCallRoomIdRef.current = null; currentCallRoomIdRef.current = null;
} }
callTimeoutRef.current = null; callTimeoutRef.current = null;
}, 120000); // 2 minutes safety timeout }, 45000); // 45 seconds safety timeout (reduced from 2 minutes)
console.log('[useRocketChatCalls] 📞 Incoming call notification UI set', { console.log('[useRocketChatCalls] 📞 Incoming call notification UI set', {
from: callEvent.from.username, from: callEvent.from.username,

View File

@ -602,6 +602,7 @@ export class RocketChatCallListener {
}); });
// Check if this is a call ending event (hangup, end, cancel, reject, etc.) // Check if this is a call ending event (hangup, end, cancel, reject, etc.)
// Also check for various RocketChat-specific call end indicators
const isCallEnded = const isCallEnded =
callType === 'call-ended' || callType === 'call-ended' ||
callType === 'hangup' || callType === 'hangup' ||
@ -609,16 +610,27 @@ export class RocketChatCallListener {
callType === 'cancel' || callType === 'cancel' ||
callType === 'reject' || callType === 'reject' ||
callType === 'decline' || callType === 'decline' ||
callType === 'timeout' ||
callType === 'missed' ||
eventData.action === 'hangup' || eventData.action === 'hangup' ||
eventData.action === 'end' || eventData.action === 'end' ||
eventData.action === 'cancel' || eventData.action === 'cancel' ||
eventData.action === 'reject' || eventData.action === 'reject' ||
eventData.action === 'decline' || eventData.action === 'decline' ||
eventData.action === 'timeout' ||
eventData.status === 'ended' || eventData.status === 'ended' ||
eventData.status === 'cancelled' || eventData.status === 'cancelled' ||
eventData.status === 'rejected' || eventData.status === 'rejected' ||
eventData.status === 'timeout' ||
eventData.status === 'missed' ||
eventData.event === 'hangup' || eventData.event === 'hangup' ||
eventData.event === 'end'; eventData.event === 'end' ||
eventData.event === 'timeout' ||
eventData.message?.action === 'end' ||
eventData.message?.action === 'hangup' ||
eventData.message?.action === 'cancel' ||
// Check if message type indicates call ended
(eventData.message?.t === 'videoconf' && (eventData.message?.action === 'end' || eventData.message?.status === 'ended'));
// Check if this is an incoming call event // Check if this is an incoming call event
// RocketChat sends calls via notifications with message.t === 'videoconf' or 'audio' // RocketChat sends calls via notifications with message.t === 'videoconf' or 'audio'
@ -637,38 +649,76 @@ export class RocketChatCallListener {
(eventData.type === 'call' && eventData.status === 'ringing'); (eventData.type === 'call' && eventData.status === 'ringing');
// Handle call ended events // Handle call ended events
if (isCallEnded && roomId) { // Also handle cases where roomId might not be present but we have other indicators
const callEvent: CallEvent = { if (isCallEnded) {
type: 'call-ended', // Try to extract roomId from various sources if not directly available
from: { const finalRoomId = roomId || eventData.rid || eventData.roomId || eventData.room?._id || '';
userId: from._id || from.userId || from.id || '',
username: from.username || from.name || 'Unknown',
name: from.name || from.username || 'Unknown',
},
roomId,
roomName: roomName || from.name || 'Chat',
timestamp: new Date(),
};
logger.info('[ROCKETCHAT_CALL_LISTENER] 📞 CALL ENDED DETECTED!', { if (finalRoomId) {
from: callEvent.from.username, const callEvent: CallEvent = {
roomId: callEvent.roomId, type: 'call-ended',
roomName: callEvent.roomName, from: {
callType, userId: from._id || from.userId || from.id || '',
action: eventData.action, username: from.username || from.name || 'Unknown',
status: eventData.status, name: from.name || from.username || 'Unknown',
}); },
roomId: finalRoomId,
roomName: roomName || from.name || 'Chat',
timestamp: new Date(),
};
// Notify all handlers that the call has ended logger.info('[ROCKETCHAT_CALL_LISTENER] 📞 CALL ENDED DETECTED!', {
this.callHandlers.forEach((handler) => { from: callEvent.from.username,
try { roomId: callEvent.roomId,
handler(callEvent); roomName: callEvent.roomName,
} catch (error) { callType,
logger.error('[ROCKETCHAT_CALL_LISTENER] Error in call ended handler', { action: eventData.action,
error: error instanceof Error ? error.message : String(error) status: eventData.status,
}); event: eventData.event,
} messageAction: eventData.message?.action,
}); });
// Notify all handlers that the call has ended
this.callHandlers.forEach((handler) => {
try {
handler(callEvent);
} catch (error) {
logger.error('[ROCKETCHAT_CALL_LISTENER] Error in call ended handler', {
error: error instanceof Error ? error.message : String(error)
});
}
});
} else {
// Even without roomId, if we're sure it's a call end event, try to match by any active call
logger.info('[ROCKETCHAT_CALL_LISTENER] 📞 CALL ENDED DETECTED (no roomId, will match any active call)', {
callType,
action: eventData.action,
status: eventData.status,
});
// Create a generic call-ended event that will match any active call
const callEvent: CallEvent = {
type: 'call-ended',
from: {
userId: from._id || from.userId || from.id || '',
username: from.username || from.name || 'Unknown',
name: from.name || from.username || 'Unknown',
},
roomId: '', // Empty roomId will match any call in the handler
roomName: roomName || from.name || 'Chat',
timestamp: new Date(),
};
this.callHandlers.forEach((handler) => {
try {
handler(callEvent);
} catch (error) {
logger.error('[ROCKETCHAT_CALL_LISTENER] Error in call ended handler', {
error: error instanceof Error ? error.message : String(error)
});
}
});
}
} }
// Handle incoming call events // Handle incoming call events
else if (isIncomingCall && roomId) { else if (isIncomingCall && roomId) {