From 8e6eb70e5b60032c33ad03bb085b353cd4cbdcc7 Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 13 Oct 2025 13:52:01 +0200 Subject: [PATCH] refactor: use `EnterRTCSessionOptions` instead of unnamed bools --- src/rtcSessionHelpers.test.ts | 20 +++++++++++++++----- src/rtcSessionHelpers.ts | 34 ++++++++++++++++++++++++++++++---- src/state/CallViewModel.ts | 10 ++++++---- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/rtcSessionHelpers.test.ts b/src/rtcSessionHelpers.test.ts index 258d2f9a..e7f204ec 100644 --- a/src/rtcSessionHelpers.test.ts +++ b/src/rtcSessionHelpers.test.ts @@ -15,6 +15,7 @@ import { mockConfig } from "./utils/test"; import { ElementWidgetActions, widget } from "./widget"; import { ErrorCode } from "./utils/errors.ts"; +const USE_MUTI_SFU = false; const getUrlParams = vi.hoisted(() => vi.fn(() => ({}))); vi.mock("./UrlParams", () => ({ getUrlParams })); @@ -93,7 +94,10 @@ test("It joins the correct Session", async () => { livekit_service_url: "http://my-well-known-service-url.com", type: "livekit", }, - true, + { + encryptMedia: true, + useMultiSfu: USE_MUTI_SFU, + } ); expect(mockedSession.joinRoomSession).toHaveBeenLastCalledWith( @@ -123,12 +127,12 @@ test("It joins the correct Session", async () => { focus_selection: "oldest_membership", type: "livekit", }, - { + expect.objectContaining({ manageMediaKeys: false, useLegacyMemberEvents: false, useNewMembershipManager: true, useExperimentalToDeviceTransport: false, - }, + }), ); }); @@ -197,7 +201,10 @@ test("It fails with configuration error if no live kit url config is set in fall livekit_service_url: "http://my-well-known-service-url.com", type: "livekit", }, - true, + { + encryptMedia: true, + useMultiSfu: USE_MUTI_SFU, + } ), ).rejects.toThrowError( expect.objectContaining({ code: ErrorCode.MISSING_MATRIX_RTC_TRANSPORT }), @@ -240,6 +247,9 @@ test("It should not fail with configuration error if homeserver config has livek livekit_service_url: "http://my-well-known-service-url.com", type: "livekit", }, - true, + { + encryptMedia: true, + useMultiSfu: USE_MUTI_SFU, + } ); }); diff --git a/src/rtcSessionHelpers.ts b/src/rtcSessionHelpers.ts index 3cdd82e7..1bb9f11e 100644 --- a/src/rtcSessionHelpers.ts +++ b/src/rtcSessionHelpers.ts @@ -97,14 +97,40 @@ export async function makeTransport( return transport; } +export interface EnterRTCSessionOptions { + encryptMedia: boolean; + // TODO: remove this flag, the new membership manager is stable enough + useNewMembershipManager?: boolean; + // TODO: remove this flag, to-device transport is stable enough now + useExperimentalToDeviceTransport?: boolean; + /** EXPERIMENTAL: If true, will use the multi-sfu codepath where each member connects to its SFU instead of everyone connecting to an elected on. */ + useMultiSfu?: boolean; +} + +/** + * TODO! document this function properly + * @param rtcSession + * @param transport + * @param options + */ export async function enterRTCSession( rtcSession: MatrixRTCSession, transport: LivekitTransport, - encryptMedia: boolean, - useNewMembershipManager = true, - useExperimentalToDeviceTransport = false, - useMultiSfu = true, + options: EnterRTCSessionOptions = { + encryptMedia: true, + useNewMembershipManager: true, + useExperimentalToDeviceTransport: false, + useMultiSfu: true, + }, ): Promise { + + const { + encryptMedia, + useNewMembershipManager = true, + useExperimentalToDeviceTransport = false, + useMultiSfu = true, + } = options; + PosthogAnalytics.instance.eventCallEnded.cacheStartCall(new Date()); PosthogAnalytics.instance.eventCallStarted.track(rtcSession.room.roomId); diff --git a/src/state/CallViewModel.ts b/src/state/CallViewModel.ts index b2f6a464..82fd7cab 100644 --- a/src/state/CallViewModel.ts +++ b/src/state/CallViewModel.ts @@ -2016,10 +2016,12 @@ export class CallViewModel extends ViewModel { await enterRTCSession( this.matrixRTCSession, localTransport.value, - this.options.encryptionSystem.kind !== E2eeType.NONE, - true, - true, - multiSfu.value$.value, + { + encryptMedia: this.options.encryptionSystem.kind !== E2eeType.NONE, + useExperimentalToDeviceTransport: true, + useNewMembershipManager: true, + useMultiSfu: multiSfu.value$.value + } ); } catch (e) { logger.error("Error entering RTC session", e);