fix: handling of existing calls in `onCallInvite`

This commit is contained in:
Yash-Garg 2025-04-22 14:49:34 +05:30
parent 02e481ab52
commit 2738451ff6
No known key found for this signature in database
GPG Key ID: F6A13221914ABB4B
2 changed files with 53 additions and 1 deletions

View File

@ -384,7 +384,7 @@ class VoIP {
'[glare] got new call ${content.tryGet('call_id')} and currently room id is mapped to ${incomingCallRoomId.tryGet(room.id)}',
);
if (call != null && call.state == CallState.kEnded) {
if (call != null && call.state != CallState.kEnded) {
// Session already exist.
Logs().v('[VOIP] onCallInvite: Session [$callId] already exist.');
return;

View File

@ -932,5 +932,57 @@ void main() {
expect(room.groupCallParticipantCount('participants_count'), 2);
expect(room.hasActiveGroupCall, true);
});
test('call persists after sending invite', () async {
CallSession? incomingCall;
// incoming call should not be created yet
incomingCall = voip.calls[voip.currentCID];
expect(incomingCall, isNull);
expect(incomingCall?.pc, isNull);
// send invite for the call
final outgoingCall = await voip.inviteToCall(
room,
CallType.kVoice,
userId: '@alice:testing.com',
);
// acknowledge the invite
await matrix.handleSync(
SyncUpdate(
nextBatch: 'something',
rooms: RoomsUpdate(
join: {
room.id: JoinedRoomUpdate(
timeline: TimelineUpdate(
events: [
MatrixEvent(
type: 'm.call.invite',
content: {
'lifetime': 60000,
'call_id': outgoingCall.callId,
'party_id': outgoingCall.localPartyId,
'version': '1',
'offer': {'type': 'offer', 'sdp': 'sdp'},
},
senderId: '@alice:testing.com',
eventId: 'outgoingCallInviteEvent',
originServerTs: DateTime.now(),
),
],
),
),
},
),
),
);
// incoming call pc should be created
// if this fails, the call was not properly created
incomingCall = voip.calls[voip.currentCID];
expect(incomingCall, isNotNull);
expect(incomingCall?.pc, isNotNull);
});
});
}