From 63a00eef2fd756861e3be00252cffd3b9dc77df4 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:27:07 +0200 Subject: [PATCH] await leave rtc session (#1648) 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 bc513c18..bbd9652e 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -217,13 +217,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(); }