mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 23:30:28 +03:00
Remove superfluous comments and Date.now() that was causing loading... bug when widgetId desynced
This commit is contained in:
parent
6e33c8e8da
commit
7ef33400c1
1 changed files with 12 additions and 63 deletions
|
|
@ -49,34 +49,8 @@ export function PersistentCallContainer({ children }: PersistentCallContainerPro
|
||||||
[activeCallRoomId, viewedRoomId]
|
[activeCallRoomId, viewedRoomId]
|
||||||
);
|
);
|
||||||
|
|
||||||
// logger.error('RANDOM LOG RANDOM LOG RANDOM LOG\n\n\n\n\n\n');
|
|
||||||
// logger.error(room?.normalizedName);
|
|
||||||
|
|
||||||
const setupWidget = useCallback(
|
const setupWidget = useCallback(
|
||||||
(widgetApiRef, smallWidgetRef, iframeRef, skipLobby) => {
|
(widgetApiRef, smallWidgetRef, iframeRef, skipLobby) => {
|
||||||
/**
|
|
||||||
* TODO:
|
|
||||||
* Need proper shutdown handling. Events from the previous widget can still come through it seems. Might need
|
|
||||||
* to queue the events and then allow the join to actually occur. This will *work* for now as it does handle switching technically.
|
|
||||||
* Need to look closer at it.
|
|
||||||
*
|
|
||||||
* Might also be able to keep the iframe alive and instead navigate to a new "room" to make the transition smoother
|
|
||||||
*/
|
|
||||||
const cleanup = () => {
|
|
||||||
// logger.error(`CallContext: Cleaning up for previous room: ${cleanupRoomId}`);
|
|
||||||
|
|
||||||
if (smallWidgetRef.current) {
|
|
||||||
// smallWidgetRef.current.stopMessaging();
|
|
||||||
}
|
|
||||||
// Potentially call widgetApi.stop() or similar if the API instance has it
|
|
||||||
if (widgetApiRef.current) {
|
|
||||||
// widgetApiRef.current.stop?.();
|
|
||||||
}
|
|
||||||
// widgetApiRef.current = null;
|
|
||||||
// smallWidgetRef.current = null;
|
|
||||||
// if (iframeRef.current) iframeRef.current.src = 'about:blank';
|
|
||||||
};
|
|
||||||
|
|
||||||
if (mx?.getUserId()) {
|
if (mx?.getUserId()) {
|
||||||
if (
|
if (
|
||||||
(activeCallRoomId !== viewedCallRoomId && isCallActive) ||
|
(activeCallRoomId !== viewedCallRoomId && isCallActive) ||
|
||||||
|
|
@ -96,63 +70,48 @@ export function PersistentCallContainer({ children }: PersistentCallContainerPro
|
||||||
returnToLobby: 'true',
|
returnToLobby: 'true',
|
||||||
perParticipentE2EE: 'true',
|
perParticipentE2EE: 'true',
|
||||||
});
|
});
|
||||||
if (iframeRef.current && iframeRef.current.src !== newUrl.toString()) {
|
|
||||||
logger.info(
|
|
||||||
`PersistentCallContainer: Updating iframe src for ${roomIdToSet} to ${newUrl.toString()}`
|
|
||||||
);
|
|
||||||
cleanup();
|
|
||||||
iframeRef.current.src = newUrl.toString();
|
|
||||||
} else if (iframeRef.current && !iframeRef.current.src) {
|
|
||||||
logger.info(
|
|
||||||
`PersistentCallContainer: Setting initial iframe src for ${roomIdToSet} to ${newUrl.toString()}`
|
|
||||||
);
|
|
||||||
iframeRef.current.src = newUrl.toString();
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
newUrl.toString() === primarySmallWidgetRef?.current?.url ||
|
newUrl.toString() === primarySmallWidgetRef?.current?.url ||
|
||||||
newUrl.toString() === backupSmallWidgetRef?.current?.url
|
newUrl.toString() === backupSmallWidgetRef?.current?.url
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logger.error(
|
if (iframeRef.current && iframeRef.current.src !== newUrl.toString()) {
|
||||||
`New: ${roomIdToSet}
|
iframeRef.current.src = newUrl.toString();
|
||||||
\n Primary: ${primarySmallWidgetRef?.current?.roomId}
|
} else if (iframeRef.current && !iframeRef.current.src) {
|
||||||
\n Backup: ${backupSmallWidgetRef?.current?.roomId}`
|
iframeRef.current.src = newUrl.toString();
|
||||||
);
|
}
|
||||||
|
|
||||||
const iframeElement = iframeRef.current;
|
const iframeElement = iframeRef.current;
|
||||||
if (!iframeElement) {
|
if (!iframeElement) {
|
||||||
logger.error('PersistentCallContainer: iframeRef is null, cannot setup API.');
|
return;
|
||||||
return cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = mx.getUserId() ?? '';
|
const userId = mx.getUserId() ?? '';
|
||||||
const app = createVirtualWidget(
|
const app = createVirtualWidget(
|
||||||
mx,
|
mx,
|
||||||
`element-call-${roomIdToSet}-${Date.now()}`,
|
`element-call-${roomIdToSet}`,
|
||||||
userId,
|
userId,
|
||||||
'Element Call',
|
'Element Call',
|
||||||
'm.call',
|
'm.call',
|
||||||
newUrl,
|
newUrl,
|
||||||
false,
|
true,
|
||||||
getWidgetData(mx, roomIdToSet, {}, { skipLobby: true }),
|
getWidgetData(mx, roomIdToSet, {}, { skipLobby: true }),
|
||||||
roomIdToSet
|
roomIdToSet
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.error(`PersistentCallContainer: Creating new SmallWidget/API for ${roomIdToSet}`);
|
// logger.error(`PersistentCallContainer: Creating new SmallWidget/API for ${roomIdToSet}`);
|
||||||
const smallWidget = new SmallWidget(app);
|
const smallWidget = new SmallWidget(app);
|
||||||
smallWidgetRef.current = smallWidget;
|
smallWidgetRef.current = smallWidget;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const widgetApiInstance = smallWidget.startMessaging(iframeElement);
|
const widgetApiInstance = smallWidget.startMessaging(iframeElement);
|
||||||
widgetApiRef.current = widgetApiInstance;
|
widgetApiRef.current = widgetApiInstance;
|
||||||
logger.error('Pre-register');
|
|
||||||
|
|
||||||
logger.error(`This is our check: ${skipLobby}`);
|
|
||||||
if (skipLobby) {
|
if (skipLobby) {
|
||||||
registerActiveClientWidgetApi(activeCallRoomId, widgetApiRef.current);
|
registerActiveClientWidgetApi(activeCallRoomId, widgetApiRef.current);
|
||||||
} else {
|
} else {
|
||||||
registerViewedClientWidgetApi(viewedCallRoomId, widgetApiRef.current);
|
registerViewedClientWidgetApi(viewedCallRoomId, widgetApiRef.current);
|
||||||
logger.error('Post view register');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
widgetApiInstance.once('ready', () => {
|
widgetApiInstance.once('ready', () => {
|
||||||
|
|
@ -163,19 +122,9 @@ export function PersistentCallContainer({ children }: PersistentCallContainerPro
|
||||||
`PersistentCallContainer: Error initializing widget messaging for ${roomIdToSet}:`,
|
`PersistentCallContainer: Error initializing widget messaging for ${roomIdToSet}:`,
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
if (iframeRef.current && iframeRef.current.src !== 'about:blank') {
|
|
||||||
logger.info('PersistentCallContainer: No active call, setting src to about:blank');
|
|
||||||
iframeRef.current.src = 'about:blank';
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
cleanup();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cleanup;
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
activeCallRoomId,
|
activeCallRoomId,
|
||||||
|
|
@ -189,7 +138,7 @@ export function PersistentCallContainer({ children }: PersistentCallContainerPro
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
logger.error(`This is our param: ${isPrimaryIframe}`);
|
//logger.error(`This is our param: ${isPrimaryIframe}`);
|
||||||
setupWidget(primaryWidgetApiRef, primarySmallWidgetRef, primaryIframeRef, isPrimaryIframe);
|
setupWidget(primaryWidgetApiRef, primarySmallWidgetRef, primaryIframeRef, isPrimaryIframe);
|
||||||
setupWidget(backupWidgetApiRef, backupSmallWidgetRef, backupIframeRef, !isPrimaryIframe);
|
setupWidget(backupWidgetApiRef, backupSmallWidgetRef, backupIframeRef, !isPrimaryIframe);
|
||||||
}, [
|
}, [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue