From d4566d7512f75930bd3a96396fa5a5bafadf24fa Mon Sep 17 00:00:00 2001 From: td Date: Tue, 21 May 2024 15:02:30 +0530 Subject: [PATCH 1/4] fix: minor perm issue typo while setting famedly call member event --- lib/src/voip/utils/famedly_call_extension.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/voip/utils/famedly_call_extension.dart b/lib/src/voip/utils/famedly_call_extension.dart index 0f7b6d4a..5f83a6f0 100644 --- a/lib/src/voip/utils/famedly_call_extension.dart +++ b/lib/src/voip/utils/famedly_call_extension.dart @@ -120,7 +120,7 @@ extension FamedlyCallMemberEventsExtension on Room { } Future setFamedlyCallMemberEvent(Map newContent) async { - if (groupCallsEnabledForEveryone) { + if (canJoinGroupCall) { await client.setRoomStateWithKey( id, EventTypes.GroupCallMember, From d10befcac52491e39bb5ec29638d44fc612aa851 Mon Sep 17 00:00:00 2001 From: td Date: Tue, 21 May 2024 15:04:25 +0530 Subject: [PATCH 2/4] fix: allow famedly calls for everyone before choosing an existing one --- lib/src/voip/voip.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index 6d381a7a..7c3f6aa2 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -764,6 +764,10 @@ class VoIP { String? application, String? scope, ) async { + if (!room.groupCallsEnabledForEveryone) { + await room.enableGroupCalls(); + } + final groupCall = getGroupCallById(room.id, groupCallId); if (groupCall != null) { @@ -774,10 +778,6 @@ class VoIP { return groupCall; } - if (!room.groupCallsEnabledForEveryone) { - await room.enableGroupCalls(); - } - // The call doesn't exist, but we can create it return await _newGroupCall( groupCallId, From 39a8b8ce89f1840a8b86570890d6176d503c0ec7 Mon Sep 17 00:00:00 2001 From: td Date: Tue, 21 May 2024 15:07:44 +0530 Subject: [PATCH 3/4] chore: throw exception if you cannot send famedly call member event --- lib/src/voip/utils/famedly_call_extension.dart | 4 ++-- lib/src/voip/voip.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/voip/utils/famedly_call_extension.dart b/lib/src/voip/utils/famedly_call_extension.dart index 5f83a6f0..e7edbbe4 100644 --- a/lib/src/voip/utils/famedly_call_extension.dart +++ b/lib/src/voip/utils/famedly_call_extension.dart @@ -128,8 +128,8 @@ extension FamedlyCallMemberEventsExtension on Room { newContent, ); } else { - Logs().w( - '[VOIP] cannot send ${EventTypes.GroupCallMember} events in room: $id, fix your PLs'); + throw Exception( + '[VOIP] User is not allowed to send famedly call member events in room'); } } diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index 7c3f6aa2..f4bfa366 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -773,7 +773,7 @@ class VoIP { if (groupCall != null) { if (!room.canJoinGroupCall) { throw Exception( - 'User is not allowed to join famedly calls in the room'); + '[VOIP] User is not allowed to join famedly calls in the room'); } return groupCall; } From b5fb43af516eb672156deac2603cd124ff454835 Mon Sep 17 00:00:00 2001 From: td Date: Tue, 21 May 2024 15:47:19 +0530 Subject: [PATCH 4/4] chore: add MatrixSDKVoipException and some more logging --- lib/src/voip/backend/call_backend_model.dart | 3 ++- lib/src/voip/backend/livekit_backend.dart | 3 ++- lib/src/voip/backend/mesh_backend.dart | 25 +++++++++++-------- lib/src/voip/call_session.dart | 3 ++- lib/src/voip/group_call_session.dart | 2 +- .../voip/utils/famedly_call_extension.dart | 15 +++++++++-- lib/src/voip/voip.dart | 5 ++-- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/src/voip/backend/call_backend_model.dart b/lib/src/voip/backend/call_backend_model.dart index 8bdbc8bb..814d87ce 100644 --- a/lib/src/voip/backend/call_backend_model.dart +++ b/lib/src/voip/backend/call_backend_model.dart @@ -23,7 +23,8 @@ abstract class CallBackend { type: type, ); } else { - throw ArgumentError('Invalid type: $type'); + throw MatrixSDKVoipException( + 'Invalid type: $type in CallBackend.fromJson'); } } diff --git a/lib/src/voip/backend/livekit_backend.dart b/lib/src/voip/backend/livekit_backend.dart index c7ec5fd2..088a38f5 100644 --- a/lib/src/voip/backend/livekit_backend.dart +++ b/lib/src/voip/backend/livekit_backend.dart @@ -80,7 +80,8 @@ class LiveKitBackend extends CallBackend { final keyProvider = groupCall.voip.delegate.keyProvider; if (keyProvider == null) { - throw Exception('[VOIP] _ratchetKey called but KeyProvider was null'); + throw MatrixSDKVoipException( + '_ratchetKey called but KeyProvider was null'); } final myKeys = _encryptionKeysMap[groupCall.localParticipant]; diff --git a/lib/src/voip/backend/mesh_backend.dart b/lib/src/voip/backend/mesh_backend.dart index 755a1d06..4a0cb47c 100644 --- a/lib/src/voip/backend/mesh_backend.dart +++ b/lib/src/voip/backend/mesh_backend.dart @@ -87,8 +87,7 @@ class MeshBackend extends CallBackend { return await groupCall.voip.delegate.mediaDevices .getDisplayMedia(mediaConstraints); } catch (e, s) { - Logs().e('[VOIP] _getDisplayMedia failed because,', e, s); - rethrow; + throw MatrixSDKVoipException('_getDisplayMedia failed', stackTrace: s); } } @@ -113,7 +112,7 @@ class MeshBackend extends CallBackend { /// init a peer call from group calls. Future _initCall(GroupCallSession groupCall, CallSession call) async { if (call.remoteUserId == null) { - throw Exception( + throw MatrixSDKVoipException( 'Cannot init call without proper invitee user and device Id'); } @@ -156,7 +155,7 @@ class MeshBackend extends CallBackend { .indexWhere((element) => element.callId == existingCall.callId); if (existingCallIndex == -1) { - throw Exception('Couldn\'t find call to replace'); + throw MatrixSDKVoipException('Couldn\'t find call to replace'); } _callSessions.removeAt(existingCallIndex); @@ -181,7 +180,7 @@ class MeshBackend extends CallBackend { Future _disposeCall(GroupCallSession groupCall, CallSession call, CallErrorCode hangupReason) async { if (call.remoteUserId == null) { - throw Exception( + throw MatrixSDKVoipException( 'Cannot init call without proper invitee user and device Id'); } @@ -223,7 +222,7 @@ class MeshBackend extends CallBackend { Future _onStreamsChanged( GroupCallSession groupCall, CallSession call) async { if (call.remoteUserId == null) { - throw Exception( + throw MatrixSDKVoipException( 'Cannot init call without proper invitee user and device Id'); } @@ -372,7 +371,8 @@ class MeshBackend extends CallBackend { (stream) => stream.participant.id == existingStream.participant.id); if (streamIndex == -1) { - throw Exception('Couldn\'t find screenshare stream to replace'); + throw MatrixSDKVoipException( + 'Couldn\'t find screenshare stream to replace'); } _screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]); @@ -390,7 +390,8 @@ class MeshBackend extends CallBackend { .indexWhere((stream) => stream.participant.id == stream.participant.id); if (streamIndex == -1) { - throw Exception('Couldn\'t find screenshare stream to remove'); + throw MatrixSDKVoipException( + 'Couldn\'t find screenshare stream to remove'); } _screenshareStreams.removeWhere( @@ -451,7 +452,8 @@ class MeshBackend extends CallBackend { (stream) => stream.participant.id == existingStream.participant.id); if (streamIndex == -1) { - throw Exception('Couldn\'t find user media stream to replace'); + throw MatrixSDKVoipException( + 'Couldn\'t find user media stream to replace'); } _userMediaStreams.replaceRange(streamIndex, 1, [replacementStream]); @@ -469,7 +471,8 @@ class MeshBackend extends CallBackend { (element) => element.participant.id == stream.participant.id); if (streamIndex == -1) { - throw Exception('Couldn\'t find user media stream to remove'); + throw MatrixSDKVoipException( + 'Couldn\'t find user media stream to remove'); } _userMediaStreams.removeWhere( @@ -527,7 +530,7 @@ class MeshBackend extends CallBackend { Future initLocalStream(GroupCallSession groupCall, {WrappedMediaStream? stream}) async { if (groupCall.state != GroupCallState.localCallFeedUninitialized) { - throw Exception( + throw MatrixSDKVoipException( 'Cannot initialize local call feed in the ${groupCall.state} state.'); } diff --git a/lib/src/voip/call_session.dart b/lib/src/voip/call_session.dart index 9a96c688..8ffde2ea 100644 --- a/lib/src/voip/call_session.dart +++ b/lib/src/voip/call_session.dart @@ -928,9 +928,10 @@ class CallSession { if (sender.track != null && sender.track!.kind == 'audio') { await sender.dtmfSender.insertDTMF(tones); return; + } else { + Logs().w('[VOIP] Unable to find a track to send DTMF on'); } } - Logs().e('[VOIP] Unable to find a track to send DTMF on'); } Future terminate( diff --git a/lib/src/voip/group_call_session.dart b/lib/src/voip/group_call_session.dart index 3535a06f..6d7625cd 100644 --- a/lib/src/voip/group_call_session.dart +++ b/lib/src/voip/group_call_session.dart @@ -112,7 +112,7 @@ class GroupCallSession { Future enter({WrappedMediaStream? stream}) async { if (!(state == GroupCallState.localCallFeedUninitialized || state == GroupCallState.localCallFeedInitialized)) { - throw Exception('Cannot enter call in the $state state'); + throw MatrixSDKVoipException('Cannot enter call in the $state state'); } if (state == GroupCallState.localCallFeedUninitialized) { diff --git a/lib/src/voip/utils/famedly_call_extension.dart b/lib/src/voip/utils/famedly_call_extension.dart index e7edbbe4..4f5a70b1 100644 --- a/lib/src/voip/utils/famedly_call_extension.dart +++ b/lib/src/voip/utils/famedly_call_extension.dart @@ -128,8 +128,9 @@ extension FamedlyCallMemberEventsExtension on Room { newContent, ); } else { - throw Exception( - '[VOIP] User is not allowed to send famedly call member events in room'); + throw MatrixSDKVoipException( + 'User ${client.userID}:${client.deviceID} is not allowed to send famedly call member events in room $id, canJoinGroupCall: $canJoinGroupCall, room.canJoinGroupCall: $groupCallsEnabledForEveryone', + ); } } @@ -165,3 +166,13 @@ bool isValidMemEvent(Map event) { return false; } } + +class MatrixSDKVoipException implements Exception { + final String cause; + final StackTrace? stackTrace; + + MatrixSDKVoipException(this.cause, {this.stackTrace}); + + @override + String toString() => '[VOIP] $cause, ${super.toString()}, $stackTrace'; +} diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index f4bfa366..1b78e3d4 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -772,8 +772,9 @@ class VoIP { if (groupCall != null) { if (!room.canJoinGroupCall) { - throw Exception( - '[VOIP] User is not allowed to join famedly calls in the room'); + throw MatrixSDKVoipException( + 'User ${client.userID}:${client.deviceID} is not allowed to join famedly calls in room ${room.id}, canJoinGroupCall: ${room.canJoinGroupCall}, room.canJoinGroupCall: ${room.groupCallsEnabledForEveryone}', + ); } return groupCall; }