From 6b9be63a4decf7d191b723266355c2cd4b2becd4 Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Fri, 17 Nov 2023 12:12:47 +0530 Subject: [PATCH] fix: ignore reject/hangup events for a live call from a different device --- lib/src/voip/voip.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index 22a6a165..d63ef2b4 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -337,6 +337,7 @@ class VoIP { await delegate.stopRingtone(); Logs().v('[VOIP] onCallHangup => ${content.toString()}'); final String callId = content['call_id']; + final String partyId = content['party_id']; final call = calls[callId]; if (call != null) { if (call.room.id != roomId) { @@ -344,6 +345,11 @@ class VoIP { 'Ignoring call hangup for room $roomId claiming to be for call in room ${call.room.id}'); return; } + if (call.remotePartyId != partyId) { + Logs().w( + 'Ignoring call hangup from sender with a different party_id $partyId for call in room ${call.room.id}'); + return; + } // hangup in any case, either if the other party hung up or we did on another device await call.terminate(CallParty.kRemote, content['reason'] ?? CallErrorCode.UserHangup, true); @@ -358,6 +364,7 @@ class VoIP { Future onCallReject( String roomId, String senderId, Map content) async { final String callId = content['call_id']; + final String partyId = content['party_id']; Logs().d('Reject received for call ID $callId'); final call = calls[callId]; @@ -367,6 +374,11 @@ class VoIP { 'Ignoring call reject for room $roomId claiming to be for call in room ${call.room.id}'); return; } + if (call.remotePartyId != partyId) { + Logs().w( + 'Ignoring call reject from sender with a different party_id $partyId for call in room ${call.room.id}'); + return; + } await call.onRejectReceived(content['reason']); } else { Logs().v('[VOIP] onCallReject: Session [$callId] not found!');