From c64dbb05631cf26816b5b4ca82a9514da84035ee Mon Sep 17 00:00:00 2001 From: Gigiaj Date: Sat, 3 May 2025 00:06:36 -0500 Subject: [PATCH] add a state store for which iFrame is active --- src/app/pages/client/CallProvider.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/pages/client/CallProvider.tsx b/src/app/pages/client/CallProvider.tsx index f50a007a..6edff627 100644 --- a/src/app/pages/client/CallProvider.tsx +++ b/src/app/pages/client/CallProvider.tsx @@ -41,9 +41,11 @@ interface CallContextState { isVideoEnabled: boolean; isChatOpen: boolean; isCallActive: boolean; + isPrimaryIframe: boolean; toggleAudio: () => Promise; toggleVideo: () => Promise; toggleChat: () => Promise; + toggleIframe: () => Promise; } const CallContext = createContext(undefined); @@ -56,6 +58,7 @@ const DEFAULT_AUDIO_ENABLED = true; const DEFAULT_VIDEO_ENABLED = false; const DEFAULT_CHAT_OPENED = false; const DEFAULT_CALL_ACTIVE = false; +const DEFAULT_PRIMARY_IFRAME = false; export function CallProvider({ children }: CallProviderProps) { const [activeCallRoomId, setActiveCallRoomIdState] = useState(null); @@ -68,6 +71,7 @@ export function CallProvider({ children }: CallProviderProps) { const [isVideoEnabled, setIsVideoEnabledState] = useState(DEFAULT_VIDEO_ENABLED); const [isChatOpen, setIsChatOpenState] = useState(DEFAULT_CHAT_OPENED); const [isCallActive, setIsCallActive] = useState(DEFAULT_CALL_ACTIVE); + const [isPrimaryIframe, setIsPrimaryIframe] = useState(DEFAULT_PRIMARY_IFRAME); const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>(); const mx = useMatrixClient(); @@ -165,6 +169,7 @@ export function CallProvider({ children }: CallProviderProps) { `CallContext: Received hangup action from widget in room ${activeCallRoomId}.`, ev ); + setIsPrimaryIframe(true); setIsCallActive(false); //hangUp(); }; @@ -193,6 +198,11 @@ export function CallProvider({ children }: CallProviderProps) { const handleJoin = (ev: CustomEvent) => { ev.preventDefault(); + if (isCallActive) { + setIsPrimaryIframe(false); + } else { + setIsPrimaryIframe(true); + } setIsCallActive(true); }; @@ -291,6 +301,11 @@ export function CallProvider({ children }: CallProviderProps) { setIsChatOpenState(newState); }, [isChatOpen]); + const toggleIframe = useCallback(async () => { + const newState = !isPrimaryIframe; + setIsPrimaryIframe(newState); + }, [isPrimaryIframe]); + const contextValue = useMemo( () => ({ activeCallRoomId, @@ -303,9 +318,11 @@ export function CallProvider({ children }: CallProviderProps) { isAudioEnabled, isVideoEnabled, isCallActive, + isPrimaryIframe, toggleAudio, toggleVideo, toggleChat, + toggleIframe, }), [ activeCallRoomId, @@ -318,9 +335,11 @@ export function CallProvider({ children }: CallProviderProps) { isAudioEnabled, isVideoEnabled, isCallActive, + isPrimaryIframe, toggleAudio, toggleVideo, toggleChat, + toggleIframe, ] );