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; }