refactor widget hangup procedure

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo K
2023-10-30 15:30:33 +01:00
parent 9c449c8de6
commit b9b2a1b104
3 changed files with 19 additions and 22 deletions

View File

@@ -201,22 +201,6 @@ export const GroupCallView: FC<Props> = ({
const [leaveError, setLeaveError] = useState<Error | undefined>(undefined);
const history = useHistory();
const widgetPostHangupProcedure = async (): Promise<void> => {
if (!widget) {
logger.warn("called widgetPostHangupProcedure without a widget.");
return;
}
// 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, {});
};
const onLeave = useCallback(
async (leaveError?: Error) => {
setLeaveError(leaveError);
@@ -232,9 +216,6 @@ export const GroupCallView: FC<Props> = ({
);
await leaveRTCSession(rtcSession);
if (widget) {
widgetPostHangupProcedure();
}
if (
!isPasswordlessUser &&
@@ -254,7 +235,6 @@ export const GroupCallView: FC<Props> = ({
): Promise<void> => {
widget!.api.transport.reply(ev.detail, {});
await leaveRTCSession(rtcSession);
widgetPostHangupProcedure();
};
widget.lazyActions.once(ElementWidgetActions.HangupCall, onHangup);
return () => {