From b0610902971a46dcd21e81d4dd55be10dca4d5f4 Mon Sep 17 00:00:00 2001 From: Timo K Date: Thu, 28 Sep 2023 14:00:19 +0200 Subject: [PATCH] await leave rtc session so that the widget is only getting the hangup even, once the call has been cleaned up Signed-off-by: Timo K --- src/room/GroupCallView.tsx | 5 ++++- src/rtcSessionHelpers.ts | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index ab96926a..e6e48129 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -224,13 +224,16 @@ export function GroupCallView({ sendInstantly ); - leaveRTCSession(rtcSession); + await leaveRTCSession(rtcSession); if (widget) { // we need to wait until the callEnded event is tracked on posthog. // Otherwise the iFrame gets killed before the callEnded event got tracked. await new Promise((resolve) => window.setTimeout(resolve, 10)); // 10ms widget.api.setAlwaysOnScreen(false); PosthogAnalytics.instance.logout(); + + // we will always send the hangup event after the memberships have been updated + // calling leaveRTCSession. widget.api.transport.send(ElementWidgetActions.HangupCall, {}); } diff --git a/src/rtcSessionHelpers.ts b/src/rtcSessionHelpers.ts index 3d62f980..3cad5627 100644 --- a/src/rtcSessionHelpers.ts +++ b/src/rtcSessionHelpers.ts @@ -47,7 +47,9 @@ export function enterRTCSession(rtcSession: MatrixRTCSession) { rtcSession.joinRoomSession([makeFocus(livekitAlias)]); } -export function leaveRTCSession(rtcSession: MatrixRTCSession) { +export async function leaveRTCSession( + rtcSession: MatrixRTCSession +): Promise { //groupCallOTelMembership?.onLeaveCall(); - rtcSession.leaveRoomSession(); + await rtcSession.leaveRoomSession(); }