mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 15:30:27 +03:00
add a state store for which iFrame is active
This commit is contained in:
parent
7f8aeb335f
commit
c64dbb0563
1 changed files with 19 additions and 0 deletions
|
|
@ -41,9 +41,11 @@ interface CallContextState {
|
||||||
isVideoEnabled: boolean;
|
isVideoEnabled: boolean;
|
||||||
isChatOpen: boolean;
|
isChatOpen: boolean;
|
||||||
isCallActive: boolean;
|
isCallActive: boolean;
|
||||||
|
isPrimaryIframe: boolean;
|
||||||
toggleAudio: () => Promise<void>;
|
toggleAudio: () => Promise<void>;
|
||||||
toggleVideo: () => Promise<void>;
|
toggleVideo: () => Promise<void>;
|
||||||
toggleChat: () => Promise<void>;
|
toggleChat: () => Promise<void>;
|
||||||
|
toggleIframe: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CallContext = createContext<CallContextState | undefined>(undefined);
|
const CallContext = createContext<CallContextState | undefined>(undefined);
|
||||||
|
|
@ -56,6 +58,7 @@ const DEFAULT_AUDIO_ENABLED = true;
|
||||||
const DEFAULT_VIDEO_ENABLED = false;
|
const DEFAULT_VIDEO_ENABLED = false;
|
||||||
const DEFAULT_CHAT_OPENED = false;
|
const DEFAULT_CHAT_OPENED = false;
|
||||||
const DEFAULT_CALL_ACTIVE = false;
|
const DEFAULT_CALL_ACTIVE = false;
|
||||||
|
const DEFAULT_PRIMARY_IFRAME = false;
|
||||||
|
|
||||||
export function CallProvider({ children }: CallProviderProps) {
|
export function CallProvider({ children }: CallProviderProps) {
|
||||||
const [activeCallRoomId, setActiveCallRoomIdState] = useState<string | null>(null);
|
const [activeCallRoomId, setActiveCallRoomIdState] = useState<string | null>(null);
|
||||||
|
|
@ -68,6 +71,7 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
const [isVideoEnabled, setIsVideoEnabledState] = useState<boolean>(DEFAULT_VIDEO_ENABLED);
|
const [isVideoEnabled, setIsVideoEnabledState] = useState<boolean>(DEFAULT_VIDEO_ENABLED);
|
||||||
const [isChatOpen, setIsChatOpenState] = useState<boolean>(DEFAULT_CHAT_OPENED);
|
const [isChatOpen, setIsChatOpenState] = useState<boolean>(DEFAULT_CHAT_OPENED);
|
||||||
const [isCallActive, setIsCallActive] = useState<boolean>(DEFAULT_CALL_ACTIVE);
|
const [isCallActive, setIsCallActive] = useState<boolean>(DEFAULT_CALL_ACTIVE);
|
||||||
|
const [isPrimaryIframe, setIsPrimaryIframe] = useState<boolean>(DEFAULT_PRIMARY_IFRAME);
|
||||||
|
|
||||||
const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>();
|
const { roomIdOrAlias: viewedRoomId } = useParams<{ roomIdOrAlias: string }>();
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
|
@ -165,6 +169,7 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
||||||
ev
|
ev
|
||||||
);
|
);
|
||||||
|
setIsPrimaryIframe(true);
|
||||||
setIsCallActive(false);
|
setIsCallActive(false);
|
||||||
//hangUp();
|
//hangUp();
|
||||||
};
|
};
|
||||||
|
|
@ -193,6 +198,11 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
|
|
||||||
const handleJoin = (ev: CustomEvent) => {
|
const handleJoin = (ev: CustomEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
if (isCallActive) {
|
||||||
|
setIsPrimaryIframe(false);
|
||||||
|
} else {
|
||||||
|
setIsPrimaryIframe(true);
|
||||||
|
}
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -291,6 +301,11 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
setIsChatOpenState(newState);
|
setIsChatOpenState(newState);
|
||||||
}, [isChatOpen]);
|
}, [isChatOpen]);
|
||||||
|
|
||||||
|
const toggleIframe = useCallback(async () => {
|
||||||
|
const newState = !isPrimaryIframe;
|
||||||
|
setIsPrimaryIframe(newState);
|
||||||
|
}, [isPrimaryIframe]);
|
||||||
|
|
||||||
const contextValue = useMemo<CallContextState>(
|
const contextValue = useMemo<CallContextState>(
|
||||||
() => ({
|
() => ({
|
||||||
activeCallRoomId,
|
activeCallRoomId,
|
||||||
|
|
@ -303,9 +318,11 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
isAudioEnabled,
|
isAudioEnabled,
|
||||||
isVideoEnabled,
|
isVideoEnabled,
|
||||||
isCallActive,
|
isCallActive,
|
||||||
|
isPrimaryIframe,
|
||||||
toggleAudio,
|
toggleAudio,
|
||||||
toggleVideo,
|
toggleVideo,
|
||||||
toggleChat,
|
toggleChat,
|
||||||
|
toggleIframe,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
activeCallRoomId,
|
activeCallRoomId,
|
||||||
|
|
@ -318,9 +335,11 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
isAudioEnabled,
|
isAudioEnabled,
|
||||||
isVideoEnabled,
|
isVideoEnabled,
|
||||||
isCallActive,
|
isCallActive,
|
||||||
|
isPrimaryIframe,
|
||||||
toggleAudio,
|
toggleAudio,
|
||||||
toggleVideo,
|
toggleVideo,
|
||||||
toggleChat,
|
toggleChat,
|
||||||
|
toggleIframe,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue