@@ -18,6 +18,7 @@ limitations under the License.
18
18
*/
19
19
20
20
import React from "react" ;
21
+ import { MatrixError } from "matrix-js-sdk/src/matrix" ;
21
22
import {
22
23
CallError ,
23
24
CallErrorCode ,
@@ -29,7 +30,7 @@ import {
29
30
} from "matrix-js-sdk/src/webrtc/call" ;
30
31
import { logger } from "matrix-js-sdk/src/logger" ;
31
32
import EventEmitter from "events" ;
32
- import { RuleId , TweakName , Tweaks } from "matrix-js-sdk/src/@types/PushRules" ;
33
+ import { RuleId , TweakName } from "matrix-js-sdk/src/@types/PushRules" ;
33
34
import { PushProcessor } from "matrix-js-sdk/src/pushprocessor" ;
34
35
import { SyncState } from "matrix-js-sdk/src/sync" ;
35
36
import { CallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/callEventHandler" ;
@@ -65,6 +66,7 @@ import { getJoinedNonFunctionalMembers } from "./utils/room/getJoinedNonFunction
65
66
import { localNotificationsAreSilenced } from "./utils/notifications" ;
66
67
import { SdkContextClass } from "./contexts/SDKContext" ;
67
68
import { showCantStartACallDialog } from "./voice-broadcast/utils/showCantStartACallDialog" ;
69
+ import { isNotNull } from "./Typeguards" ;
68
70
69
71
export const PROTOCOL_PSTN = "m.protocol.pstn" ;
70
72
export const PROTOCOL_PSTN_PREFIXED = "im.vector.protocol.pstn" ;
@@ -582,7 +584,9 @@ export default class LegacyCallHandler extends EventEmitter {
582
584
call . on ( CallEvent . Hangup , ( ) => {
583
585
if ( ! mappedRoomId || ! this . matchesCallForThisRoom ( call ) ) return ;
584
586
585
- this . removeCallForRoom ( mappedRoomId ) ;
587
+ if ( isNotNull ( mappedRoomId ) ) {
588
+ this . removeCallForRoom ( mappedRoomId ) ;
589
+ }
586
590
} ) ;
587
591
call . on ( CallEvent . State , ( newState : CallState , oldState : CallState ) => {
588
592
this . onCallStateChanged ( newState , oldState , call ) ;
@@ -598,8 +602,10 @@ export default class LegacyCallHandler extends EventEmitter {
598
602
this . pause ( AudioID . Ringback ) ;
599
603
}
600
604
601
- this . removeCallForRoom ( mappedRoomId ) ;
602
- this . addCallForRoom ( mappedRoomId , newCall ) ;
605
+ if ( isNotNull ( mappedRoomId ) ) {
606
+ this . removeCallForRoom ( mappedRoomId ) ;
607
+ this . addCallForRoom ( mappedRoomId , newCall ) ;
608
+ }
603
609
this . setCallListeners ( newCall ) ;
604
610
this . setCallState ( newCall , newCall . state ) ;
605
611
} ) ;
@@ -635,7 +641,7 @@ export default class LegacyCallHandler extends EventEmitter {
635
641
636
642
const newMappedRoomId = this . roomIdForCall ( call ) ;
637
643
logger . log ( `Old room ID: ${ mappedRoomId } , new room ID: ${ newMappedRoomId } ` ) ;
638
- if ( newMappedRoomId && newMappedRoomId !== mappedRoomId ) {
644
+ if ( newMappedRoomId !== mappedRoomId && isNotNull ( mappedRoomId ) && isNotNull ( newMappedRoomId ) ) {
639
645
this . removeCallForRoom ( mappedRoomId ) ;
640
646
mappedRoomId = newMappedRoomId ;
641
647
logger . log ( "Moving call to room " + mappedRoomId ) ;
@@ -675,8 +681,11 @@ export default class LegacyCallHandler extends EventEmitter {
675
681
RuleId . IncomingCall ,
676
682
) ;
677
683
const pushRuleEnabled = incomingCallPushRule ?. enabled ;
684
+ // actions can be either Tweaks | PushRuleActionName, ie an object or a string type enum
685
+ // and we want to only run this check on the Tweaks
678
686
const tweakSetToRing = incomingCallPushRule ?. actions . some (
679
- ( action : Tweaks ) => action . set_tweak === TweakName . Sound && action . value === "ring" ,
687
+ ( action ) =>
688
+ typeof action !== "string" && action . set_tweak === TweakName . Sound && action . value === "ring" ,
680
689
) ;
681
690
682
691
if ( pushRuleEnabled && tweakSetToRing && ! this . isForcedSilent ( ) ) {
@@ -692,7 +701,10 @@ export default class LegacyCallHandler extends EventEmitter {
692
701
}
693
702
case CallState . Ended : {
694
703
const hangupReason = call . hangupReason ;
695
- this . removeCallForRoom ( mappedRoomId ) ;
704
+ if ( isNotNull ( mappedRoomId ) ) {
705
+ this . removeCallForRoom ( mappedRoomId ) ;
706
+ }
707
+
696
708
if ( oldState === CallState . InviteSent && call . hangupParty === CallParty . Remote ) {
697
709
this . play ( AudioID . Busy ) ;
698
710
@@ -724,7 +736,9 @@ export default class LegacyCallHandler extends EventEmitter {
724
736
this . play ( AudioID . CallEnd ) ;
725
737
}
726
738
727
- this . logCallStats ( call , mappedRoomId ) ;
739
+ if ( isNotNull ( mappedRoomId ) ) {
740
+ this . logCallStats ( call , mappedRoomId ) ;
741
+ }
728
742
break ;
729
743
}
730
744
}
@@ -1081,13 +1095,15 @@ export default class LegacyCallHandler extends EventEmitter {
1081
1095
1082
1096
const roomId = await ensureDMExists ( MatrixClientPeg . get ( ) , nativeUserId ) ;
1083
1097
1084
- dis . dispatch < ViewRoomPayload > ( {
1085
- action : Action . ViewRoom ,
1086
- room_id : roomId ,
1087
- metricsTrigger : "WebDialPad" ,
1088
- } ) ;
1098
+ if ( isNotNull ( roomId ) ) {
1099
+ dis . dispatch < ViewRoomPayload > ( {
1100
+ action : Action . ViewRoom ,
1101
+ room_id : roomId ,
1102
+ metricsTrigger : "WebDialPad" ,
1103
+ } ) ;
1089
1104
1090
- await this . placeMatrixCall ( roomId , CallType . Voice , transferee ) ;
1105
+ await this . placeMatrixCall ( roomId , CallType . Voice , transferee ) ;
1106
+ }
1091
1107
}
1092
1108
1093
1109
public async startTransferToPhoneNumber (
@@ -1183,17 +1199,19 @@ export default class LegacyCallHandler extends EventEmitter {
1183
1199
// Prevent double clicking the call button
1184
1200
const widget = WidgetStore . instance . getApps ( roomId ) . find ( ( app ) => WidgetType . JITSI . matches ( app . type ) ) ;
1185
1201
if ( widget ) {
1186
- const room = client . getRoom ( roomId ) ;
1187
1202
// If there already is a Jitsi widget, pin it
1188
- if ( room ) WidgetLayoutStore . instance . moveToContainer ( room , widget , Container . Top ) ;
1203
+ const room = client . getRoom ( roomId ) ;
1204
+ if ( isNotNull ( room ) ) {
1205
+ WidgetLayoutStore . instance . moveToContainer ( room , widget , Container . Top ) ;
1206
+ }
1189
1207
return ;
1190
1208
}
1191
1209
1192
1210
try {
1193
1211
await WidgetUtils . addJitsiWidget ( roomId , type , "Jitsi" , false ) ;
1194
1212
logger . log ( "Jitsi widget added" ) ;
1195
1213
} catch ( e ) {
1196
- if ( e . errcode === "M_FORBIDDEN" ) {
1214
+ if ( e instanceof MatrixError && e . errcode === "M_FORBIDDEN" ) {
1197
1215
Modal . createDialog ( ErrorDialog , {
1198
1216
title : _t ( "Permission Required" ) ,
1199
1217
description : _t ( "You do not have permission to start a conference call in this room" ) ,
0 commit comments