chore: add MatrixSDKVoipException and some more logging

This commit is contained in:
td 2024-05-21 15:47:19 +05:30
parent 39a8b8ce89
commit b5fb43af51
No known key found for this signature in database
GPG Key ID: 62A30523D4D6CE28
7 changed files with 37 additions and 19 deletions

View File

@ -23,7 +23,8 @@ abstract class CallBackend {
type: type, type: type,
); );
} else { } else {
throw ArgumentError('Invalid type: $type'); throw MatrixSDKVoipException(
'Invalid type: $type in CallBackend.fromJson');
} }
} }

View File

@ -80,7 +80,8 @@ class LiveKitBackend extends CallBackend {
final keyProvider = groupCall.voip.delegate.keyProvider; final keyProvider = groupCall.voip.delegate.keyProvider;
if (keyProvider == null) { 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]; final myKeys = _encryptionKeysMap[groupCall.localParticipant];

View File

@ -87,8 +87,7 @@ class MeshBackend extends CallBackend {
return await groupCall.voip.delegate.mediaDevices return await groupCall.voip.delegate.mediaDevices
.getDisplayMedia(mediaConstraints); .getDisplayMedia(mediaConstraints);
} catch (e, s) { } catch (e, s) {
Logs().e('[VOIP] _getDisplayMedia failed because,', e, s); throw MatrixSDKVoipException('_getDisplayMedia failed', stackTrace: s);
rethrow;
} }
} }
@ -113,7 +112,7 @@ class MeshBackend extends CallBackend {
/// init a peer call from group calls. /// init a peer call from group calls.
Future<void> _initCall(GroupCallSession groupCall, CallSession call) async { Future<void> _initCall(GroupCallSession groupCall, CallSession call) async {
if (call.remoteUserId == null) { if (call.remoteUserId == null) {
throw Exception( throw MatrixSDKVoipException(
'Cannot init call without proper invitee user and device Id'); 'Cannot init call without proper invitee user and device Id');
} }
@ -156,7 +155,7 @@ class MeshBackend extends CallBackend {
.indexWhere((element) => element.callId == existingCall.callId); .indexWhere((element) => element.callId == existingCall.callId);
if (existingCallIndex == -1) { if (existingCallIndex == -1) {
throw Exception('Couldn\'t find call to replace'); throw MatrixSDKVoipException('Couldn\'t find call to replace');
} }
_callSessions.removeAt(existingCallIndex); _callSessions.removeAt(existingCallIndex);
@ -181,7 +180,7 @@ class MeshBackend extends CallBackend {
Future<void> _disposeCall(GroupCallSession groupCall, CallSession call, Future<void> _disposeCall(GroupCallSession groupCall, CallSession call,
CallErrorCode hangupReason) async { CallErrorCode hangupReason) async {
if (call.remoteUserId == null) { if (call.remoteUserId == null) {
throw Exception( throw MatrixSDKVoipException(
'Cannot init call without proper invitee user and device Id'); 'Cannot init call without proper invitee user and device Id');
} }
@ -223,7 +222,7 @@ class MeshBackend extends CallBackend {
Future<void> _onStreamsChanged( Future<void> _onStreamsChanged(
GroupCallSession groupCall, CallSession call) async { GroupCallSession groupCall, CallSession call) async {
if (call.remoteUserId == null) { if (call.remoteUserId == null) {
throw Exception( throw MatrixSDKVoipException(
'Cannot init call without proper invitee user and device Id'); '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); (stream) => stream.participant.id == existingStream.participant.id);
if (streamIndex == -1) { 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]); _screenshareStreams.replaceRange(streamIndex, 1, [replacementStream]);
@ -390,7 +390,8 @@ class MeshBackend extends CallBackend {
.indexWhere((stream) => stream.participant.id == stream.participant.id); .indexWhere((stream) => stream.participant.id == stream.participant.id);
if (streamIndex == -1) { if (streamIndex == -1) {
throw Exception('Couldn\'t find screenshare stream to remove'); throw MatrixSDKVoipException(
'Couldn\'t find screenshare stream to remove');
} }
_screenshareStreams.removeWhere( _screenshareStreams.removeWhere(
@ -451,7 +452,8 @@ class MeshBackend extends CallBackend {
(stream) => stream.participant.id == existingStream.participant.id); (stream) => stream.participant.id == existingStream.participant.id);
if (streamIndex == -1) { 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]); _userMediaStreams.replaceRange(streamIndex, 1, [replacementStream]);
@ -469,7 +471,8 @@ class MeshBackend extends CallBackend {
(element) => element.participant.id == stream.participant.id); (element) => element.participant.id == stream.participant.id);
if (streamIndex == -1) { 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( _userMediaStreams.removeWhere(
@ -527,7 +530,7 @@ class MeshBackend extends CallBackend {
Future<WrappedMediaStream?> initLocalStream(GroupCallSession groupCall, Future<WrappedMediaStream?> initLocalStream(GroupCallSession groupCall,
{WrappedMediaStream? stream}) async { {WrappedMediaStream? stream}) async {
if (groupCall.state != GroupCallState.localCallFeedUninitialized) { if (groupCall.state != GroupCallState.localCallFeedUninitialized) {
throw Exception( throw MatrixSDKVoipException(
'Cannot initialize local call feed in the ${groupCall.state} state.'); 'Cannot initialize local call feed in the ${groupCall.state} state.');
} }

View File

@ -928,9 +928,10 @@ class CallSession {
if (sender.track != null && sender.track!.kind == 'audio') { if (sender.track != null && sender.track!.kind == 'audio') {
await sender.dtmfSender.insertDTMF(tones); await sender.dtmfSender.insertDTMF(tones);
return; 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<void> terminate( Future<void> terminate(

View File

@ -112,7 +112,7 @@ class GroupCallSession {
Future<void> enter({WrappedMediaStream? stream}) async { Future<void> enter({WrappedMediaStream? stream}) async {
if (!(state == GroupCallState.localCallFeedUninitialized || if (!(state == GroupCallState.localCallFeedUninitialized ||
state == GroupCallState.localCallFeedInitialized)) { 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) { if (state == GroupCallState.localCallFeedUninitialized) {

View File

@ -128,8 +128,9 @@ extension FamedlyCallMemberEventsExtension on Room {
newContent, newContent,
); );
} else { } else {
throw Exception( throw MatrixSDKVoipException(
'[VOIP] User is not allowed to send famedly call member events in room'); '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<String, Object?> event) {
return false; 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';
}

View File

@ -772,8 +772,9 @@ class VoIP {
if (groupCall != null) { if (groupCall != null) {
if (!room.canJoinGroupCall) { if (!room.canJoinGroupCall) {
throw Exception( throw MatrixSDKVoipException(
'[VOIP] User is not allowed to join famedly calls in the room'); '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; return groupCall;
} }