Stop reading URL parameters from inside the call path

The view models reached for getUrlParams() — and so window.location —
from deep inside the call path: CallViewModel, MediaDevices, Publisher,
LocalMember and the footer view model. An embedded Element Call has no URL
of its own, so these values have to arrive as arguments instead.

Add the relevant options to CallViewModelOptions, to the MediaDevices and
Publisher constructors, to createLocalMembership$ and enterRTCSession, and
to createCallFooterViewModel. The remaining React consumers read the
context added in the previous commit. AppViewModel now takes its audio
output options too, moving that URL read out to main.tsx, where the app
shell can act as the adapter.

The new CallViewModelOptions fields are optional, defaulting to what the
URL parameters resolve to outside widget mode; the MediaDevices and
Publisher arguments are required, so that every construction site has to
be explicit.

useTheme.test.ts mocked the UrlParams module with a factory, so it needed
updating to mock the hook rather than getUrlParams.

No functional change.
This commit is contained in:
Valere
2026-09-02 10:31:48 +02:00
parent bc6015eff2
commit 6e44332fd1
20 changed files with 176 additions and 65 deletions
+3 -1
View File
@@ -29,7 +29,9 @@ const reactionData = {
reactions$: new BehaviorSubject({}),
};
const mediaDevices = new MediaDevices(globalScope);
const mediaDevices = new MediaDevices(globalScope, {
controlledAudioDevices: false,
});
/**
* A wrapper component that is used for:
@@ -15,6 +15,7 @@ import type { Alignment, Layout } from "../state/layout-types";
import type { SpotlightTileViewModel } from "../state/TileViewModel";
import type { DeviceLabel } from "../state/MediaDevices";
import { createCallFooterViewModel } from "./CallFooterViewModel";
import { HeaderStyle } from "../UrlParams";
const platformMock = vi.hoisted(() => vi.fn(() => "desktop"));
vi.mock("../Platform", () => ({
@@ -105,6 +106,7 @@ describe("createCallFooterViewModel", () => {
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
expect(vm.audioOptions$.value).toEqual([]);
@@ -126,6 +128,7 @@ describe("createCallFooterViewModel", () => {
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
expect(vm.audioOptions$?.value).toEqual([
+5 -2
View File
@@ -19,7 +19,7 @@ import { type Behavior, constant } from "../state/Behavior";
import type { ObservableScope } from "../state/ObservableScope";
import { type MuteStates } from "../state/MuteStates";
import { createStaticViewModel, type ViewModel } from "../state/ViewModel";
import { getUrlParams, HeaderStyle } from "../UrlParams";
import { HeaderStyle } from "../UrlParams";
import { platform } from "../Platform";
import { type FooterSnapshot } from "./CallFooter";
@@ -138,6 +138,8 @@ function buildDeviceBehaviors(
* @param mediaDevices - Available and selected input devices.
* @param reactionIdentifier - The local user's reaction identifier string, or
* undefined when reactions are not supported (hides the reaction button).
* @param options - `showControls`: whether the call controls should be shown.
* `header`: the style of header, which decides whether to show the logo.
*/
export function createCallFooterViewModel(
scope: ObservableScope,
@@ -145,8 +147,9 @@ export function createCallFooterViewModel(
muteStates: MuteStates,
mediaDevices: MediaDevices,
reactionIdentifier: string | undefined,
options: { showControls: boolean; header: HeaderStyle },
): ViewModel<FooterSnapshot> {
const { showControls, header: headerStyle } = getUrlParams();
const { showControls, header: headerStyle } = options;
const showLogo = headerStyle === HeaderStyle.Standard;
const isPip$ = scope.behavior(
@@ -14,7 +14,9 @@ import { MediaDevicesContext } from "../MediaDevicesContext";
import { MediaDevices } from "../state/MediaDevices";
import { globalScope } from "../state/ObservableScope";
const mediaDevices = new MediaDevices(globalScope);
const mediaDevices = new MediaDevices(globalScope, {
controlledAudioDevices: false,
});
const meta = {
component: MediaMuteAndSwitchButton,