mirror of
https://github.com/element-hq/element-call.git
synced 2026-11-22 15:38:40 +00:00
Make callViewModel construction consume a Props obj.
This commit is contained in:
1 parent
89e3ff4c5a
commit
23c8cb05c8
6 files changed
+86
-59
No files matched your search
@@ -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<T>`, an observable with a current value, is
|
||||
the default for anything a view reads.
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
+10
-8
@@ -186,14 +186,16 @@ export const ActiveCall: FC<ActiveCallProps> = (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,
|
||||
|
||||
@@ -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<Record<string, RaisedHandInfo>>;
|
||||
reactionsSubject$: Observable<Record<string, ReactionInfo>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<Record<string, RaisedHandInfo>>,
|
||||
reactionsSubject$: Observable<Record<string, ReactionInfo>>,
|
||||
{
|
||||
rtcParticipation,
|
||||
matrixRoom,
|
||||
mediaDevices,
|
||||
muteStates,
|
||||
encryptionSystem,
|
||||
viewSize$,
|
||||
handsRaisedSubject$,
|
||||
reactionsSubject$,
|
||||
}: CallViewModelProps,
|
||||
options: CallViewModelOptions = {},
|
||||
): CallViewModel {
|
||||
const logger = rootLogger.getChild("[CallViewModel]");
|
||||
|
||||
@@ -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$(
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user