Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 19efa09

Browse files
authored
Handle Jitsi Meet crashes more gracefully (#8541)
1 parent 333dd59 commit 19efa09

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/stores/VideoChannelStore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
159159
messaging.on(`action:${ElementWidgetActions.UnmuteAudio}`, this.onUnmuteAudio);
160160
messaging.on(`action:${ElementWidgetActions.MuteVideo}`, this.onMuteVideo);
161161
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);
162166

163167
this.emit(VideoChannelEvent.StartConnect, roomId);
164168

@@ -186,14 +190,14 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
186190
messaging.off(`action:${ElementWidgetActions.UnmuteAudio}`, this.onUnmuteAudio);
187191
messaging.off(`action:${ElementWidgetActions.MuteVideo}`, this.onMuteVideo);
188192
messaging.off(`action:${ElementWidgetActions.UnmuteVideo}`, this.onUnmuteVideo);
193+
messaging.off(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
189194

190195
this.emit(VideoChannelEvent.Disconnect, roomId);
191196

192197
throw new Error(`Failed to join call in room ${roomId}: ${e}`);
193198
}
194199

195200
this.connected = true;
196-
messaging.once(`action:${ElementWidgetActions.HangupCall}`, this.onHangup);
197201
this.matrixClient.getRoom(roomId).on(RoomEvent.MyMembership, this.onMyMembership);
198202
window.addEventListener("beforeunload", this.setDisconnected);
199203

@@ -258,6 +262,9 @@ export default class VideoChannelStore extends AsyncStoreWithClient<null> {
258262

259263
private onHangup = async (ev: CustomEvent<IWidgetApiRequest>) => {
260264
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);
261268
await this.setDisconnected();
262269
};
263270

0 commit comments

Comments
 (0)