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

Commit 720bf05

Browse files
authored
Make calls automatically disconnect if the widget disappears (#9862)
If something goes wrong with the widget, there's no way we can continue the call, so this acts as a safeguard against stuck calls in cases where the widget crashes or disconnects weirdly.
1 parent 432ce3c commit 720bf05

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/models/Call.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
255255
}
256256

257257
this.room.on(RoomEvent.MyMembership, this.onMyMembership);
258+
WidgetMessagingStore.instance.on(WidgetMessagingStoreEvent.StopMessaging, this.onStopMessaging);
258259
window.addEventListener("beforeunload", this.beforeUnload);
259260
this.connectionState = ConnectionState.Connected;
260261
}
@@ -275,6 +276,7 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
275276
*/
276277
public setDisconnected() {
277278
this.room.off(RoomEvent.MyMembership, this.onMyMembership);
279+
WidgetMessagingStore.instance.off(WidgetMessagingStoreEvent.StopMessaging, this.onStopMessaging);
278280
window.removeEventListener("beforeunload", this.beforeUnload);
279281
this.messaging = null;
280282
this.connectionState = ConnectionState.Disconnected;
@@ -292,6 +294,13 @@ export abstract class Call extends TypedEventEmitter<CallEvent, CallEventHandler
292294
if (membership !== "join") this.setDisconnected();
293295
};
294296

297+
private onStopMessaging = (uid: string) => {
298+
if (uid === this.widgetUid) {
299+
logger.log("The widget died; treating this as a user hangup");
300+
this.setDisconnected();
301+
}
302+
};
303+
295304
private beforeUnload = () => this.setDisconnected();
296305
}
297306

test/models/Call-test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,13 @@ describe("ElementCall", () => {
784784
expect(call.connectionState).toBe(ConnectionState.Connected);
785785
});
786786

787+
it("disconnects if the widget dies", async () => {
788+
await call.connect();
789+
expect(call.connectionState).toBe(ConnectionState.Connected);
790+
WidgetMessagingStore.instance.stopMessaging(widget, room.roomId);
791+
expect(call.connectionState).toBe(ConnectionState.Disconnected);
792+
});
793+
787794
it("tracks participants in room state", async () => {
788795
expect(call.participants).toEqual(new Map());
789796

0 commit comments

Comments
 (0)