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(); }