mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-06 07:20:29 +03:00
Applies the correct changes to the call state and removes listeners of old active widget so we don't trigger hang ups on the new one (the element-call widget likes to spam the hang up response back several times for some reason long after you tell it to hang up)
This commit is contained in:
parent
d9c0c85483
commit
6e33c8e8da
1 changed files with 19 additions and 10 deletions
|
|
@ -129,9 +129,10 @@ 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}`, {});
|
||||||
|
viewedClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
||||||
setActiveCallRoomIdState(null);
|
setActiveCallRoomIdState(null);
|
||||||
setIsCallActive(false);
|
setIsCallActive(false);
|
||||||
}, [activeClientWidgetApi?.transport]);
|
}, [activeClientWidgetApi?.transport, viewedClientWidgetApi?.transport]);
|
||||||
|
|
||||||
const setActiveClientWidgetApi = useCallback(
|
const setActiveClientWidgetApi = useCallback(
|
||||||
(clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => {
|
(clientWidgetApi: ClientWidgetApi | null, roomId: string | null) => {
|
||||||
|
|
@ -198,18 +199,22 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeCallRoomId || !viewedCallRoomId) {
|
if (!activeCallRoomId && !viewedCallRoomId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const handleHangup = (ev: CustomEvent) => {
|
const handleHangup = (ev: CustomEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
||||||
viewedClientWidgetApi?.transport.reply(ev.detail, {});
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
setIsCallActive(false);
|
||||||
|
} else if (ev.detail.widgetId === viewedClientWidgetApi?.widget.id) {
|
||||||
|
viewedClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
setIsCallActive(false);
|
||||||
|
}
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
||||||
ev
|
ev
|
||||||
);
|
);
|
||||||
setIsCallActive(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMediaStateUpdate = (ev: CustomEvent<MediaStatePayload>) => {
|
const handleMediaStateUpdate = (ev: CustomEvent<MediaStatePayload>) => {
|
||||||
|
|
@ -241,16 +246,20 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
const handleJoin = (ev: CustomEvent) => {
|
const handleJoin = (ev: CustomEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
|
||||||
logger.error(isCallActive.toString());
|
|
||||||
logger.error(activeClientWidgetApi);
|
|
||||||
logger.error(viewedClientWidgetApi);
|
|
||||||
|
|
||||||
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
||||||
|
setIsCallActive(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isCallActive && activeClientWidgetApi && viewedClientWidgetApi) {
|
if (isCallActive && activeClientWidgetApi && viewedClientWidgetApi) {
|
||||||
|
activeClientWidgetApi?.removeAllListeners();
|
||||||
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
||||||
setActiveCallRoomIdState(viewedCallRoomId);
|
|
||||||
setActiveClientWidgetApi(viewedClientWidgetApi, viewedCallRoomId);
|
setActiveClientWidgetApi(viewedClientWidgetApi, viewedCallRoomId);
|
||||||
|
setActiveCallRoomIdState(viewedCallRoomId);
|
||||||
|
setViewedClientWidgetApi(null, null);
|
||||||
setIsPrimaryIframe(!isPrimaryIframe);
|
setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
|
setIsCallActive(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue