@@ -159,6 +159,10 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
159
159
messaging . on ( `action:${ ElementWidgetActions . UnmuteAudio } ` , this . onUnmuteAudio ) ;
160
160
messaging . on ( `action:${ ElementWidgetActions . MuteVideo } ` , this . onMuteVideo ) ;
161
161
messaging . on ( `action:${ ElementWidgetActions . UnmuteVideo } ` , this . onUnmuteVideo ) ;
162
+ // Empirically, it's possible for Jitsi Meet to crash instantly at startup,
163
+ // sending a hangup event that races with the rest of this method, so we also
164
+ // need to add the hangup listener now rather than later
165
+ messaging . once ( `action:${ ElementWidgetActions . HangupCall } ` , this . onHangup ) ;
162
166
163
167
this . emit ( VideoChannelEvent . StartConnect , roomId ) ;
164
168
@@ -186,14 +190,14 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
186
190
messaging . off ( `action:${ ElementWidgetActions . UnmuteAudio } ` , this . onUnmuteAudio ) ;
187
191
messaging . off ( `action:${ ElementWidgetActions . MuteVideo } ` , this . onMuteVideo ) ;
188
192
messaging . off ( `action:${ ElementWidgetActions . UnmuteVideo } ` , this . onUnmuteVideo ) ;
193
+ messaging . off ( `action:${ ElementWidgetActions . HangupCall } ` , this . onHangup ) ;
189
194
190
195
this . emit ( VideoChannelEvent . Disconnect , roomId ) ;
191
196
192
197
throw new Error ( `Failed to join call in room ${ roomId } : ${ e } ` ) ;
193
198
}
194
199
195
200
this . connected = true ;
196
- messaging . once ( `action:${ ElementWidgetActions . HangupCall } ` , this . onHangup ) ;
197
201
this . matrixClient . getRoom ( roomId ) . on ( RoomEvent . MyMembership , this . onMyMembership ) ;
198
202
window . addEventListener ( "beforeunload" , this . setDisconnected ) ;
199
203
@@ -258,6 +262,9 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
258
262
259
263
private onHangup = async ( ev : CustomEvent < IWidgetApiRequest > ) => {
260
264
this . ack ( ev ) ;
265
+ // In case this hangup is caused by Jitsi Meet crashing at startup,
266
+ // wait for the connection event in order to avoid racing
267
+ if ( ! this . connected ) await waitForEvent ( this , VideoChannelEvent . Connect ) ;
261
268
await this . setDisconnected ( ) ;
262
269
} ;
263
270
0 commit comments