Testing the iframe juggling. Seems to work for the first and second joins... so likely on the right path with this

This commit is contained in:
Gigiaj 2025-05-11 17:55:04 -05:00
parent 5ab0b39152
commit f3612e23c6

View file

@ -132,8 +132,9 @@ export function CallProvider({ children }: CallProviderProps) {
const hangUp = useCallback(() => { const hangUp = useCallback(() => {
logger.debug(`CallContext: Hang up called.`); logger.debug(`CallContext: Hang up called.`);
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {}); activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
setIsCallActive(false); //setActiveCallRoomIdState(null);
}, [activeClientWidgetApi]); //setIsCallActive(false);
}, [activeClientWidgetApi?.transport]);
const setActiveClientWidgetApi = useCallback( const setActiveClientWidgetApi = useCallback(
(clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => { (clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => {
@ -182,11 +183,11 @@ export function CallProvider({ children }: CallProviderProps) {
} }
if (roomId && clientWidgetApi) { if (roomId && clientWidgetApi) {
logger.error(`CallContext: Registering active clientWidgetApi for room ${roomId}.`); logger.error(`CallContext: Registering viewed clientWidgetApi for room ${roomId}.`);
setViewedClientWidgetApi(clientWidgetApi, roomId); setViewedClientWidgetApi(clientWidgetApi, roomId);
} else if (roomId === viewedClientWidgetApiRoomId || roomId === null) { } else if (roomId === viewedClientWidgetApiRoomId || roomId === null) {
logger.error( logger.error(
`CallContext: Clearing active clientWidgetApi for room ${viewedClientWidgetApiRoomId}.` `CallContext: Clearing viewed clientWidgetApi for room ${viewedClientWidgetApiRoomId}.`
); );
setViewedClientWidgetApi(null, null); setViewedClientWidgetApi(null, null);
//resetMediaState(); //resetMediaState();
@ -200,19 +201,13 @@ export function CallProvider({ children }: CallProviderProps) {
); );
useEffect(() => { useEffect(() => {
if ( if (!activeCallRoomId || !viewedCallRoomId) {
!activeClientWidgetApi ||
!viewedClientWidgetApi ||
!activeCallRoomId ||
!viewedCallRoomId ||
isCallActive
) {
return; return;
} }
//logger.error(viewedClientWidgetApi); //logger.error(viewedClientWidgetApi);
const handleHangup = (ev: CustomEvent) => { const handleHangup = (ev: CustomEvent) => {
ev.preventDefault(); ev.preventDefault();
hangUp(); //hangUp();
// if (!isPrimaryIframe) { // if (!isPrimaryIframe) {
activeClientWidgetApi?.transport.reply(ev.detail, {}); activeClientWidgetApi?.transport.reply(ev.detail, {});
// } else { // } else {
@ -223,7 +218,7 @@ export function CallProvider({ children }: CallProviderProps) {
ev ev
); );
//setIsPrimaryIframe(!isPrimaryIframe); //setIsPrimaryIframe(!isPrimaryIframe);
setIsCallActive(false); //setIsCallActive(false);
//setActiveCallRoomIdState(null); //setActiveCallRoomIdState(null);
}; };
@ -255,16 +250,53 @@ export function CallProvider({ children }: CallProviderProps) {
const handleJoin = (ev: CustomEvent) => { const handleJoin = (ev: CustomEvent) => {
ev.preventDefault(); ev.preventDefault();
if (isCallActive && activeClientWidgetApi) {
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => { logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error('PRE Swap');
logger.error(isCallActive.toString());
logger.error(activeClientWidgetApi);
logger.error(viewedClientWidgetApi);
activeClientWidgetApi?.transport.reply(ev.detail, {});
if (isCallActive && activeClientWidgetApi && viewedClientWidgetApi) {
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
logger.error('Primary Swap');
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {});
setActiveCallRoomIdState(viewedCallRoomId); setActiveCallRoomIdState(viewedCallRoomId);
setActiveClientWidgetApi(viewedClientWidgetApi, viewedCallRoomId); setActiveClientWidgetApi(viewedClientWidgetApi, viewedCallRoomId);
//setIsPrimaryIframe(!isPrimaryIframe); setIsPrimaryIframe(!isPrimaryIframe);
//setViewedCallRoomId(null);
//setViewedClientWidgetApi(null, null); //setViewedClientWidgetApi(null, null);
setIsCallActive(true); //setViewedClientWidgetApi(null, null);
activeClientWidgetApi?.transport.reply(ev.detail, {}); } else {
}); //setActiveCallRoomIdState(viewedCallRoomId);
} }
setIsCallActive(true);
}; };
logger.debug( logger.debug(