From 720bf0573a8317c415d901cb3a2faccb519c0d22 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 4 Jan 2023 15:51:42 -0500 Subject: [PATCH] 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. --- src/models/Call.ts | 9 +++++++++ test/models/Call-test.ts | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/models/Call.ts b/src/models/Call.ts index 2b996c96c3..eaee7df2e8 100644 --- a/src/models/Call.ts +++ b/src/models/Call.ts @@ -255,6 +255,7 @@ export abstract class Call extends TypedEventEmitter { + if (uid === this.widgetUid) { + logger.log("The widget died; treating this as a user hangup"); + this.setDisconnected(); + } + }; + private beforeUnload = () => this.setDisconnected(); } diff --git a/test/models/Call-test.ts b/test/models/Call-test.ts index ad6bb362dd..17f4fbfc4a 100644 --- a/test/models/Call-test.ts +++ b/test/models/Call-test.ts @@ -784,6 +784,13 @@ describe("ElementCall", () => { expect(call.connectionState).toBe(ConnectionState.Connected); }); + it("disconnects if the widget dies", async () => { + await call.connect(); + expect(call.connectionState).toBe(ConnectionState.Connected); + WidgetMessagingStore.instance.stopMessaging(widget, room.roomId); + expect(call.connectionState).toBe(ConnectionState.Disconnected); + }); + it("tracks participants in room state", async () => { expect(call.participants).toEqual(new Map());