From 6e33c8e8da911fd605644c6a96dc20f954f922cf Mon Sep 17 00:00:00 2001 From: Gigiaj Date: Wed, 21 May 2025 21:14:31 -0500 Subject: [PATCH] Applies the correct changes to the call state and removes listeners of old active widget so we don't trigger hang ups on the new one (the element-call widget likes to spam the hang up response back several times for some reason long after you tell it to hang up) --- src/app/pages/client/CallProvider.tsx | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/app/pages/client/CallProvider.tsx b/src/app/pages/client/CallProvider.tsx index 0aa27a5a..039ddfa1 100644 --- a/src/app/pages/client/CallProvider.tsx +++ b/src/app/pages/client/CallProvider.tsx @@ -129,9 +129,10 @@ export function CallProvider({ children }: CallProviderProps) { const hangUp = useCallback(() => { logger.debug(`CallContext: Hang up called.`); activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {}); + viewedClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {}); setActiveCallRoomIdState(null); setIsCallActive(false); - }, [activeClientWidgetApi?.transport]); + }, [activeClientWidgetApi?.transport, viewedClientWidgetApi?.transport]); const setActiveClientWidgetApi = useCallback( (clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => { @@ -198,18 +199,22 @@ export function CallProvider({ children }: CallProviderProps) { ); useEffect(() => { - if (!activeCallRoomId || !viewedCallRoomId) { + if (!activeCallRoomId && !viewedCallRoomId) { return; } const handleHangup = (ev: CustomEvent) => { ev.preventDefault(); - activeClientWidgetApi?.transport.reply(ev.detail, {}); - viewedClientWidgetApi?.transport.reply(ev.detail, {}); + if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) { + activeClientWidgetApi?.transport.reply(ev.detail, {}); + setIsCallActive(false); + } else if (ev.detail.widgetId === viewedClientWidgetApi?.widget.id) { + viewedClientWidgetApi?.transport.reply(ev.detail, {}); + setIsCallActive(false); + } logger.warn( `CallContext: Received hangup action from widget in room ${activeCallRoomId}.`, ev ); - setIsCallActive(false); }; const handleMediaStateUpdate = (ev: CustomEvent) => { @@ -241,16 +246,20 @@ export function CallProvider({ children }: CallProviderProps) { const handleJoin = (ev: CustomEvent) => { ev.preventDefault(); - logger.error(isCallActive.toString()); - logger.error(activeClientWidgetApi); - logger.error(viewedClientWidgetApi); - activeClientWidgetApi?.transport.reply(ev.detail, {}); + if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) { + setIsCallActive(true); + return; + } + if (isCallActive && activeClientWidgetApi && viewedClientWidgetApi) { + activeClientWidgetApi?.removeAllListeners(); activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => { - setActiveCallRoomIdState(viewedCallRoomId); setActiveClientWidgetApi(viewedClientWidgetApi, viewedCallRoomId); + setActiveCallRoomIdState(viewedCallRoomId); + setViewedClientWidgetApi(null, null); setIsPrimaryIframe(!isPrimaryIframe); + setIsCallActive(true); }); } else { setIsCallActive(true);