mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 06:50:28 +03:00
Fixes a bug where if you left a call then went to a lobby and joined it didn't update the actual activeCallRoomId
This commit is contained in:
parent
e3f1697367
commit
6edee72a15
1 changed files with 11 additions and 12 deletions
|
|
@ -206,14 +206,17 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
const hangUp = useCallback(
|
const hangUp = useCallback(
|
||||||
(nextRoom: string) => {
|
(nextRoom: string) => {
|
||||||
if (typeof nextRoom === 'string') {
|
if (typeof nextRoom === 'string') {
|
||||||
|
logger.debug('1 Hangup');
|
||||||
setActiveClientWidgetApi(null, null, null);
|
setActiveClientWidgetApi(null, null, null);
|
||||||
setActiveCallRoomIdState(null);
|
setActiveCallRoomIdState(null);
|
||||||
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
||||||
} else if (viewedRoomId !== activeCallRoomId) {
|
} else if (viewedRoomId !== activeCallRoomId) {
|
||||||
|
logger.debug('2 Hangup');
|
||||||
setActiveClientWidgetApi(null, null, null);
|
setActiveClientWidgetApi(null, null, null);
|
||||||
setActiveCallRoomIdState(null);
|
setActiveCallRoomIdState(null);
|
||||||
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
||||||
} else if (activeClientWidget) {
|
} else if (activeClientWidget) {
|
||||||
|
logger.debug('3 Hangup');
|
||||||
const iframeDoc =
|
const iframeDoc =
|
||||||
activeClientWidget?.iframe.contentDocument ||
|
activeClientWidget?.iframe.contentDocument ||
|
||||||
activeClientWidget?.iframe.contentWindow.document;
|
activeClientWidget?.iframe.contentWindow.document;
|
||||||
|
|
@ -302,13 +305,6 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
|
|
||||||
const handleJoin = (ev: CustomEvent) => {
|
const handleJoin = (ev: CustomEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
logger.error(`1
|
|
||||||
activeCall: ${activeCallRoomId}
|
|
||||||
viewedCall: ${viewedCallRoomId}
|
|
||||||
lastActiveCall: ${lastViewedRoomDuringCall}
|
|
||||||
viewed: ${viewedRoomId}
|
|
||||||
isCallActive ${isCallActive}
|
|
||||||
`);
|
|
||||||
const setViewedAsActive = () => {
|
const setViewedAsActive = () => {
|
||||||
if (viewedCallRoomId !== activeCallRoomId) setIsPrimaryIframe(!isPrimaryIframe);
|
if (viewedCallRoomId !== activeCallRoomId) setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
setActiveClientWidgetApi(viewedClientWidgetApi, viewedClientWidget, viewedCallRoomId);
|
setActiveClientWidgetApi(viewedClientWidgetApi, viewedClientWidget, viewedCallRoomId);
|
||||||
|
|
@ -324,15 +320,12 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
setIsCallActive(false);
|
setIsCallActive(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
});
|
});
|
||||||
observer.observe(iframeDoc, { childList: true, subtree: true });
|
observer.observe(iframeDoc, { childList: true, subtree: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
||||||
ev.detail.widgetId === activeClientWidgetApi?.widget.id
|
|
||||||
) {
|
|
||||||
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
const iframeDoc =
|
const iframeDoc =
|
||||||
activeClientWidget?.iframe.contentDocument ||
|
activeClientWidget?.iframe.contentDocument ||
|
||||||
|
|
@ -346,6 +339,7 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
}
|
}
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
});
|
});
|
||||||
|
logger.debug('1 Join');
|
||||||
observer.observe(iframeDoc, { childList: true, subtree: true });
|
observer.observe(iframeDoc, { childList: true, subtree: true });
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
return;
|
return;
|
||||||
|
|
@ -355,22 +349,27 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
viewedRoomId === activeCallRoomId &&
|
viewedRoomId === activeCallRoomId &&
|
||||||
lastViewedRoomDuringCall === activeCallRoomId
|
lastViewedRoomDuringCall === activeCallRoomId
|
||||||
) {
|
) {
|
||||||
|
logger.debug('2 Join');
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
logger.error('Active widget joined on? Most likely a new widget after a hangup method.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (activeClientWidgetApi) {
|
if (activeClientWidgetApi) {
|
||||||
if (isCallActive && viewedClientWidgetApi && viewedCallRoomId) {
|
if (isCallActive && viewedClientWidgetApi && viewedCallRoomId) {
|
||||||
activeClientWidgetApi?.removeAllListeners();
|
activeClientWidgetApi?.removeAllListeners();
|
||||||
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
||||||
|
logger.debug('3 Join');
|
||||||
setViewedAsActive();
|
setViewedAsActive();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
logger.debug('4 Join');
|
||||||
|
setViewedAsActive();
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
}
|
}
|
||||||
} else if (viewedCallRoomId !== viewedRoomId) {
|
} else if (viewedCallRoomId !== viewedRoomId) {
|
||||||
|
logger.debug('5 Join');
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
} else {
|
} else {
|
||||||
|
logger.debug('6 Join');
|
||||||
setViewedAsActive();
|
setViewedAsActive();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue