diff --git a/src/UrlParams.test.ts b/src/UrlParams.test.ts index 75bf9bfb8..05c5f7ba1 100644 --- a/src/UrlParams.test.ts +++ b/src/UrlParams.test.ts @@ -123,6 +123,28 @@ describe("UrlParams", () => { }); }); + describe("enableClientWellKnownLookups", () => { + it("is undefined when not set (so the config value applies)", () => { + expect( + computeUrlParams().enableClientWellKnownLookups, + ).toBeUndefined(); + }); + + it("is false when set to false", () => { + expect( + computeUrlParams("?enableClientWellKnownLookups=false") + .enableClientWellKnownLookups, + ).toBe(false); + }); + + it("is true when set to true", () => { + expect( + computeUrlParams("?enableClientWellKnownLookups=true") + .enableClientWellKnownLookups, + ).toBe(true); + }); + }); + describe("returnToLobby", () => { it("is false in SPA mode", () => { expect(computeUrlParams("?returnToLobby=true").returnToLobby).toBe(false); diff --git a/src/UrlParams.ts b/src/UrlParams.ts index 0212c50fe..abde3f38b 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -190,9 +190,10 @@ export interface UrlConfiguration { /** * Whether the app may make client `.well-known` lookups against the user's * homeserver `server_name` (the post-login well-known poll and the legacy - * MatrixRTC foci `.well-known` fallback). Defaults to true. + * MatrixRTC foci `.well-known` fallback). Set by the embedder in widget mode; + * when unset the `enable_client_well_known_lookups` config value applies. */ - enableClientWellKnownLookups: boolean; + enableClientWellKnownLookups?: boolean; /** * Whether the app should use per participant keys for E2EE. @@ -378,7 +379,6 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => { showControls: true, hideScreensharing: false, allowIceFallback: true, - enableClientWellKnownLookups: true, perParticipantE2EE: true, controlledAudioDevices: platform === "desktop" ? false : true, skipLobby: true, @@ -434,7 +434,6 @@ export const computeUrlParams = (search = "", hash = ""): UrlParams => { showControls: true, hideScreensharing: false, allowIceFallback: false, - enableClientWellKnownLookups: true, perParticipantE2EE: false, controlledAudioDevices: false, skipLobby: false, diff --git a/src/config/Config.ts b/src/config/Config.ts index f52b28fde..e40e1dfb5 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -90,6 +90,19 @@ export class Config { return Config.get().default_server_config?.["m.homeserver"].server_name; } + /** + * Whether the app may make client `.well-known` lookups against the + * homeserver `server_name`. The embedded (widget) deployment sets this via + * the `enableClientWellKnownLookups` URL parameter; the standalone (SPA) + * deployment sets it via `enable_client_well_known_lookups` in config.json. + */ + public static clientWellKnownLookupsEnabled(): boolean { + return ( + getUrlParams().enableClientWellKnownLookups ?? + Config.get().enable_client_well_known_lookups + ); + } + public config?: ResolvedConfigOptions; private initPromise?: Promise; } diff --git a/src/config/ConfigOptions.ts b/src/config/ConfigOptions.ts index 3d9fcfb50..1f0effbb6 100644 --- a/src/config/ConfigOptions.ts +++ b/src/config/ConfigOptions.ts @@ -70,6 +70,16 @@ export interface ConfigOptions { }; }; + /** + * Whether the app may make client `.well-known` lookups against the user's + * homeserver `server_name` (the post-login well-known poll and the legacy + * MatrixRTC foci `.well-known` fallback). Set to false to keep the app on the + * homeserver base URL. This is the standalone (SPA) deployment control; + * embedded deployments set it via the `enableClientWellKnownLookups` URL + * parameter instead. Defaults to true. + */ + enable_client_well_known_lookups?: boolean; + // Describes the LiveKit configuration to be used. livekit?: { // The link to the service that returns a livekit url and token to use it. @@ -189,6 +199,7 @@ export interface ResolvedConfigOptions extends ConfigOptions { server_name: string; }; }; + enable_client_well_known_lookups: boolean; sync_disconnect_grace_period_ms: number; ssla: string; matrix_rtc_session: { @@ -211,6 +222,7 @@ export const DEFAULT_CONFIG: ResolvedConfigOptions = { features: { feature_use_device_session_member_events: true, }, + enable_client_well_known_lookups: true, sync_disconnect_grace_period_ms: 10000, ssla: "https://static.element.io/legal/element-software-and-services-license-agreement-uk-1.pdf", matrix_rtc_session: { diff --git a/src/state/CallViewModel/localMember/LocalTransport.ts b/src/state/CallViewModel/localMember/LocalTransport.ts index 91eae4fc8..aacd76b09 100644 --- a/src/state/CallViewModel/localMember/LocalTransport.ts +++ b/src/state/CallViewModel/localMember/LocalTransport.ts @@ -44,7 +44,6 @@ import { } from "../../../livekit/openIDSFU.ts"; import { areLivekitTransportsEqual } from "../remoteMembers/MatrixLivekitMembers.ts"; import { customLivekitUrl } from "../../../settings/settings.ts"; -import { getUrlParams } from "../../../UrlParams.ts"; import { RtcTransportAutoDiscovery } from "./RtcTransportAutoDiscovery.ts"; const logger = rootLogger.getChild("[LocalTransport]"); @@ -148,7 +147,7 @@ export const createLocalTransport$ = ({ const transportDiscovery = new RtcTransportAutoDiscovery({ client: client, resolvedConfig: Config.get(), - enableClientWellKnownLookups: getUrlParams().enableClientWellKnownLookups, + enableClientWellKnownLookups: Config.clientWellKnownLookupsEnabled(), wellKnownFetcher: AutoDiscovery.getRawClientConfig.bind(AutoDiscovery), logger: logger, }); diff --git a/src/utils/matrix.ts b/src/utils/matrix.ts index 2ea7aea76..4cac5cba3 100644 --- a/src/utils/matrix.ts +++ b/src/utils/matrix.ts @@ -112,7 +112,7 @@ export async function initClient( // the values around, but we initialise the matrix client in // many different places so we'd have to pass it into all of // them. - const { e2eEnabled, enableClientWellKnownLookups } = getUrlParams(); + const { e2eEnabled } = getUrlParams(); if (!e2eEnabled) { logger.info("Disabling E2E: group call signalling will NOT be encrypted."); } @@ -169,7 +169,9 @@ export async function initClient( // Leaving `clientWellKnownPollPeriod` unset stops the SDK polling the // homeserver's `server_name` `.well-known` after login. await client.startClient({ - clientWellKnownPollPeriod: enableClientWellKnownLookups ? 60 * 10 : undefined, + clientWellKnownPollPeriod: Config.clientWellKnownLookupsEnabled() + ? 60 * 10 + : undefined, }); await syncPromise; diff --git a/src/widget.ts b/src/widget.ts index 6c4c80903..9d62b4b20 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -82,7 +82,6 @@ export const initializeWidget = ( baseUrl, e2eEnabled, allowIceFallback, - enableClientWellKnownLookups, } = getUrlParams(); if (!roomId) throw new Error("Room ID must be supplied"); @@ -199,7 +198,7 @@ export const initializeWidget = ( // Leaving `clientWellKnownPollPeriod` unset stops the SDK polling the // homeserver's `server_name` `.well-known` after login. await client.startClient({ - clientWellKnownPollPeriod: enableClientWellKnownLookups + clientWellKnownPollPeriod: Config.clientWellKnownLookupsEnabled() ? 60 * 10 : undefined, });