diff --git a/lib/services/rocketchat-call-listener.ts b/lib/services/rocketchat-call-listener.ts index cacd164..933af85 100644 --- a/lib/services/rocketchat-call-listener.ts +++ b/lib/services/rocketchat-call-listener.ts @@ -392,30 +392,52 @@ export class RocketChatCallListener { // Check if this is a call ending notification const notificationText = notification.text || payload?.text || notification.title || payload?.title || ''; + const messageAction = payload?.message?.action || payload?.action; + const messageStatus = payload?.message?.status || payload?.status; + const isCallEndedNotification = notificationText.toLowerCase().includes('call ended') || notificationText.toLowerCase().includes('appel terminé') || notificationText.toLowerCase().includes('call cancelled') || notificationText.toLowerCase().includes('appel annulé') || - payload?.message?.action === 'end' || - payload?.message?.action === 'hangup' || - payload?.message?.action === 'cancel'; + notificationText.toLowerCase().includes('call missed') || + notificationText.toLowerCase().includes('appel manqué') || + messageAction === 'end' || + messageAction === 'hangup' || + messageAction === 'cancel' || + messageAction === 'reject' || + messageStatus === 'ended' || + messageStatus === 'cancelled' || + messageStatus === 'rejected' || + messageStatus === 'missed'; if (isCallEndedNotification) { logger.info('[ROCKETCHAT_CALL_LISTENER] 📞 CALL ENDED DETECTED in notification!', { notificationText, roomId: payload?.rid, sender: payload?.sender, + messageAction, + messageStatus, + fullPayload: JSON.stringify(payload).substring(0, 1000), + }); + + console.log('[ROCKETCHAT_CALL_LISTENER] 📞 CALL ENDED in notification:', { + notificationText, + roomId: payload?.rid, + messageAction, + messageStatus, + payload, }); // Handle as call ended event this.handleCallEvent({ type: 'call-ended', - action: 'end', + action: messageAction || 'end', from: payload?.sender || {}, roomId: payload?.rid, roomName: payload?.name || notification.title, message: payload?.message, + status: messageStatus, }); } else if (isCallNotification) { logger.info('[ROCKETCHAT_CALL_LISTENER] ✅ VIDEO/AUDIO CALL DETECTED in notification!', { @@ -470,9 +492,22 @@ export class RocketChatCallListener { type: webrtcData.type, event: webrtcData.event, status: webrtcData.status, - roomId: webrtcData.roomId || webrtcData.rid + roomId: webrtcData.roomId || webrtcData.rid, + fullData: JSON.stringify(webrtcData).substring(0, 1000), }); + + console.log('[ROCKETCHAT_CALL_LISTENER] 📞 Call ended in webrtc event:', webrtcData); + this.handleCallEvent(webrtcData); + } else { + // Log other webrtc events to see what we're missing + logger.debug('[ROCKETCHAT_CALL_LISTENER] ⚠️ Other webrtc event (not call start/end)', { + action: webrtcData.action, + type: webrtcData.type, + event: webrtcData.event, + status: webrtcData.status, + keys: Object.keys(webrtcData), + }); } } } @@ -513,12 +548,15 @@ export class RocketChatCallListener { eventName?.includes('call') || eventName?.includes('webrtc') || eventName?.includes('videoconf') || + eventName?.includes('notification') || args.some((arg: any) => arg?.action === 'hangup' || arg?.action === 'end' || arg?.action === 'cancel' || arg?.type === 'call-ended' || - arg?.message?.t === 'videoconf' + arg?.message?.t === 'videoconf' || + arg?.message?.t === 'audio' || + arg?.message?.t === 'video' ); if (mightBeCallEvent) { @@ -529,8 +567,16 @@ export class RocketChatCallListener { hasArgs: args.length > 0, argsCount: args.length, firstArgKeys: args[0] ? Object.keys(args[0]) : [], + firstArgPreview: args[0] ? JSON.stringify(args[0]).substring(0, 500) : null, fullFields: message.fields, }); + + // Also log to console for immediate debugging + console.log('[ROCKETCHAT_CALL_LISTENER] 📢 POTENTIAL CALL EVENT:', { + eventName, + firstArg: args[0], + allArgs: args, + }); } else { logger.debug('[ROCKETCHAT_CALL_LISTENER] 📢 Stream notify user message', { msg: message.msg,