mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-05 15:00:30 +03:00
This seems to manage the hangup state with the status bar button well enough that black screens should never be encountered
This commit is contained in:
parent
9499289fb3
commit
7d26601bfc
1 changed files with 59 additions and 14 deletions
|
|
@ -23,6 +23,7 @@ const WIDGET_MEDIA_STATE_UPDATE_ACTION = 'io.element.device_mute';
|
||||||
const WIDGET_HANGUP_ACTION = 'im.vector.hangup';
|
const WIDGET_HANGUP_ACTION = 'im.vector.hangup';
|
||||||
const WIDGET_ON_SCREEN_ACTION = 'set_always_on_screen';
|
const WIDGET_ON_SCREEN_ACTION = 'set_always_on_screen';
|
||||||
const WIDGET_JOIN_ACTION = 'io.element.join';
|
const WIDGET_JOIN_ACTION = 'io.element.join';
|
||||||
|
const WIDGET_TILE_UPDATE = 'io.element.tile_layout';
|
||||||
|
|
||||||
interface CallContextState {
|
interface CallContextState {
|
||||||
activeCallRoomId: string | null;
|
activeCallRoomId: string | null;
|
||||||
|
|
@ -202,19 +203,35 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
[viewedClientWidgetApi, viewedClientWidgetApiRoomId, setViewedClientWidgetApi]
|
[viewedClientWidgetApi, viewedClientWidgetApiRoomId, setViewedClientWidgetApi]
|
||||||
);
|
);
|
||||||
|
|
||||||
const hangUp = useCallback(() => {
|
const hangUp = useCallback(
|
||||||
logger.debug(`CallContext: Hang up called.`);
|
(nextRoom) => {
|
||||||
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
setIsCallActive(false);
|
||||||
setActiveClientWidgetApi(null, null, null);
|
if (typeof nextRoom !== 'string') {
|
||||||
setViewedCallRoomId(activeCallRoomId);
|
if (viewedCallRoomId === activeCallRoomId) {
|
||||||
|
setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
|
} else {
|
||||||
|
setViewedCallRoomId(activeCallRoomId);
|
||||||
|
}
|
||||||
|
} else if (viewedCallRoomId !== null) {
|
||||||
|
setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
|
setViewedCallRoomId(null);
|
||||||
|
}
|
||||||
|
setActiveClientWidgetApi(null, null, null);
|
||||||
|
setActiveCallRoomId(null);
|
||||||
|
|
||||||
setIsCallActive(false);
|
logger.debug(`CallContext: Hang up called.`);
|
||||||
}, [
|
activeClientWidgetApi?.transport.send(`${WIDGET_HANGUP_ACTION}`, {});
|
||||||
activeCallRoomId,
|
},
|
||||||
activeClientWidgetApi?.transport,
|
[
|
||||||
setActiveClientWidgetApi,
|
activeCallRoomId,
|
||||||
setViewedCallRoomId,
|
activeClientWidgetApi?.transport,
|
||||||
]);
|
isPrimaryIframe,
|
||||||
|
setActiveCallRoomId,
|
||||||
|
setActiveClientWidgetApi,
|
||||||
|
setViewedCallRoomId,
|
||||||
|
viewedCallRoomId,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!activeCallRoomId && !viewedCallRoomId) {
|
if (!activeCallRoomId && !viewedCallRoomId) {
|
||||||
|
|
@ -224,7 +241,23 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
||||||
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
setIsCallActive(false);
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
if (viewedRoomId === activeCallRoomId) {
|
||||||
|
if (viewedCallRoomId !== activeCallRoomId) {
|
||||||
|
setViewedCallRoomId(activeCallRoomId);
|
||||||
|
|
||||||
|
setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
|
} else {
|
||||||
|
setIsPrimaryIframe(!isPrimaryIframe);
|
||||||
|
}
|
||||||
|
setViewedClientWidgetApi(viewedClientWidgetApi, viewedClientWidget, viewedCallRoomId);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// setActiveClientWidgetApi(null, null, null);
|
||||||
|
// setActiveCallRoomId(null);
|
||||||
|
// setIsCallActive(false);
|
||||||
}
|
}
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
`CallContext: Received hangup action from widget in room ${activeCallRoomId}.`,
|
||||||
|
|
@ -262,6 +295,15 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOnTileLayout = (ev: CustomEvent) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
if (isPrimaryIframe) {
|
||||||
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
} else {
|
||||||
|
viewedClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleJoin = (ev: CustomEvent) => {
|
const handleJoin = (ev: CustomEvent) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const setViewedAsActive = () => {
|
const setViewedAsActive = () => {
|
||||||
|
|
@ -271,12 +313,13 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
};
|
};
|
||||||
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
activeClientWidgetApi?.transport.reply(ev.detail, {});
|
||||||
|
|
||||||
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
if (ev.detail.widgetId === activeClientWidgetApi?.widget.id) {
|
||||||
setIsCallActive(true);
|
setIsCallActive(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (activeClientWidgetApi) {
|
if (activeClientWidgetApi) {
|
||||||
if (isCallActive && viewedClientWidgetApi) {
|
if (isCallActive && viewedClientWidgetApi && viewedCallRoomId) {
|
||||||
activeClientWidgetApi?.removeAllListeners();
|
activeClientWidgetApi?.removeAllListeners();
|
||||||
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
activeClientWidgetApi?.transport.send(WIDGET_HANGUP_ACTION, {}).then(() => {
|
||||||
setViewedAsActive();
|
setViewedAsActive();
|
||||||
|
|
@ -294,11 +337,13 @@ export function CallProvider({ children }: CallProviderProps) {
|
||||||
);
|
);
|
||||||
activeClientWidgetApi?.on(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
activeClientWidgetApi?.on(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
||||||
activeClientWidgetApi?.on(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
activeClientWidgetApi?.on(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
||||||
|
viewedClientWidgetApi?.on(`action:${WIDGET_TILE_UPDATE}`, handleOnTileLayout);
|
||||||
activeClientWidgetApi?.on(`action:${WIDGET_ON_SCREEN_ACTION}`, handleOnScreenStateUpdate);
|
activeClientWidgetApi?.on(`action:${WIDGET_ON_SCREEN_ACTION}`, handleOnScreenStateUpdate);
|
||||||
activeClientWidgetApi?.on(`action:${WIDGET_JOIN_ACTION}`, handleJoin);
|
activeClientWidgetApi?.on(`action:${WIDGET_JOIN_ACTION}`, handleJoin);
|
||||||
|
|
||||||
viewedClientWidgetApi?.on(`action:${WIDGET_JOIN_ACTION}`, handleJoin);
|
viewedClientWidgetApi?.on(`action:${WIDGET_JOIN_ACTION}`, handleJoin);
|
||||||
viewedClientWidgetApi?.on(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
viewedClientWidgetApi?.on(`action:${WIDGET_MEDIA_STATE_UPDATE_ACTION}`, handleMediaStateUpdate);
|
||||||
|
viewedClientWidgetApi?.on(`action:${WIDGET_TILE_UPDATE}`, handleOnTileLayout);
|
||||||
viewedClientWidgetApi?.on(`action:${WIDGET_ON_SCREEN_ACTION}`, handleOnScreenStateUpdate);
|
viewedClientWidgetApi?.on(`action:${WIDGET_ON_SCREEN_ACTION}`, handleOnScreenStateUpdate);
|
||||||
viewedClientWidgetApi?.on(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
viewedClientWidgetApi?.on(`action:${WIDGET_HANGUP_ACTION}`, handleHangup);
|
||||||
}, [
|
}, [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue