From 23c8cb05c82c85dbd88fb31f564302e7ac3fcde6 Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Wed, 18 Nov 2026 17:17:14 +0100 Subject: [PATCH] Make callViewModel construction consume a Props obj. --- docs/agents/architecture.md | 12 ++-- sdk-target-based-on-call-view-model/main.ts | 20 ++++--- src/room/InCallView.tsx | 18 +++--- src/state/CallViewModel/CallViewModel.ts | 59 ++++++++++++------- .../CallViewModel/CallViewModelTestUtils.ts | 18 +++--- src/utils/test-viewmodel.ts | 18 +++--- 6 files changed, 86 insertions(+), 59 deletions(-) diff --git a/docs/agents/architecture.md b/docs/agents/architecture.md index a5a53312c..b3b37d1c1 100644 --- a/docs/agents/architecture.md +++ b/docs/agents/architecture.md @@ -10,11 +10,13 @@ - Owning a resource: a class taking the scope in its constructor — `MediaDevices`, `MuteStates`, `TileStore`, `Publisher`, `Connection`. Both styles are current; don't convert one to the other in passing. -- A factory's positional parameters are what the thing is made of: required, no - sensible default. Its trailing `options` bag is how the host wants it to - behave: every field optional, each defaulting to standalone behaviour, so `{}` - works. A value with no default is never an option; a test seam is never an - option either — mock the dependency it comes from. See `createCallViewModel$`. +- A factory's required parameters are what the thing is made of: no sensible + default. Several of them go in a props interface, so each can carry a doc + comment. Its trailing `options` bag is how the host wants it to behave: every + field optional, each defaulting to standalone behaviour, so `{}` works. A + value with no default is never an option; a test seam is never an option + either — mock the dependency it comes from. See `createCallViewModel$`, with + `CallViewModelProps` and `CallViewModelOptions`. - `foo$` is an observable. `Behavior`, an observable with a current value, is the default for anything a view reads. diff --git a/sdk-target-based-on-call-view-model/main.ts b/sdk-target-based-on-call-view-model/main.ts index dd4407748..1d780a9f5 100644 --- a/sdk-target-based-on-call-view-model/main.ts +++ b/sdk-target-based-on-call-view-model/main.ts @@ -128,15 +128,17 @@ export async function createMatrixRTCSdk( }); vm = createCallViewModel$( scope, - participation, - room, - mediaDevices, - muteStates, - encryptionSystem, - // The bundle owns its page, so the body is the space it has - scope.behavior(observeElementSize$(document.body)), - of({}), - of({}), + { + rtcParticipation: participation, + matrixRoom: room, + mediaDevices, + muteStates, + encryptionSystem, + // The bundle owns its page, so the body is the space it has + viewSize$: scope.behavior(observeElementSize$(document.body)), + handsRaisedSubject$: of({}), + reactionsSubject$: of({}), + }, { ...callViewModelOptionsFromParams(urlParams), capture, diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 36ba61022..32f70b69c 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -186,14 +186,16 @@ export const ActiveCall: FC = (props) => { const vm = createCallViewModel$( scope, - rtcParticipation, - props.matrixRoom, - mediaDevices, - props.muteStates, - props.e2eeSystem, - scope.behavior(observeElementSize$(rootElement)), - reactionsReader.raisedHands$, - reactionsReader.reactions$, + { + rtcParticipation, + matrixRoom: props.matrixRoom, + mediaDevices, + muteStates: props.muteStates, + encryptionSystem: props.e2eeSystem, + viewSize$: scope.behavior(observeElementSize$(rootElement)), + handsRaisedSubject$: reactionsReader.raisedHands$, + reactionsSubject$: reactionsReader.reactions$, + }, { ...callViewModelOptionsFromParams(urlParams), capture, diff --git a/src/state/CallViewModel/CallViewModel.ts b/src/state/CallViewModel/CallViewModel.ts index 86fb3d030..9d6405e51 100644 --- a/src/state/CallViewModel/CallViewModel.ts +++ b/src/state/CallViewModel/CallViewModel.ts @@ -185,13 +185,37 @@ export function initialPublishRequests( return requests; } +/** + * What the call is made of: the room, the participation, the devices, the + * things with no sensible default. How the host wants it to behave is in + * {@link CallViewModelOptions} instead. + */ +export interface CallViewModelProps { + rtcParticipation: RTCParticipation; + /** A call is permanently tied to a single Matrix room. */ + matrixRoom: MatrixRoom; + mediaDevices: MediaDevices; + muteStates: MuteStates; + encryptionSystem: EncryptionSystem; + /** + * The size of the space the call is drawn in: the page when Element Call + * owns it, or the container a host mounted it in when it is a component. + * The layout — whether the call is shown full size, flat, narrow or as a + * picture-in-picture — follows this rather than the size of the window, so + * that a component shrunk by its host adapts even though the window has not + * changed. + */ + viewSize$: Behavior<{ width: number; height: number }>; + handsRaisedSubject$: Observable>; + reactionsSubject$: Observable>; +} + /** * How the host wants the call to behave. Every field is optional and defaults * to what standalone Element Call does, so `{}` is a working standalone call. - * What the call is made of — the room, the participation, the devices, the - * things with no sensible default — is a positional parameter of - * {@link createCallViewModel$} instead. A test that wants to replace behaviour - * mocks the dependency it comes from rather than adding an option here. + * What the call is made of is in {@link CallViewModelProps} instead. A test + * that wants to replace behaviour mocks the dependency it comes from rather + * than adding an option here. */ export interface CallViewModelOptions { /** @@ -465,23 +489,16 @@ export interface CallViewModel { */ export function createCallViewModel$( scope: ObservableScope, - rtcParticipation: RTCParticipation, - // A call is permanently tied to a single Matrix room - matrixRoom: MatrixRoom, - mediaDevices: MediaDevices, - muteStates: MuteStates, - encryptionSystem: EncryptionSystem, - /** - * The size of the space the call is drawn in: the page when Element Call - * owns it, or the container a host mounted it in when it is a component. - * The layout — whether the call is shown full size, flat, narrow or as a - * picture-in-picture — follows this rather than the size of the window, so - * that a component shrunk by its host adapts even though the window has not - * changed. - */ - viewSize$: Behavior<{ width: number; height: number }>, - handsRaisedSubject$: Observable>, - reactionsSubject$: Observable>, + { + rtcParticipation, + matrixRoom, + mediaDevices, + muteStates, + encryptionSystem, + viewSize$, + handsRaisedSubject$, + reactionsSubject$, + }: CallViewModelProps, options: CallViewModelOptions = {}, ): CallViewModel { const logger = rootLogger.getChild("[CallViewModel]"); diff --git a/src/state/CallViewModel/CallViewModelTestUtils.ts b/src/state/CallViewModel/CallViewModelTestUtils.ts index b490ae32c..6a3cdf77a 100644 --- a/src/state/CallViewModel/CallViewModelTestUtils.ts +++ b/src/state/CallViewModel/CallViewModelTestUtils.ts @@ -261,14 +261,16 @@ export function withCallViewModel(mode: MatrixRTCMode) { const vm = createCallViewModel$( scope, - rtcParticipation, - room, - mediaDevices, - muteStates, - { kind: E2eeType.PER_PARTICIPANT }, - viewSize$, - raisedHands$, - reactions$, + { + rtcParticipation, + matrixRoom: room, + mediaDevices, + muteStates, + encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, + viewSize$, + handsRaisedSubject$: raisedHands$, + reactionsSubject$: reactions$, + }, { autoLeaveWhenOthersLeft: false, sentCallNotification$: createSentCallNotification$( diff --git a/src/utils/test-viewmodel.ts b/src/utils/test-viewmodel.ts index d3f3e7627..5ac530321 100644 --- a/src/utils/test-viewmodel.ts +++ b/src/utils/test-viewmodel.ts @@ -196,14 +196,16 @@ export function getBasicCallViewModelEnvironment( }); const vm = createCallViewModel$( scope, - rtcParticipation, - matrixRoom, - mediaDevices, - muteStates, - { kind: E2eeType.PER_PARTICIPANT }, - constant({ width: 1000, height: 800 }), - handRaisedSubject$, - reactionsSubject$, + { + rtcParticipation, + matrixRoom, + mediaDevices, + muteStates, + encryptionSystem: { kind: E2eeType.PER_PARTICIPANT }, + viewSize$: constant({ width: 1000, height: 800 }), + handsRaisedSubject$: handRaisedSubject$, + reactionsSubject$, + }, { sentCallNotification$: createSentCallNotification$( scope,