From a180370c505e9d1399b8a033369d48087180e1a0 Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 27 Jun 2025 14:47:45 +0200 Subject: [PATCH] Read url params for auto leave --- src/UrlParams.ts | 17 ++++++++++++++++- src/room/GroupCallView.tsx | 7 +++++-- src/room/InCallView.tsx | 5 ++++- src/state/CallViewModel.test.ts | 2 +- src/utils/test-viewmodel.ts | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/UrlParams.ts b/src/UrlParams.ts index 94fd3c14..94d7ced9 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -210,6 +210,12 @@ export interface UrlConfiguration { * Whether and what type of notification EC should send, when the user joins the call. */ sendNotificationType?: RTCNotificationType; + /** + * Whether the app should automatically leave the call when there + * is no one left in the call. + * This is one part to make the call matrixRTC session behave like a telephone call. + */ + telephoneAutoLeave: boolean; } // If you need to add a new flag to this interface, prefer a name that describes @@ -277,10 +283,16 @@ class ParamParser { ]; } + /** + * Returns true if the flag exists and is not "false". + */ public getFlagParam(name: string, defaultValue = false): boolean { const param = this.getParam(name); return param === null ? defaultValue : param !== "false"; } + /** + * Returns the value of the flag if it exists, or undefined if it does not. + */ public getFlag(name: string): boolean | undefined { const param = this.getParam(name); return param !== null ? param !== "false" : undefined; @@ -334,6 +346,7 @@ export const getUrlParams = ( skipLobby: true, returnToLobby: false, sendNotificationType: "notification" as RTCNotificationType, + telephoneAutoLeave: false, }; switch (intent) { case UserIntent.StartNewCall: @@ -377,6 +390,7 @@ export const getUrlParams = ( skipLobby: false, returnToLobby: false, sendNotificationType: undefined, + telephoneAutoLeave: false, }; } @@ -428,12 +442,13 @@ export const getUrlParams = ( "ring", "notification", ]), + telephoneAutoLeave: parser.getFlag("telephoneAutoLeave"), }; return { ...properties, ...intentPreset, - ...pickBy(configuration, (v) => v !== undefined), + ...pickBy(configuration, (v?: unknown) => v !== undefined), }; }; diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 4af599bb..76352523 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -166,7 +166,11 @@ export const GroupCallView: FC = ({ const { displayName, avatarUrl } = useProfile(client); const roomName = useRoomName(room); const roomAvatar = useRoomAvatar(room); - const { perParticipantE2EE, returnToLobby } = useUrlParams(); + const { + perParticipantE2EE, + returnToLobby, + password: passwordFromUrl, + } = useUrlParams(); const e2eeSystem = useRoomEncryptionSystem(room.roomId); const [useNewMembershipManager] = useSetting(useNewMembershipManagerSetting); const [useExperimentalToDeviceTransport] = useSetting( @@ -174,7 +178,6 @@ export const GroupCallView: FC = ({ ); // Save the password once we start the groupCallView - const { password: passwordFromUrl } = useUrlParams(); useEffect(() => { if (passwordFromUrl) saveKeyForRoom(room.roomId, passwordFromUrl); }, [passwordFromUrl, room.roomId]); diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index a7d7d4dc..16ed9c86 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -163,6 +163,8 @@ export const ActiveCall: FC = (props) => { }; }, [livekitRoom]); + const { telephoneAutoLeave } = useUrlParams(); + useEffect(() => { if (livekitRoom !== undefined) { const reactionsReader = new ReactionsReader(props.rtcSession); @@ -172,7 +174,7 @@ export const ActiveCall: FC = (props) => { mediaDevices, { encryptionSystem: props.e2eeSystem, - autoLeaveWhenOthersLeft: undefined, + autoLeaveWhenOthersLeft: telephoneAutoLeave, }, connStateObservable$, reactionsReader.raisedHands$, @@ -190,6 +192,7 @@ export const ActiveCall: FC = (props) => { mediaDevices, props.e2eeSystem, connStateObservable$, + telephoneAutoLeave, ]); if (livekitRoom === undefined || vm === null) return null; diff --git a/src/state/CallViewModel.test.ts b/src/state/CallViewModel.test.ts index a3068c32..9d3064dd 100644 --- a/src/state/CallViewModel.test.ts +++ b/src/state/CallViewModel.test.ts @@ -282,7 +282,7 @@ function withCallViewModel( liveKitRoom, mediaDevices, { - kind: E2eeType.PER_PARTICIPANT, + encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, }, connectionState$, raisedHands$, diff --git a/src/utils/test-viewmodel.ts b/src/utils/test-viewmodel.ts index 179c38b1..4781bf3d 100644 --- a/src/utils/test-viewmodel.ts +++ b/src/utils/test-viewmodel.ts @@ -139,7 +139,7 @@ export function getBasicCallViewModelEnvironment( liveKitRoom, mockMediaDevices({}), { - kind: E2eeType.PER_PARTICIPANT, + encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, }, of(ConnectionState.Connected), handRaisedSubject$,