Compare commits

...
Author SHA1 Message Date
Timo K. aee75d7d72 Introduce Backend concept (just renames for now. no new strucutre) 2026-11-20 04:42:54 +01:00
Timo K. 5235fd0e65 make EC component rtcSession independent, more own js-sdk wrapped
methods
Everything related to the session is now burried inside the SDK.
2026-11-20 03:11:26 +01:00
Timo K. 0f5969677f remove the rtcSession from everything below the CallView!!!!
This is a big step in the js-sdk independence of EC.
It concludes a clear position where we can start building the
matrixBackend.
2026-11-20 02:23:22 +01:00
Timo K. d492b9d93a Make the reactions logic independent of the rtcSession 2026-11-20 01:51:54 +01:00
Timo K. 800e8d2a39 SDK api updated (rtcMode slot->join, RTCMember.eventId)
Two things were added
 - The rtc mode is now passed on join and not part of the slot (it is a
   participation prop only, uninteresting for non joined slots, its per
   participant anyhow)
 - RTCMember.matrixEventId$ includes the event id which we need in the
   rtc sdk as some apps (e.g. call) might need it.
2026-11-20 01:44:40 +01:00
Timo K. 2a8836e44a never use rtcSession.room (Relation classes refactor)
make sure everything is passed through dedicated room / client props.
2026-11-20 01:01:28 +01:00
Timo K. f6b5dd0b7e Use implementations for rtc related methods of our own js-sdk
getRTCTransports
getOpenIdToken
getLivekitToken
delegateDelayedLeave
2026-11-20 01:00:33 +01:00
Timo K. 3176992d5d Make the client Picks transparent up to the component 2026-11-20 00:43:37 +01:00
Timo K. f934cd158f Make the room Picks transparent up to the component. 2026-11-20 00:11:06 +01:00
Timo K. ab7d2d3893 Allocate a new js-sdk matrixRTCSession for the embedded component (no
more peer dep)
2026-11-19 23:46:59 +01:00
Timo K. 0e1badf559 api iteration: only pass the participation the slot data that makes
sense
 - dont pass the participation$ itself
 - dont pass the join fn.
2026-11-19 23:45:53 +01:00
Timo K. c835409cd2 createRTCSlot takes the MatrixRTC session via fn param 2026-11-19 23:43:35 +01:00
Timo K. 79c9900568 Mark everything below the CallView with Pick<> 2026-11-19 22:36:51 +01:00
Timo K. f2207ce21f Make callViewModel declare what it really needs from room (using
`Pick<>`
2026-11-19 21:58:14 +01:00
Robin ef1f69e085 Merge pull request #4342 from element-hq/valere/cleanup_sound_licence_listing
Sound listing clean-up
2026-11-19 14:42:58 -05:00
Robin 86ad9bcb28 Merge pull request #4475 from element-hq/robin/clean-release-notes
Hide Docker and Actions updates from release notes
2026-11-19 09:42:41 -05:00
Johannes Marbach 7cd9ed8022 Merge pull request #4477 from element-hq/johannes/stable-rtc-member
Request capability to receive m.rtc.member events
2026-11-19 15:34:10 +01:00
Johannes Marbach 29b80b62c9 Request capability to receive m.rtc.member events 2026-11-19 08:49:25 +01:00
Robin df1156b385 Hide Docker and Actions updates from release notes
To make the release notes more scannable.
2026-11-18 14:06:18 -05:00
Timo 7cf6cb4fee Merge pull request #4437 from element-hq/toger5/background-effects-brush-up
Review from the background effects
2026-11-18 17:36:59 +01:00
Timo K. 23c8cb05c8 Make callViewModel construction consume a Props obj. 2026-11-18 17:17:14 +01:00
Timo K. 89e3ff4c5a reveiw: dediated dismiss 2026-11-18 16:52:05 +01:00
Timo K. 586154772e Update track mute comment 2026-11-18 15:23:29 +01:00
Timo K. 20a174c0b4 review: windowSize$ -> viewSize$ 2026-11-18 15:11:52 +01:00
Timo K. 02eb134e40 setEffect -> ClearEffect 2026-11-18 15:01:57 +01:00
Timo K. 3acf5d9a28 review: toggle comments confusing 2026-11-18 14:58:03 +01:00
Timo K. ac461840a3 comment changes to MediaMenuViewModel 2026-11-18 14:55:28 +01:00
renovate[bot]andJohannes Marbach 2e3f40e08c Update ghcr.io/element-hq/element-web:develop Docker digest to 62e9865 (#4469)
* Update ghcr.io/element-hq/element-web:develop Docker digest to f85350f

* Improve failure analysis

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Johannes Marbach <n0-0ne+github@mailbox.org>
2026-11-18 08:28:04 +00:00
Timo K. 438d14d1a1 fix facing mode
Use default fallback instead of inversed check.
2026-11-17 21:11:34 +01:00
Timo d04bfdc624 Merge pull request #4471 from element-hq/toger5/bump-dompurify
Raise dompurify override to 3.4.17
2026-11-17 15:01:22 +01:00
Timo b1f8fcd604 Merge pull request #4470 from element-hq/toger5/bump-oxfmt
Update oxfmt to 0.79.0
2026-11-17 14:43:00 +01:00
Timo 001a015a3f Merge pull request #4467 from element-hq/johannes/stable-get-token
Switch to non-unstable method for /rtc/get_token
2026-11-17 14:32:01 +01:00
Timo K. cee9e02617 oxfmt fix 2026-11-17 14:21:58 +01:00
Timo K.andClaude Opus 5.5 b3bbdc79f5 Raise dompurify override to 3.4.17
posthog-js pulls in dompurify and the lockfile still resolved 3.4.12,
which is affected by GHSA-cg2g-xh64-v4q7, GHSA-mrv2-3pqr-j5jr and
GHSA-c6gr-qvv4-5v3f. Raise the override floor to the fixed release so a
lockfile refresh cannot fall back below it. Resolves to 3.4.18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:19:04 +01:00
Timo K.andClaude Opus 5.5 e91d1387b7 Update oxfmt to 0.79.0
oxfmt 0.66.0 pins tinypool to 2.1.0, which has known vulnerabilities.
0.79.0 pins tinypool 2.2.0. Reformat the two files whose output
changed with the new version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 14:03:00 +01:00
Timo K. 34465d7230 Merge branch 'main' into johannes/stable-get-token 2026-11-17 13:29:09 +01:00
Johannes Marbach 512e885bf2 Merge pull request #4449 from element-hq/johannes/claude-failure-analysis
Add workflow for letting Claude analyse CI failures
2026-11-17 12:54:10 +01:00
Johannes Marbach 629031038f Merge pull request #4466 from element-hq/johannes/stable-delegate-delayed
Use non-unstable function for delegating delayed leaves
2026-11-16 18:06:06 +01:00
Johannes Marbach 3879cd65b5 Merge pull request #4357 from element-hq/johannes/sticky-fixes
Sticky event handling fixes
2026-11-16 13:33:36 +01:00
Johannes Marbach 74500f37ea Switch to non-unstable method for /rtc/get_token 2026-11-16 13:31:24 +01:00
Johannes Marbach c9616efc5b Use non-unstable function for delegating delayed leaves 2026-11-16 12:23:22 +01:00
Johannes Marbach b9546b80f5 Start with current sticky events 2026-11-16 10:47:53 +01:00
Johannes Marbach ad316bbe9a Merge pull request #4464 from element-hq/renovate/livekit-components
Update dependency @livekit/components-core to v0.12.16
2026-11-16 08:54:58 +01:00
renovate[bot] 63f31e711c Update ghcr.io/element-hq/element-web:develop Docker digest to bfb9108 (#4463)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-16 03:47:10 +00:00
renovate[bot] 3e864c537a Update dependency @livekit/components-core to v0.12.16 2026-11-16 03:40:16 +00:00
renovate[bot] 3ce3d0e266 Update ghcr.io/element-hq/element-web:develop Docker digest to f7b5906 (#4462)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-15 01:53:38 +00:00
renovate[bot] 6f328d7304 Update ghcr.io/element-hq/element-web:develop Docker digest to 00133e9 (#4460)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-14 02:17:39 +00:00
Johannes Marbach e5d74102e1 Merge branch 'main' into johannes/sticky-fixes 2026-11-13 15:51:31 +01:00
Johannes Marbach 413b795459 Merge pull request #4452 from element-hq/johannes/agents-fixes
Compact AGENTS.md and split hand-off out into a skill
2026-11-13 14:22:39 +01:00
renovate[bot] e9c1e25542 Update ghcr.io/element-hq/element-web:develop Docker digest to 2901117 (#4453)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-13 09:06:50 +00:00
Timo K. 60985885d3 Seperate Options and props for CallViewModel
- props are dependencies (otherwise no call can work)
 - options are optional
2026-11-12 18:27:37 +01:00
Timo f88d8d5830 Merge pull request #4456 from element-hq/toger5/getRTCTrasnport_and_getDomain
Use non deprecated non unstable names for getRTCTransports.
2026-11-12 16:12:02 +01:00
Timo K. 6c66f9a3e7 use non deprecated non unstable names for getRTCTransports.
Also remove getDomain where possible
2026-11-12 16:01:11 +01:00
Johannes Marbach 99f48ff987 Merge pull request #4454 from element-hq/johannes/lk-jwt-service-0.10.0
Bump lk-jwt-service to 0.10.0
2026-11-12 13:01:09 +01:00
Timo 6846c8dd3e Merge pull request #4431 from element-hq/toger5/component-no-store-worker
Keep the store worker out of the component package
2026-11-12 12:27:47 +01:00
Johannes Marbach 28ee707ace Bump lk-jwt-service to 0.10.0 2026-11-12 08:29:26 +01:00
Timo K.andClaude Fable 5.1 3100c1c410 Cover the standalone client's initialisation and session restore
Neither had a test before the move, so the moved lines showed up as
uncovered. The client initialisation is tested through a fake client
and mocked stores: which store it syncs into with and without
IndexedDB, with and without the worker, the fallback to memory when
the IndexedDB store cannot start, clearing the stores only when not
restoring, carrying on without crypto, and counting as ready only
after a sync from the network rather than the one restored from the
store. The session restore is tested for no stored session, a
restored one, one the homeserver no longer knows, and any other
failure.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 19:24:21 +01:00
Timo K.andClaude Fable 5.1 fc1e91f54c Keep the store worker out of the component package
The package carried the standalone app's IndexedDB store worker: 11 MB
with a copy of the Matrix SDK and its crypto wasm, referenced by an
absolute path no host could serve, and never used by the component,
which takes the host's client. The bundler emits the worker file as
soon as it loads the `?worker` import, used or not, and the import sat
in the Matrix utilities the component reaches for the room URLs.

The client initialisation moves into a module of its own, with the
worker import, which only the standalone login, registration and
session restore paths import. ClientProvider takes the session loader
through a `loadClient` prop instead of importing it itself, since even
a dynamic import keeps a module in the package: the standalone app
passes a lazy `initSPA` from App.tsx, the component passes nothing,
and given neither a client nor a loader no one is signed in.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-11 19:24:21 +01:00
Johannes Marbach 1ea5f0821d Shorten prompt 2026-11-11 16:40:33 +01:00
Johannes Marbach d5f72f464d Compact AGENTS.md and split hand-off out into a skill 2026-11-11 16:33:46 +01:00
Johannes Marbach 1227b0aa18 Add workflow for letting Claude analyse CI failures 2026-11-11 15:56:36 +01:00
Timo K. 889828763c Review from the background effects 2026-11-07 16:18:26 +01:00
Johannes Marbach 783bd946e8 Add tests 2026-10-26 11:58:54 +01:00
Johannes Marbach 9c64316b42 Sticky event handling fixes 2026-10-16 14:47:10 +02:00
Valere 25c4f14d8f Sound listing clean-up 2026-10-09 16:06:19 +02:00
129 changed files with 4857 additions and 2715 deletions
+35
View File
@@ -0,0 +1,35 @@
---
name: handoff
description: Implement the first cut of a task and stop for a direction check before the quality pass.
argument-hint: <the task>
disable-model-invocation: true
---
Task: $ARGUMENTS
Stop after the first implementation and hand it back before the quality pass.
## Before the hand-off
- Run the narrowest check that rules out an obviously broken hand-off: the test
file for the touched code, `tsc` on its own, a single story. Not the full
`pnpm lint`, not the whole suite.
- If a wider check is needed before feedback can be useful, keep it to the touched
code and say why it was needed.
- Leave wider refactors, extra tests and documentation polish out. They are
follow-up work, not part of the first hand-off.
## The hand-off
Stop and ask whether the direction is right. The message says:
- what was built and where, in a few lines,
- which check ran and what it returned, verbatim if it failed,
- what was left out on purpose,
- the decisions that could have gone another way.
Do not continue past this point on your own.
## After the user confirms
The skill ends here. Continue with the quality pass as usual.
+3
View File
@@ -105,6 +105,9 @@
- name: "Claude-Review"
description: "Request code review from Claude"
color: "e57157"
- name: "Claude-Analyse-Failures"
description: "Request an analysis of failing tests from Claude"
color: "4ADEC0"
- name: "customer-retainer"
color: "F44A5F"
- name: "dependencies"
@@ -0,0 +1,106 @@
name: Claude failure analysis
on:
pull_request:
types: [labeled]
permissions:
# The action exchanges the GitHub OIDC token for a short-lived Anthropic
# access token. GitHub API access goes through CLAUDE_GH_TOKEN instead.
id-token: write
actions: read
jobs:
analysis:
name: Analyse failures
# Only run on labelling and skip forks.
if: github.event.label.name == 'Claude-Analyse-Failures' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
# The turn limit below is generous, so bound the job by time instead.
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
# We may need commit history.
fetch-depth: 0
persist-credentials: false
# Pre-download job logs and artifacts of failed runs so that Claude doesn't spend cycles on it.
- name: Download logs and artifacts of failed workflow runs
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -eu
dir=agent-workspace/ci-artifacts
mkdir -p "$dir"
for run in $(gh run list --commit "$HEAD_SHA" --status failure --json databaseId --jq '.[].databaseId'); do
mkdir -p "$dir/$run"
# Fetch run summary, logs of failed jobs and artifacts.
gh run view "$run" > "$dir/$run/run.txt"
gh run view "$run" --log-failed > "$dir/$run/failed-jobs.log"
gh run download "$run" --dir "$dir/$run" || echo "No artifacts for run $run"
done
# Unpack any (nested) zip archives.
while zips=$(find "$dir" -name '*.zip') && [ -n "$zips" ]; do
echo "$zips" | while IFS= read -r zip; do
unzip -oq "$zip" -d "${zip%.zip}" && rm "$zip"
done
done
find "$dir" -maxdepth 3 -type d
- name: Analyse
uses: anthropics/claude-code-action@6fed3ca145920b639991cb756090506e1bcaf515 # v1.0.245
with:
anthropic_federation_rule_id: fdrl_01XQmWo4nka1ZTqZdsdeScyr
anthropic_organization_id: dfbc9a23-d636-4653-8970-035204ef60fa
anthropic_service_account_id: svac_018Ay5qaA7ZW8X7XsbdekqUM
anthropic_workspace_id: wrkspc_01Aw8LHjBS6fZysu9yqzYifW
# The token used here must grant read access to code, issues, and metadata as well as
# read and write access to pull requests.
github_token: ${{ secrets.CLAUDE_GH_TOKEN }}
use_sticky_comment: true
track_progress: true
additional_permissions: |
actions: read
prompt: |
One or more test jobs failed on this pull request. Find out why and
what would need to change to make them pass.
The details, logs and artifacts of every failed workflow run have
already been downloaded into `agent-workspace/ci-artifacts/<run id>/`:
- `run.txt`: Textual run summary with jobs, steps and failure annotations
- `failed-jobs.log`: Logs of the failed jobs
- Any other file: Unpacked run artifacts.
If `agent-workspace/ci-artifacts` is empty, no workflow failed. Say so
and stop in this case.
Read the commits on this branch with `git log` and `git diff` against
the base branch of the PR.
For each failed workflow run , find out what failed and search the
root cause(s). Stop investigating once direct evidence confirms a root
cause. Devise at least one possible resolution for each root cause.
Report your findings as PR comment. Start your message with "# Automated
CI failure analysis". Then add one section per root cause with:
- The affected workflows
- Evidence from the logs
- The fix proposal(s)
Be brief and concise in all your communication. Do not mention things
workflows that did not fail.
Use Markdown links for anything that can be navigated to on GitHub
such as files, commits, issues, pull requests, workflow runs and
jobs.
# Set a generous turn limit. It's bounded by timeout-minutes above.
claude_args: |
--model claude-fable-5-1
--allowedTools "mcp__github_ci__get_ci_status,mcp__github_ci__get_workflow_run_details,mcp__github_ci__download_job_log,mcp__github__list_commits,mcp__github__get_commit,mcp__github__get_file_contents,mcp__github__search_code,mcp__github__list_workflow_runs,mcp__github__get_workflow_run,mcp__github__list_pull_requests,mcp__github__get_pull_request,mcp__github__get_pull_request_files,mcp__github__list_tags,Bash(git log:*),Bash(git diff:*),Bash(git show:*),Bash(gh run list:*),Bash(gh run view:*),Bash(gh run download:*),Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh api:*),Bash(docker:*)"
--max-turns 150
@@ -1,4 +1,4 @@
name: Claude
name: Claude review
on:
pull_request:
types: [labeled]
+4
View File
@@ -44,3 +44,7 @@ storybook-static
# Nested checkout made by scripts/layered.sh
/matrix-js-sdk/
# Claude
/.claude/*
!/.claude/skills/
+25 -4
View File
@@ -16,19 +16,35 @@ host's page. It is the MatrixRTC reference implementation.
`@media`, global `i18next` or the `widget` global — take it from a provider.
- The change works standalone, as a widget and as a component. Say what you checked.
- Every gate below is green before you push.
- Hand off after the first implementation, before the quality pass. Then commit on
the user's word where the setup allows it, or hand them the message.
## Read before you
| … | … |
| -------------------------------- | ---------------------------------------------------------- |
| start a task of any size | [docs/agents/workflow.md](docs/agents/workflow.md) |
| touch call logic or a view model | [docs/agents/architecture.md](docs/agents/architecture.md) |
| write any code | [docs/agents/code-style.md](docs/agents/code-style.md) |
| write a test, story or e2e spec | [docs/agents/testing.md](docs/agents/testing.md) |
| open a PR | [CONTRIBUTING.md](CONTRIBUTING.md) |
| implement from a feature spec | [FEATURES_SPEC/AGENTS.md](FEATURES_SPEC/AGENTS.md) |
## Scratch files live in `agent-workspace/`
Git-ignored. One kebab-case subfolder per task, matching the branch topic:
`agent-workspace/<slug>/`.
| File | Purpose |
| --------------------------- | -------------------------------------------------------------------------------- |
| `plan.md` | The concrete approach — files, symbols, edit order — once direction is confirmed |
| `commit-msg.txt` | `git commit -F agent-workspace/<slug>/commit-msg.txt` |
| `pr-body.md` | `gh pr create --body-file agent-workspace/<slug>/pr-body.md` |
| `implementation-summary.md` | What was built, decisions, trade-offs |
| `NN-prompt.md` | Raw prompt text, numbered, when worth keeping |
- Nothing here is durable. The folder is ignored, so anything worth keeping is
promoted into the PR body or a doc before the task ends.
- Never write scratch files to the repo root. Stray `load_test_summary.md` and
`config.json_` files are what this folder prevents.
- Start `pr-body.md` from `.github/PULL_REQUEST_TEMPLATE.md` and fill every
section.
## Gates
@@ -42,6 +58,11 @@ pnpm i18n:check
`knip` fails on dead code; a file deliberately inert ahead of its consumer goes in
`knip.ts` `ignoreFiles` with a reason.
Ready means every gate is green and the change is covered at the layers
[testing.md](docs/agents/testing.md) asks for. Read the diff against
[code-style.md](docs/agents/code-style.md) first. Re-run the whole checklist after
any fix.
## A good PR
- One slice, under ~400 changed lines, green on its own, linked to its issue.
+93
View File
@@ -0,0 +1,93 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { afterEach, beforeEach, expect, test, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { type MatrixClient, type Room } from "matrix-js-sdk";
import { mockEmitter, mockMatrixRoom } from "../src/utils/test";
import { ElementCall } from "./index";
// The call itself is out of scope: what matters is what it is handed
const callView = vi.hoisted(() => vi.fn());
vi.mock("../src/room/CallView", () => ({
CallView: (props: object): string => {
callView(props);
return "call";
},
}));
// Media devices need a browser jsdom does not have
vi.mock("../src/state/AppViewModel", () => ({
AppViewModel: class {
public mediaDevices = {};
public backgroundEffects = {};
},
}));
const roomId = "!room:example.org";
let room: Room;
beforeEach(() => {
// What the call's backend takes from the room
room = mockMatrixRoom({
roomId,
getMembersWithMembership: vi.fn(),
getLiveTimeline: vi.fn(),
getVersion: vi.fn(),
hasMembershipState: vi.fn(),
_unstable_getStickyEvents: vi.fn(),
getMxcAvatarUrl: vi.fn(),
getJoinRule: vi.fn(),
});
});
afterEach(() => {
callView.mockClear();
});
test("calls in the room, leaving the session to the call", async () => {
render(<ElementCall client={mockClient()} roomId={roomId} />);
await screen.findByText("call");
const props = callView.mock.lastCall?.[0];
expect(props).toMatchObject({ backend: { roomId } });
expect(props).not.toHaveProperty("rtcSession");
});
test("shows no call in a room the host's client does not know", () => {
render(<ElementCall client={mockClient(null)} roomId={roomId} />);
expect(screen.queryByText("call")).toBeNull();
});
// No `matrixRTC`: the host's session manager is not ours to use
function mockClient(knownRoom: Room | null = room): MatrixClient {
return {
...mockEmitter(),
getRoom: (id: string) => (id === roomId ? knownRoom : null),
// What the call view's client is made from
baseUrl: "https://matrix.example.org",
getUserId: () => "@alice:example.org",
getDeviceId: () => "DEVICE",
getAccessToken: () => "token",
getSyncState: () => null,
getUser: () => null,
getCrypto: () => undefined,
sendEvent: vi.fn(),
sendStateEvent: vi.fn(),
_unstable_sendStickyEvent: vi.fn(),
_unstable_sendStickyDelayedEvent: vi.fn(),
cancelPendingEvent: vi.fn(),
encryptAndSendToDevice: vi.fn(),
redactEvent: vi.fn(),
decryptEventIfNeeded: vi.fn(),
setDisplayName: vi.fn(),
setAvatarUrl: vi.fn(),
uploadContent: vi.fn(),
doesServerSupportUnstableFeature: vi.fn(),
} as unknown as MatrixClient;
}
+118
View File
@@ -0,0 +1,118 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { afterEach, expect, test, vi } from "vitest";
import {
ClientEvent,
EventType,
type MatrixClient,
SyncState,
} from "matrix-js-sdk";
import { createComponentLocalJsClient } from "./componentLocalJsClient";
afterEach(() => {
vi.unstubAllGlobals();
});
test("reads the host's live state from the host's client", () => {
const host = mockHost();
const client = createComponentLocalJsClient(host);
const listener = (): void => {};
expect(client.getSyncState()).toBe(SyncState.Syncing);
client.on(ClientEvent.Sync, listener);
client.off(ClientEvent.Sync, listener);
client.getUser("@bob:example.org");
client.getCrypto();
expect(host.getSyncState).toHaveBeenCalledOnce();
expect(host.on).toHaveBeenCalledWith(ClientEvent.Sync, listener);
expect(host.off).toHaveBeenCalledWith(ClientEvent.Sync, listener);
expect(host.getUser).toHaveBeenCalledWith("@bob:example.org");
expect(host.getCrypto).toHaveBeenCalledOnce();
});
test("sends the RTC session's encrypted events with the host's crypto", async () => {
const host = mockHost();
const client = createComponentLocalJsClient(host);
await client._unstable_sendStickyEvent(
"!room:example.org",
1000,
null,
EventType.RTCMembership,
{ slot_id: "m.call#ROOM", msc4354_sticky_key: "key" },
);
await client.encryptAndSendToDevice("m.room.encrypted", [], {});
expect(host._unstable_sendStickyEvent).toHaveBeenCalledOnce();
expect(host.encryptAndSendToDevice).toHaveBeenCalledOnce();
});
test("takes its credentials from the host", () => {
const client = createComponentLocalJsClient(mockHost());
expect(client.getUserId()).toBe("@alice:example.org");
expect(client.getDeviceId()).toBe("DEVICE");
expect(client.getDomain()).toBe("example.org");
expect(client.baseUrl).toBe("https://matrix.example.org");
});
test("makes requests with whichever token the host holds now", async () => {
const fetch = vi.fn(
async () =>
await Promise.resolve(
new Response(JSON.stringify({ access_token: "openid" }), {
headers: { "Content-Type": "application/json" },
}),
),
);
vi.stubGlobal("fetch", fetch);
const host = mockHost();
const client = createComponentLocalJsClient(host);
// As if the host had refreshed its token after we were created
host.token = "refreshed";
await client.getOpenIdToken();
expect(fetch).toHaveBeenCalledOnce();
const [url, init] = fetch.mock.calls[0] as unknown as [URL, RequestInit];
expect(url.toString()).toBe(
"https://matrix.example.org/_matrix/client/v3/user/%40alice%3Aexample.org/openid/request_token",
);
expect(new Headers(init.headers).get("Authorization")).toBe(
"Bearer refreshed",
);
});
function mockHost(): MatrixClient & { token: string } {
const host = {
token: "first",
baseUrl: "https://matrix.example.org",
getUserId: (): string => "@alice:example.org",
getDeviceId: (): string => "DEVICE",
getAccessToken: (): string => host.token,
getSyncState: vi.fn(() => SyncState.Syncing),
on: vi.fn(),
off: vi.fn(),
getUser: vi.fn(() => null),
getCrypto: vi.fn(() => undefined),
sendEvent: vi.fn(),
sendStateEvent: vi.fn(),
_unstable_sendStickyEvent: vi.fn(),
_unstable_sendStickyDelayedEvent: vi.fn(),
encryptAndSendToDevice: vi.fn(),
redactEvent: vi.fn(),
decryptEventIfNeeded: vi.fn(),
setDisplayName: vi.fn(),
setAvatarUrl: vi.fn(),
uploadContent: vi.fn(),
doesServerSupportUnstableFeature: vi.fn(),
};
return host as unknown as MatrixClient & { token: string };
}
+108
View File
@@ -0,0 +1,108 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { createClient, type MatrixClient } from "matrix-js-sdk";
import type { createCallMatrixBackend } from "../src/CallMatrixBackend";
/**
* The client for Element Call in Component mode.
* We do get the full host client but we dont want to use it as it
* might use older versions of methods were we expect changes. (f.ex. getLivekitToken)
* We really want the expected implementation to not get runtime errors.
*
* This creates a new client that does use the hosts token and "stable"
* methods but uses the ElementCall Components js-sdk's client impl for anything else.
*/
export function createComponentLocalJsClient(
host: MatrixClient,
): Parameters<typeof createCallMatrixBackend>[0] {
const own = createClient({
baseUrl: host.baseUrl,
userId: host.getUserId() ?? undefined,
deviceId: host.getDeviceId() ?? undefined,
accessToken: host.getAccessToken() ?? undefined,
// The host refreshes its token without telling us, so each request takes
// whichever token the host holds now
fetchFn: async (input, init) => {
const headers = new Headers(init?.headers);
const token = host.getAccessToken();
if (token !== null) headers.set("Authorization", `Bearer ${token}`);
return globalThis.fetch(input, { ...init, headers });
},
});
return {
// Own has no sync loop: `syncApi?.getSyncState() ?? null` is always null
getSyncState: host.getSyncState.bind(host),
// Only the syncing host emits `Sync`, `ToDeviceEvent` and `Decrypted`
on: host.on.bind(host),
// The same emitter as `on`
off: host.off.bind(host),
// `this.store.getUser`: own's store is empty, only the host's sync fills it
getUser: host.getUser.bind(host),
// Own never inits crypto, and a second one on the device would corrupt it
getCrypto: host.getCrypto.bind(host),
// Own has no rooms: `encryptEventIfNeeded`'s `if (!room) return` skips E2EE
sendEvent: host.sendEvent.bind(host),
// Not encrypted, but the local echo goes to `getRoom()`: only the host's
redactEvent: host.redactEvent.bind(host),
// `attemptDecryption` only runs `if (this.getCrypto())`: a no-op on own
decryptEventIfNeeded: host.decryptEventIfNeeded.bind(host),
// Like `sendEvent`: on own, `if (!room) return` sends it in plaintext
_unstable_sendStickyEvent: host._unstable_sendStickyEvent.bind(host),
// Like `sendEvent`: delayed, but still `encryptEventIfNeeded(event, room)`
_unstable_sendStickyDelayedEvent:
host._unstable_sendStickyDelayedEvent.bind(host),
// `if (!this.cryptoBackend) throw`: own has no crypto
encryptAndSendToDevice: host.encryptAndSendToDevice.bind(host),
// Static: own was created with the host's user id
getUserId: own.getUserId.bind(own),
// Static: own was created with the host's device id
getDeviceId: own.getDeviceId.bind(own),
// Static: derived from the user id
getDomain: own.getDomain.bind(own),
// Static: own was created with the host's base URL
baseUrl: own.baseUrl,
// MSC4143 stable or unstable prefix, picked by /versions: ours knows both
getRTCTransports: own.getRTCTransports.bind(own),
// Plain HTTP with the copied credentials, like the other LiveKit auth
getOpenIdToken: own.getOpenIdToken.bind(own),
// MSC4195 stable or `io.element.msc4195` prefix: an older host may lack it
getLivekitToken: own.getLivekitToken.bind(own),
// MSC4195, like `getLivekitToken`: an older host may lack it
delegateDelayedLeave: own.delegateDelayedLeave.bind(own),
// Plain HTTP into own's cache, which `getCachedCapabilities` reads
fetchCapabilities: own.fetchCapabilities.bind(own),
// Has to be the client whose cache `fetchCapabilities` filled
getCachedCapabilities: own.getCachedCapabilities.bind(own),
// Straight to `scheduleDelayedEvent`: no room, no crypto, plain HTTP
_unstable_sendDelayedStateEvent:
own._unstable_sendDelayedStateEvent.bind(own),
// Plain POST `/delayed_events/{id}/cancel`; newer API an old host may lack
_unstable_cancelScheduledDelayedEvent:
own._unstable_cancelScheduledDelayedEvent.bind(own),
// Plain POST by the server's delay id: restarts the host's sticky leave too
_unstable_restartScheduledDelayedEvent:
own._unstable_restartScheduledDelayedEvent.bind(own),
// Plain POST `/delayed_events/{id}/send`; newer API an old host may lack
_unstable_sendScheduledDelayedEvent:
own._unstable_sendScheduledDelayedEvent.bind(own),
// Plain HTTP, either client works; a stable API, so the host's
sendStateEvent: host.sendStateEvent.bind(host),
// Updates the `User` in the host's store, which `useProfile` listens to
setDisplayName: host.setDisplayName.bind(host),
// Like `setDisplayName`: updates the `User` in the host's store
setAvatarUrl: host.setAvatarUrl.bind(host),
// Plain HTTP, either client works; a stable API, so the host's
uploadContent: host.uploadContent.bind(host),
// Reads the host's /versions, which it has already fetched
doesServerSupportUnstableFeature:
host.doesServerSupportUnstableFeature.bind(host),
};
}
+13 -6
View File
@@ -84,7 +84,9 @@ import styles from "./ElementCall.module.css";
import { useComponentHostBridge } from "./host";
import { CallPortalRoot } from "./CallPortalRoot";
import { type ElementCallProps } from "./api";
import { createComponentLocalJsClient } from "./componentLocalJsClient";
import { supportedLanguages, translationsBackend } from "./localization";
import { createCallMatrixBackend } from "../src/CallMatrixBackend";
// The languages Element Call can be shown in
export { supportedLanguages } from "./localization";
@@ -205,12 +207,14 @@ export const ElementCall: FC<ElementCallProps> = ({
}, [controlledAudioDevices, callIntent]);
const room = client.getRoom(roomId);
const rtcSession = useMemo(
() => (room === null ? null : client.matrixRTC.getRoomSession(room)),
const backend = useMemo(
() =>
room &&
createCallMatrixBackend(createComponentLocalJsClient(client), room),
[client, room],
);
if (rtcSession === null)
if (room === null)
logger.error(
`Element Call was asked to call in ${roomId}, which its host's client does not know about`,
);
@@ -220,7 +224,7 @@ export const ElementCall: FC<ElementCallProps> = ({
// is told that Element Call has loaded, as the widget tells its client once
// its own initialisation is over. Once per mount, however often the pieces
// are later swapped out.
const ready = container !== null && rtcSession !== null && vm !== null;
const ready = container !== null && backend !== null && vm !== null;
const announcedLoaded = useRef(false);
useEffect(() => {
if (!ready || announcedLoaded.current) return;
@@ -250,14 +254,17 @@ export const ElementCall: FC<ElementCallProps> = ({
>
<Decoration>
<TooltipProvider>
{/* The host's own client: what reads it through
the context (avatars, the encryption system,
rageshakes, the disconnected banner) uses only its
stable methods. */}
<ClientProvider client={client}>
<MediaDevicesContext value={vm.mediaDevices}>
<BackgroundEffectsProvider
effects={vm.backgroundEffects}
>
<CallView
client={client}
rtcSession={rtcSession}
backend={backend}
isPasswordlessUser={false}
confineToRoom={params.confineToRoom}
preload={params.preload}
+2 -2
View File
@@ -3,7 +3,7 @@ networks:
services:
auth-service:
image: ghcr.io/element-hq/lk-jwt-service:0.8.0
image: ghcr.io/element-hq/lk-jwt-service:0.10.0
pull_policy: always
hostname: auth-server
environment:
@@ -33,7 +33,7 @@ services:
- ecbackend
auth-service-1:
image: ghcr.io/element-hq/lk-jwt-service:0.8.0
image: ghcr.io/element-hq/lk-jwt-service:0.10.0
pull_policy: always
hostname: auth-server-1
environment:
+2 -2
View File
@@ -19,10 +19,10 @@ services:
- ./backend/playwright_homeserver-othersite.yaml:/data/cfg/homeserver.yaml:Z
element-web:
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
image: ghcr.io/element-hq/element-web:develop@sha256:72791f0b2541208f8f7edd9c6b5a7eaf88accd8ed1f0c4db1bc62bfe18eb90fe
image: ghcr.io/element-hq/element-web:develop@sha256:f85350f2b31a7521a800d9050e9f5c0676d04cfb60675242ccc0c6e25cad7d04
element-web-1:
# Pin to a SHA so that upstream cannot break our tests. Renovate handles regular updates.
image: ghcr.io/element-hq/element-web:develop@sha256:72791f0b2541208f8f7edd9c6b5a7eaf88accd8ed1f0c4db1bc62bfe18eb90fe
image: ghcr.io/element-hq/element-web:develop@sha256:f85350f2b31a7521a800d9050e9f5c0676d04cfb60675242ccc0c6e25cad7d04
volumes:
# The other site opens the embedded package under test in place of the
# copy its image bundles (the first site opens the dev server's app.
+5 -1
View File
@@ -14,7 +14,11 @@ This folder contains documentation for setup, usage, and development of Element
Entry point: [AGENTS.md](../AGENTS.md).
- [Agent workflow](./agents/workflow.md)
- [Architecture](./agents/architecture.md)
- [Code style](./agents/code-style.md)
- [Testing](./agents/testing.md)
Opt-in skills in [`.claude/skills/`](../.claude/skills/):
- `/handoff <task>` — get the first implementation back for a direction check
before lint, the full suite and polish.
+16 -9
View File
@@ -10,6 +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 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.
@@ -36,15 +43,15 @@ Element Call can be mounted several times inside a host's React tree, so it owns
neither window, URL, document nor router. Each seam defaults to the old standalone
and widget behaviour.
| Never | Use |
| --------------------------------------------- | ------------------------------------------------------------- |
| the `widget` global | `useHostBridge()` — `src/HostBridge.ts` |
| `getUrlParams()`, `window.location` | `useUrlParams()` |
| `useNavigate("/")`, `<Link to="/">` | `useLeaveToHome()`, `LeaveToHomeLink` |
| `document.body` | `useRootElement()` |
| `window.innerWidth/Height`, `useMediaQuery` | `useRootSizeMatches()` in views, `windowSize$` in view models |
| global `i18next` | the instance in `src/utils/i18n.ts` |
| config or analytics reading their environment | `Config.initWith()`, `PosthogAnalytics.configure()` |
| Never | Use |
| --------------------------------------------- | ----------------------------------------------------------- |
| the `widget` global | `useHostBridge()` — `src/HostBridge.ts` |
| `getUrlParams()`, `window.location` | `useUrlParams()` |
| `useNavigate("/")`, `<Link to="/">` | `useLeaveToHome()`, `LeaveToHomeLink` |
| `document.body` | `useRootElement()` |
| `window.innerWidth/Height`, `useMediaQuery` | `useRootSizeMatches()` in views, `viewSize$` in view models |
| global `i18next` | the instance in `src/utils/i18n.ts` |
| config or analytics reading their environment | `Config.initWith()`, `PosthogAnalytics.configure()` |
- View models take values as options, never `getUrlParams()`
(`callViewModelOptionsFromParams`, `CallViewModelOptions.hostBridge`).
-50
View File
@@ -1,50 +0,0 @@
# Agent workflow
## Scratch files live in `agent-workspace/`
Git-ignored. One kebab-case subfolder per task, matching the branch topic:
`agent-workspace/<slug>/`.
| File | Purpose |
| --------------------------- | -------------------------------------------------------------------------------- |
| `plan.md` | The concrete approach — files, symbols, edit order — once direction is confirmed |
| `commit-msg.txt` | `git commit -F agent-workspace/<slug>/commit-msg.txt` |
| `pr-body.md` | `gh pr create --body-file agent-workspace/<slug>/pr-body.md` |
| `implementation-summary.md` | What was built, decisions, trade-offs |
| `NN-prompt.md` | Raw prompt text, numbered, when worth keeping |
- Nothing here is durable. The folder is ignored, so anything worth keeping is
promoted into the PR body, a doc, or a feature spec before the task ends.
- Never write scratch files to the repo root. Stray `load_test_summary.md` and
`config.json_` files are what this folder prevents.
- Start `pr-body.md` from `.github/PULL_REQUEST_TEMPLATE.md` and fill every
section.
- Commit subjects are plain imperative English. No conventional-commits prefixes.
- A `plan.md` and a feature spec sit at different altitudes; neither replaces the
other. A spec in `FEATURES_SPEC/` is durable and deliberately abstract —
behaviour, decisions, acceptance criteria — so the feature can be rebuilt against
a `main` nobody has seen yet. A plan is one slice of it landing on today's
`main`: the paths, symbols and edit order the spec's decisions and criteria must
not name. `FEATURES_SPEC/AGENTS.md` wins wherever the two genuinely overlap.
## Hand off before the quality pass
- Implement the change, run the narrowest check that rules out an obviously broken
handoff, then stop and ask whether the direction is right.
- Full `pnpm lint`, the whole suite, coverage and benchmarks come after the
direction is confirmed.
- Wider refactors, extra tests and documentation polish are follow-up work, not
part of the first handoff.
- If a check is needed before feedback, keep it to the touched code and say why.
## Commit and PR readiness
- Commit once the user confirms direction, or asks for one. Not before. Where the
setup has no git identity, a sandbox included, write the message to
`commit-msg.txt` and hand it over instead.
- Ready means every gate in [AGENTS.md](../../AGENTS.md#gates) is green and the
change is covered at the layers [testing.md](./testing.md) asks for. Read the diff
against [code-style.md](./code-style.md) first.
- Re-run the whole checklist after any fix. Only on green, either way.
- Once a human has started reviewing, fix forward — never force-push a
regeneration over a review in progress.
-2
View File
@@ -118,8 +118,6 @@
"livekit_connection_error": "Failed to connect to Livekit server",
"livekit_connection_error_description": "An error occurred while connecting to the Livekit server (<1>Reason:</1> <2>{{ reason }}</2>).",
"matrix_rtc_transport_missing": "The server is not configured to work with {{brand}} and no other call participant provides a usable transport. Please contact your server admin (Domain: {{domain}}, Error Code: {{ errorCode }}).",
"membership_manager": "Membership Manager Error",
"membership_manager_description": "The Membership Manager had to shut down. This is caused by many consecutive failed network requests.",
"no_matrix_2_authorization_service": "The authorization service for your media server (SFU) is out of date.",
"open_elsewhere": "Opened in another tab",
"open_elsewhere_description": "{{brand}} has been opened in another tab. If that doesn't sound right, try reloading the page.",
+2 -2
View File
@@ -107,11 +107,11 @@
"livekit-client": "^2.18.1",
"lodash-es": "^4.17.21",
"loglevel": "^1.9.1",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#dc8610e796c92553c658300a4882dde961a0678a",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#6c8b1b418189919bc69fd9df5e57354e7b3c39cb",
"matrix-widget-api": "^1.18.0",
"node-stdlib-browser": "^1.3.1",
"normalize.css": "^8.0.1",
"oxfmt": "^0.66.0",
"oxfmt": "^0.79.0",
"oxlint": "^1.70.0",
"oxlint-tsgolint": "^0.25.0",
"pako": "^2.0.4",
+111 -122
View File
@@ -16,7 +16,7 @@ overrides:
undici: ^6.27.0
flatted: ^3.4.2
ws: ^8.21.0
dompurify: ^3.4.11
dompurify: ^3.4.17
importers:
@@ -39,7 +39,7 @@ importers:
version: 11.7.12
'@livekit/components-core':
specifier: ^0.12.0
version: 0.12.15(livekit-client@2.23.0(@types/dom-mediacapture-record@1.0.22))(tslib@2.8.1)
version: 0.12.16(livekit-client@2.23.0(@types/dom-mediacapture-record@1.0.22))(tslib@2.8.1)
'@livekit/track-processors':
specifier: ^0.7.1
version: 0.7.2(@types/dom-mediacapture-transform@0.1.11)(livekit-client@2.23.0(@types/dom-mediacapture-record@1.0.22))
@@ -191,8 +191,8 @@ importers:
specifier: ^1.9.1
version: 1.9.2
matrix-js-sdk:
specifier: github:matrix-org/matrix-js-sdk#dc8610e796c92553c658300a4882dde961a0678a
version: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/dc8610e796c92553c658300a4882dde961a0678a
specifier: github:matrix-org/matrix-js-sdk#6c8b1b418189919bc69fd9df5e57354e7b3c39cb
version: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/6c8b1b418189919bc69fd9df5e57354e7b3c39cb
matrix-widget-api:
specifier: ^1.18.0
version: 1.20.0
@@ -203,8 +203,8 @@ importers:
specifier: ^8.0.1
version: 8.0.1
oxfmt:
specifier: ^0.66.0
version: 0.66.0
specifier: ^0.79.0
version: 0.79.0
oxlint:
specifier: ^1.70.0
version: 1.81.0(oxlint-tsgolint@0.25.0)
@@ -943,9 +943,6 @@ packages:
'@floating-ui/core@1.8.0':
resolution: {integrity: sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==}
'@floating-ui/dom@1.7.6':
resolution: {integrity: sha512-9gZSAI5XM36880PPMm//9dfiEngYoC6Am2izES1FF406YFsjvyBMmeJ2g4SAju3xWwtuynNRFL2s9hgxpLI5SQ==}
'@floating-ui/dom@1.8.0':
resolution: {integrity: sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==}
@@ -1176,8 +1173,8 @@ packages:
'@jridgewell/trace-mapping@0.3.31':
resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==}
'@livekit/components-core@0.12.15':
resolution: {integrity: sha512-bDkK+jkPMgyT4a5lZmdcuc/hZ8fZUrXW+qQPNHVeSpXCBMzk5q9QWzx+HPtTsPJ8hnncWGfoT81RnXHBsy+Z8g==}
'@livekit/components-core@0.12.16':
resolution: {integrity: sha512-jcXuNeHKGkXgRiT4wniWRpg+TKUSoTL9da01tMxxKGmjp98zB2DVgPmk1fBZfgDVjPBF+jsZe/WkeFAbvJu4Gw==}
engines: {node: '>=18'}
peerDependencies:
livekit-client: ^2.20.1
@@ -1195,8 +1192,8 @@ packages:
'@types/dom-mediacapture-transform': ^0.1.9
livekit-client: ^1.12.0 || ^2.1.0
'@matrix-org/matrix-sdk-crypto-wasm@18.9.0':
resolution: {integrity: sha512-NtLzNDTEfNASBjNCTGZHuk7N0jrQhS6Zx2CM857rCHZYYh/rpbKGQNrJ7azktm4S1P5Jy3WU3nwJTGohGw26qQ==}
'@matrix-org/matrix-sdk-crypto-wasm@18.9.2':
resolution: {integrity: sha512-GHeuSeb5Fj6Wg2+NE/WoLJJs9U3nOzttO+2sj7lOaS5gNBpGIksc48N/Q/kK/Z+Lxh7YMhopB7M8b6HyASXnGQ==}
engines: {node: '>= 18'}
'@mdx-js/react@3.1.1':
@@ -1629,124 +1626,124 @@ packages:
cpu: [x64]
os: [win32]
'@oxfmt/binding-android-arm-eabi@0.66.0':
resolution: {integrity: sha512-2Me9eoptv6ERdEuI2P8AOlYdHHraXebJaM6SC0kc2Dfb+mLrep2db+fedBPKaYn673h/vBgvP4tkOdAbaudX6w==}
'@oxfmt/binding-android-arm-eabi@0.79.0':
resolution: {integrity: sha512-xOCQ/rvokUXs8SxOQY5Wy2ukPaZJZ0PmdJovN0ryB1c8DVEtbcvliLdYtINUYh8QOTpmBOctIisSJk9tvh+J6w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [android]
'@oxfmt/binding-android-arm64@0.66.0':
resolution: {integrity: sha512-u7O+bSSF0HGsDKkQQxBqvLGVepu93RA+JKu+ONqvfh4sCnCEbj31wZj4iG5gk3XfRwrmYj0/8catkO2LcblQKQ==}
'@oxfmt/binding-android-arm64@0.79.0':
resolution: {integrity: sha512-WMLDvCjjchUYtI6zXKOdzTDGm72BaYZiz1/VhB1rrxdakUZRlJh1aMr3CT6ui51uHcWVBycULIXSZHpw6u2pTQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [android]
'@oxfmt/binding-darwin-arm64@0.66.0':
resolution: {integrity: sha512-/ikyMIVjX/sdo7KtjxoEsSUosfPzveVhT9RWMx9yGqFDKFJ89JAEKuEeLBmurDjrkb4w8tOnAdSO3SBaplY3bw==}
'@oxfmt/binding-darwin-arm64@0.79.0':
resolution: {integrity: sha512-+LzSN7w7tULz96ntS1Uqe5oI00XZ0o/m/t3+eSfiQp3aTPnj2eGUafqEWryMLk84j7x9NiF+GEP2YT4/BfClgA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [darwin]
'@oxfmt/binding-darwin-x64@0.66.0':
resolution: {integrity: sha512-q5xUsKeFqawa9NXa6ZGXWimFV19m8MogKPdTaSVDAAk2EQKBmBZRDeluwcl1p8ty/OFc9s9888OKEh3xfPVH0g==}
'@oxfmt/binding-darwin-x64@0.79.0':
resolution: {integrity: sha512-KFiMRhKeiiooaS1dKc4r8AZgOrfOhwVe1yf/aRef+8BajJwtVjMtlsQl/BNRxtkFbq13GjEo/4Q+9YhFGU4o6g==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [darwin]
'@oxfmt/binding-freebsd-x64@0.66.0':
resolution: {integrity: sha512-CR+x4VzMY0pRXLK/xFQ/RzsSFkP5t2Z2mef0QY6OP/rTRcMUoMLCOM62/3Fp/t0K+UDoBKxvMyeb6D0zPMjleA==}
'@oxfmt/binding-freebsd-x64@0.79.0':
resolution: {integrity: sha512-lHVIp0g8ZOFKiqVscvttp+3HJkkRH6XkGgfAA0lVexIlE1mMFVp4V7RBdxz/P9p7T8pSNsYdapFWvdT21Mib9w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [freebsd]
'@oxfmt/binding-linux-arm-gnueabihf@0.66.0':
resolution: {integrity: sha512-ZEYmO/LbH9tTQCADILHGZE4GeOXOAj2VzedHkASNwjmwlwtutJCLpCJbIs37wRGTFgWRoEcD72jpMX+IBJUGjQ==}
'@oxfmt/binding-linux-arm-gnueabihf@0.79.0':
resolution: {integrity: sha512-Pt35GoxiMUfnr+23cuzk07XQVvISDFxxPcp/aFVB87+RQvJoQaBo/XN7Re9XxgElvbELdyxTLnV9XM2aTfJeUA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
'@oxfmt/binding-linux-arm-musleabihf@0.66.0':
resolution: {integrity: sha512-hNtR9/oU0CeTkq7JnRkmBQwqe17v2ZaAMLC4VcN7IIOWeRyWDk0knSPWS9iiLmtbZ2RRBBtsG01jQgkZmKCJeQ==}
'@oxfmt/binding-linux-arm-musleabihf@0.79.0':
resolution: {integrity: sha512-zPi9Dni58VKp3r1QUcFvnbJNfBr49qyecq0vlM4SaX/MSjmguq77VngirghDua5tyhIDfqdUMTCK2KRlnZFp/g==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
'@oxfmt/binding-linux-arm64-gnu@0.66.0':
resolution: {integrity: sha512-uwOVQ8i6I1LT/+eDzfsgrrcZp8Fn6NPVUPn8fF5gdFGekFf0PddF+LEuwsD0/pbNUcKZhDj2rQ5UpITh9gF4iQ==}
'@oxfmt/binding-linux-arm64-gnu@0.79.0':
resolution: {integrity: sha512-XhRehATEWjwX7VVEgDUD+7pfHYncQIJaEU0qsHvEKtu9XX0QYzcKvXhU9+URfiGX9WRh3wy2Ow+YCc3EeHtImg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@oxfmt/binding-linux-arm64-musl@0.66.0':
resolution: {integrity: sha512-tTkF2Dmx4nGAjmBlZb+UtTGqR/EK4ZrW9qBfzte07a9XWqzoGGKzpFFlyNDhQe+Uwql94+ReCTeNbhOXscw1Dg==}
'@oxfmt/binding-linux-arm64-musl@0.79.0':
resolution: {integrity: sha512-gbVjFZYug0MEyqvuTAzXGNxFJmBqBO32o1Fud1lG8bGs6oVz48ZtNQyEcAzqrOwaaG+Sxtv4gVzcsfht9aqmkg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [musl]
'@oxfmt/binding-linux-ppc64-gnu@0.66.0':
resolution: {integrity: sha512-F3cKHUav4yXOHn6GFnwpBhSYsJOYKKf9eqO/9jlEuqPxNw9zb98E9ZFct79gcg8pibUGkbveEu9WDlmXJpDzKw==}
'@oxfmt/binding-linux-ppc64-gnu@0.79.0':
resolution: {integrity: sha512-0N0sD3vnllyuiNh1r6zKvNXWE/CakcPKJAespg7XE2+sfvxpz5Q1iFah8sF5aedsOmVvbZaOPZcSHVmMosT1fA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ppc64]
os: [linux]
libc: [glibc]
'@oxfmt/binding-linux-riscv64-gnu@0.66.0':
resolution: {integrity: sha512-K5fDaNZfDyQMYA/3qL21bqyN0X9T15LLwwbFPt2aHc94+ZG7bh0vZEsy2y7NlRnjjHFSwN+Hzg6ldJtbOriH4Q==}
'@oxfmt/binding-linux-riscv64-gnu@0.79.0':
resolution: {integrity: sha512-YtjqUHolcX6cv0ZMZuKQCM4H0ae/okcowy0wGcPHJk4O+8zjy3TvNhzDQ1/KGCkMJO8Fwulm1JcPJsraVJ3p+w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
libc: [glibc]
'@oxfmt/binding-linux-riscv64-musl@0.66.0':
resolution: {integrity: sha512-44Yc+I+qOmTElRcEhm5hUKIUJEQIOugymz4ua4tB0Wox7tGAfIbjzmXz/HDAtw1Ij6gmBwZlzh4hc9679RhWeA==}
'@oxfmt/binding-linux-riscv64-musl@0.79.0':
resolution: {integrity: sha512-H2gb9bEBr5tcdP5FU8JYTfgOavXDorWcAAlwci/zEKF2jzgh/oEr/SAw6aHB9n3FLEvnKvOh0A1fjku+vgYoUA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
libc: [musl]
'@oxfmt/binding-linux-s390x-gnu@0.66.0':
resolution: {integrity: sha512-1e29Eg9hEj2kRBB19M0seIehPbbXHCk35GvImjDvb79rjjYjXCRmtbUNHJcgoktZAMIzXrTbxDBKmTc1V4bg3A==}
'@oxfmt/binding-linux-s390x-gnu@0.79.0':
resolution: {integrity: sha512-aZUbyWW5dSOxT/u6suWc4S9GVDt7YPPNMKQon+z79M8dpXmosadcFHAb7jBhpU7Hdsd2GN6/y3nd0JFTsGddZw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [s390x]
os: [linux]
libc: [glibc]
'@oxfmt/binding-linux-x64-gnu@0.66.0':
resolution: {integrity: sha512-vODY1UQo10gngn0+D4xHKU84F1Twm1LqrzV4SqPXvmQKSd87paehvZ6jqA5wKs6XQrlWul9clYMDVHcoW9CPMA==}
'@oxfmt/binding-linux-x64-gnu@0.79.0':
resolution: {integrity: sha512-5pW/ZHYfjjQ71gQR+EKzDz8ZzWIDHlTUtWtxVFNgZbKxVZnRxiSXVrllbjpJtx1q8VtSPZ+Lyg9BLny3yw+PTA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [glibc]
'@oxfmt/binding-linux-x64-musl@0.66.0':
resolution: {integrity: sha512-YDzXx2JsT4+HL4MdkVrYjO55NS5lUKNm8rLC4ZPou8+seu0v0jhecSh+ufoO6+xEa8gccEezMlI2WHJi4ApUgw==}
'@oxfmt/binding-linux-x64-musl@0.79.0':
resolution: {integrity: sha512-3IVUerTDB7Dvd90c1EurAzlVnlE9Azl7Wn8e33qX3wL/IqnslF+P7HvwkD+VeMbHxRtuw0EEBGSArZFXpUAZrQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [musl]
'@oxfmt/binding-openharmony-arm64@0.66.0':
resolution: {integrity: sha512-mJjUYd8lj0+j4JkYyEM+5qKBf1Rnrpgjn/SVYKJhicVDqLz566ooa7Fs8zflPqt+dnZDV7X054rVIQX6ZcQNlQ==}
'@oxfmt/binding-openharmony-arm64@0.79.0':
resolution: {integrity: sha512-C5QDgJBtu9+/2BQScoP7ynv54PLOqfoSqhRWwI0D0RPOwYD4tYj0TUdJbXMO1fNegL/5zJiSOxkq6II2xvttWg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [openharmony]
'@oxfmt/binding-win32-arm64-msvc@0.66.0':
resolution: {integrity: sha512-soV+0vESv7e5ntCHWC61x4gg8OSak6IHHnWsZmHrJFlvMj2AK+kmldErCNkVkrvc1Ts2/++rJXn+IuAb2WMXhw==}
'@oxfmt/binding-win32-arm64-msvc@0.79.0':
resolution: {integrity: sha512-zlW1m8M49vNGgqQF/ze80KW8pZMicnW2XDZGBHuYtXTRYn4ewvgpqN9wwoqb6uLZZfb1R1zaQWKEB8cs7KYjwA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [win32]
'@oxfmt/binding-win32-ia32-msvc@0.66.0':
resolution: {integrity: sha512-YCPi23uRIEYuIKTZohAkKbPFpujQ5QBuUM5iDv+UqbCmTPAkaFsxjsSuB8xlBpRT0G7eP/4HMF+cPDSqHtOD9A==}
'@oxfmt/binding-win32-ia32-msvc@0.79.0':
resolution: {integrity: sha512-wbb7hFv2wK3SCTfu8dl1ydNsXM5dmH+PJMU3sojCkfKcG29VDpITL5/AtouCzXjkOc90QRkcAZcg36gP0KqoHA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ia32]
os: [win32]
'@oxfmt/binding-win32-x64-msvc@0.66.0':
resolution: {integrity: sha512-bwTQcv/JVRPkOqQtMF0X7vpvpncDQiBcXHxZ9S2hR12Hlo8bvBdUR5x5XnxzDZ3kM0qoZw1rv7KaD66Ly+pFWA==}
'@oxfmt/binding-win32-x64-msvc@0.79.0':
resolution: {integrity: sha512-JLaeaQ+4LkQiVXY06JIV1dBFEDJzssvDieK/3Poi6CsY+c4UxghZVrrsfcKGJ5R/0F2Sw3C5Lf5Hu0sM5qJfPw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [win32]
@@ -3898,8 +3895,8 @@ packages:
resolution: {integrity: sha512-GrwoxYN+uWlzO8uhUXRl0P+kHE4GtVPfYzVLcUxPL7KNdHKj66vvlhiweIHqYYXWlw+T8iLMp42Lm67ghw4WMQ==}
engines: {node: '>= 4'}
dompurify@3.4.12:
resolution: {integrity: sha512-zQvGet8Z2sWbQhCmfFz/T5QWH2oBmjnqK3qvOjaqaNLrLEF912WamU+ohnTp0TCep/MFVHpdJuCZEdFOdTnEFg==}
dompurify@3.4.18:
resolution: {integrity: sha512-ofe3wI/uNm68HInABYFJYqQxRw1EaKAjNdrFVKqjUY+UZurvNd2L/HuQe097s/4RivWiZyP6tT7aoT8atjfhwg==}
domutils@2.8.0:
resolution: {integrity: sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==}
@@ -4679,10 +4676,6 @@ packages:
resolution: {integrity: sha512-ja1E3yCr9i/0hmBVaM0bfwDjnGy8I/s6PP4DFp+yP+a+mrHO4Rm7DtmnqROTUkHIkqffC84YY7AeqX6oFk0WFg==}
engines: {node: '>=18'}
loglevel@1.9.1:
resolution: {integrity: sha512-hP3I3kCrDIMuRwAwHltphhDM1r8i55H33GgqjXbrisuJhF4kRhW1dNuxsRklp4bXl8DSdLaNLuiL4A/LWRfxvg==}
engines: {node: '>= 0.6.0'}
loglevel@1.9.2:
resolution: {integrity: sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==}
engines: {node: '>= 0.6.0'}
@@ -4734,9 +4727,9 @@ packages:
matrix-events-sdk@0.0.1:
resolution: {integrity: sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==}
matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/dc8610e796c92553c658300a4882dde961a0678a:
resolution: {gitHosted: true, integrity: sha512-Ldt/VkCzBtre6m1cn0FqgrzRV0GrgWIoARgQUQO58ef2Edu2ERFCINPzp/psFS5RwoN3RIy9Rm4oPVc1ATkEWA==, tarball: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/dc8610e796c92553c658300a4882dde961a0678a}
version: 45.0.0
matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/6c8b1b418189919bc69fd9df5e57354e7b3c39cb:
resolution: {gitHosted: true, tarball: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/6c8b1b418189919bc69fd9df5e57354e7b3c39cb}
version: 45.1.0
engines: {node: '>=22.0.0'}
matrix-widget-api@1.20.0:
@@ -4900,14 +4893,17 @@ packages:
oxc-resolver@11.21.2:
resolution: {integrity: sha512-w5tLwYN3Zo24w5EeWJjJWZOwhYqTtC8PS2B1tIt7BZUuqTIcU07sQValbDw+rq7+AuAGzOHklgK+ifsy4lpXfw==}
oxfmt@0.66.0:
resolution: {integrity: sha512-FfvqR8RFtV6JJpRrpkfqyVCQ7HDvZ/VriWFx7veftCgL1B5ZO9qNr+1rvPieycMQnNfVG0PWyJQiy7p0hq1I5w==}
oxfmt@0.79.0:
resolution: {integrity: sha512-92iLHGxAgtYk6jLp/1ZBnEeABveNduHZgMDQj7tyqO9iafuJG3q+YHJq0R5Aa4YT+E6xswMQXdmPZYMwynS8ig==}
engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true
peerDependencies:
'@astrojs/compiler-rs': ^0.5.0
svelte: ^5.0.0
vite-plus: '*'
peerDependenciesMeta:
'@astrojs/compiler-rs':
optional: true
svelte:
optional: true
vite-plus:
@@ -5791,8 +5787,8 @@ packages:
resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==}
engines: {node: '>=12.0.0'}
tinypool@2.1.0:
resolution: {integrity: sha512-Pugqs6M0m7Lv1I7FtxN4aoyToKg1C4tu+/381vH35y8oENM/Ai7f7C4StcoK4/+BSw9ebcS8jRiVrORFKCALLw==}
tinypool@2.2.0:
resolution: {integrity: sha512-jBrmx4lYmaC9k/mgPbylxs7kBUxHtD8256up+HjLaDFfXScKJQyil+SWXSvhAtT7XHo+yTVlpB81PGmHP8oLSQ==}
engines: {node: ^20.0.0 || >=22.0.0}
tinyrainbow@2.0.0:
@@ -6920,11 +6916,6 @@ snapshots:
dependencies:
'@floating-ui/utils': 0.2.12
'@floating-ui/dom@1.7.6':
dependencies:
'@floating-ui/core': 1.8.0
'@floating-ui/utils': 0.2.12
'@floating-ui/dom@1.8.0':
dependencies:
'@floating-ui/core': 1.8.0
@@ -7158,11 +7149,11 @@ snapshots:
'@jridgewell/resolve-uri': 3.1.2
'@jridgewell/sourcemap-codec': 1.6.0
'@livekit/components-core@0.12.15(livekit-client@2.23.0(@types/dom-mediacapture-record@1.0.22))(tslib@2.8.1)':
'@livekit/components-core@0.12.16(livekit-client@2.23.0(@types/dom-mediacapture-record@1.0.22))(tslib@2.8.1)':
dependencies:
'@floating-ui/dom': 1.7.6
'@floating-ui/dom': 1.8.0
livekit-client: 2.23.0(@types/dom-mediacapture-record@1.0.22)
loglevel: 1.9.1
loglevel: 1.9.2
rxjs: 7.8.2
tslib: 2.8.1
@@ -7178,7 +7169,7 @@ snapshots:
'@types/dom-mediacapture-transform': 0.1.11
livekit-client: 2.23.0(@types/dom-mediacapture-record@1.0.22)
'@matrix-org/matrix-sdk-crypto-wasm@18.9.0': {}
'@matrix-org/matrix-sdk-crypto-wasm@18.9.2': {}
'@mdx-js/react@3.1.1(@types/react@19.2.18)(react@19.3.1)':
dependencies:
@@ -7476,61 +7467,61 @@ snapshots:
'@oxc-resolver/binding-win32-x64-msvc@11.21.2':
optional: true
'@oxfmt/binding-android-arm-eabi@0.66.0':
'@oxfmt/binding-android-arm-eabi@0.79.0':
optional: true
'@oxfmt/binding-android-arm64@0.66.0':
'@oxfmt/binding-android-arm64@0.79.0':
optional: true
'@oxfmt/binding-darwin-arm64@0.66.0':
'@oxfmt/binding-darwin-arm64@0.79.0':
optional: true
'@oxfmt/binding-darwin-x64@0.66.0':
'@oxfmt/binding-darwin-x64@0.79.0':
optional: true
'@oxfmt/binding-freebsd-x64@0.66.0':
'@oxfmt/binding-freebsd-x64@0.79.0':
optional: true
'@oxfmt/binding-linux-arm-gnueabihf@0.66.0':
'@oxfmt/binding-linux-arm-gnueabihf@0.79.0':
optional: true
'@oxfmt/binding-linux-arm-musleabihf@0.66.0':
'@oxfmt/binding-linux-arm-musleabihf@0.79.0':
optional: true
'@oxfmt/binding-linux-arm64-gnu@0.66.0':
'@oxfmt/binding-linux-arm64-gnu@0.79.0':
optional: true
'@oxfmt/binding-linux-arm64-musl@0.66.0':
'@oxfmt/binding-linux-arm64-musl@0.79.0':
optional: true
'@oxfmt/binding-linux-ppc64-gnu@0.66.0':
'@oxfmt/binding-linux-ppc64-gnu@0.79.0':
optional: true
'@oxfmt/binding-linux-riscv64-gnu@0.66.0':
'@oxfmt/binding-linux-riscv64-gnu@0.79.0':
optional: true
'@oxfmt/binding-linux-riscv64-musl@0.66.0':
'@oxfmt/binding-linux-riscv64-musl@0.79.0':
optional: true
'@oxfmt/binding-linux-s390x-gnu@0.66.0':
'@oxfmt/binding-linux-s390x-gnu@0.79.0':
optional: true
'@oxfmt/binding-linux-x64-gnu@0.66.0':
'@oxfmt/binding-linux-x64-gnu@0.79.0':
optional: true
'@oxfmt/binding-linux-x64-musl@0.66.0':
'@oxfmt/binding-linux-x64-musl@0.79.0':
optional: true
'@oxfmt/binding-openharmony-arm64@0.66.0':
'@oxfmt/binding-openharmony-arm64@0.79.0':
optional: true
'@oxfmt/binding-win32-arm64-msvc@0.66.0':
'@oxfmt/binding-win32-arm64-msvc@0.79.0':
optional: true
'@oxfmt/binding-win32-ia32-msvc@0.66.0':
'@oxfmt/binding-win32-ia32-msvc@0.79.0':
optional: true
'@oxfmt/binding-win32-x64-msvc@0.66.0':
'@oxfmt/binding-win32-x64-msvc@0.79.0':
optional: true
'@oxlint-tsgolint/darwin-arm64@0.25.0':
@@ -9515,7 +9506,7 @@ snapshots:
dependencies:
domelementtype: 2.3.0
dompurify@3.4.12:
dompurify@3.4.18:
optionalDependencies:
'@types/trusted-types': 2.0.7
@@ -10029,7 +10020,7 @@ snapshots:
i18next-resources-for-ts@2.1.0:
dependencies:
'@babel/runtime': 7.29.7
'@babel/runtime': 7.29.10
'@swc/core': 1.16.2
chokidar: 5.0.0
yaml: 2.9.0
@@ -10363,8 +10354,6 @@ snapshots:
is-unicode-supported: 2.1.0
yoctocolors: 2.2.0
loglevel@1.9.1: {}
loglevel@1.9.2: {}
loupe@3.2.1: {}
@@ -10413,10 +10402,10 @@ snapshots:
matrix-events-sdk@0.0.1: {}
matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/dc8610e796c92553c658300a4882dde961a0678a:
matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/6c8b1b418189919bc69fd9df5e57354e7b3c39cb:
dependencies:
'@babel/runtime': 8.0.8
'@matrix-org/matrix-sdk-crypto-wasm': 18.9.0
'@matrix-org/matrix-sdk-crypto-wasm': 18.9.2
another-json: 0.2.0
bs58: 6.0.0
content-type: 3.1.1
@@ -10674,29 +10663,29 @@ snapshots:
'@oxc-resolver/binding-win32-arm64-msvc': 11.21.2
'@oxc-resolver/binding-win32-x64-msvc': 11.21.2
oxfmt@0.66.0:
oxfmt@0.79.0:
dependencies:
tinypool: 2.1.0
tinypool: 2.2.0
optionalDependencies:
'@oxfmt/binding-android-arm-eabi': 0.66.0
'@oxfmt/binding-android-arm64': 0.66.0
'@oxfmt/binding-darwin-arm64': 0.66.0
'@oxfmt/binding-darwin-x64': 0.66.0
'@oxfmt/binding-freebsd-x64': 0.66.0
'@oxfmt/binding-linux-arm-gnueabihf': 0.66.0
'@oxfmt/binding-linux-arm-musleabihf': 0.66.0
'@oxfmt/binding-linux-arm64-gnu': 0.66.0
'@oxfmt/binding-linux-arm64-musl': 0.66.0
'@oxfmt/binding-linux-ppc64-gnu': 0.66.0
'@oxfmt/binding-linux-riscv64-gnu': 0.66.0
'@oxfmt/binding-linux-riscv64-musl': 0.66.0
'@oxfmt/binding-linux-s390x-gnu': 0.66.0
'@oxfmt/binding-linux-x64-gnu': 0.66.0
'@oxfmt/binding-linux-x64-musl': 0.66.0
'@oxfmt/binding-openharmony-arm64': 0.66.0
'@oxfmt/binding-win32-arm64-msvc': 0.66.0
'@oxfmt/binding-win32-ia32-msvc': 0.66.0
'@oxfmt/binding-win32-x64-msvc': 0.66.0
'@oxfmt/binding-android-arm-eabi': 0.79.0
'@oxfmt/binding-android-arm64': 0.79.0
'@oxfmt/binding-darwin-arm64': 0.79.0
'@oxfmt/binding-darwin-x64': 0.79.0
'@oxfmt/binding-freebsd-x64': 0.79.0
'@oxfmt/binding-linux-arm-gnueabihf': 0.79.0
'@oxfmt/binding-linux-arm-musleabihf': 0.79.0
'@oxfmt/binding-linux-arm64-gnu': 0.79.0
'@oxfmt/binding-linux-arm64-musl': 0.79.0
'@oxfmt/binding-linux-ppc64-gnu': 0.79.0
'@oxfmt/binding-linux-riscv64-gnu': 0.79.0
'@oxfmt/binding-linux-riscv64-musl': 0.79.0
'@oxfmt/binding-linux-s390x-gnu': 0.79.0
'@oxfmt/binding-linux-x64-gnu': 0.79.0
'@oxfmt/binding-linux-x64-musl': 0.79.0
'@oxfmt/binding-openharmony-arm64': 0.79.0
'@oxfmt/binding-win32-arm64-msvc': 0.79.0
'@oxfmt/binding-win32-ia32-msvc': 0.79.0
'@oxfmt/binding-win32-x64-msvc': 0.79.0
oxlint-tsgolint@0.25.0:
optionalDependencies:
@@ -11098,7 +11087,7 @@ snapshots:
'@posthog/core': 1.46.4
'@posthog/types': 1.400.0
core-js: 3.49.0
dompurify: 3.4.12
dompurify: 3.4.18
fflate: 0.4.8
preact: 10.29.8
query-selector-shadow-dom: 1.0.1
@@ -11214,7 +11203,7 @@ snapshots:
react-i18next@17.0.13(i18next@26.4.1(typescript@5.9.3))(react-dom@19.2.8(react@19.2.8))(react@19.2.8)(typescript@5.9.3):
dependencies:
'@babel/runtime': 7.29.7
'@babel/runtime': 7.29.10
html-parse-stringify: 4.0.1
i18next: 26.4.1(typescript@5.9.3)
react: 19.2.8
@@ -11671,7 +11660,7 @@ snapshots:
fdir: 6.5.0(picomatch@4.0.5)
picomatch: 4.0.5
tinypool@2.1.0: {}
tinypool@2.2.0: {}
tinyrainbow@2.0.0: {}
+4 -1
View File
@@ -59,4 +59,7 @@ overrides:
# - https://github.com/element-hq/element-call/security/dependabot/196
# - https://github.com/element-hq/element-call/security/dependabot/195
# - https://github.com/element-hq/element-call/security/dependabot/193
"dompurify": "^3.4.11"
# - https://github.com/advisories/GHSA-cg2g-xh64-v4q7
# - https://github.com/advisories/GHSA-mrv2-3pqr-j5jr
# - https://github.com/advisories/GHSA-c6gr-qvv4-5v3f
"dompurify": "^3.4.17"
+5 -3
View File
@@ -5,7 +5,7 @@
"schedule:monthly",
":enableVulnerabilityAlertsWithLabel(security)"
],
"addLabels": ["dependencies"],
"labels": ["dependencies"],
"minimumReleaseAge": "5 days",
"packageRules": [
{
@@ -16,7 +16,8 @@
{
"groupName": "GitHub Actions",
"matchDepTypes": ["action"],
"pinDigests": true
"pinDigests": true,
"labels": ["PR-Task"]
},
{
"description": "Disable Renovate for packages we want to monitor ourselves",
@@ -69,7 +70,8 @@
"matchUpdateTypes": ["digest"],
"schedule": ["* 0-3 * * *"],
"minimumReleaseAge": null,
"automerge": true
"automerge": true,
"labels": ["PR-Task"]
}
],
"semanticCommits": "disabled",
+16 -14
View File
@@ -20,6 +20,7 @@ import { EMPTY, filter, map, type Observable, of, switchMap, take } from "rxjs";
import {
type Behavior,
createRTCSlot,
createSdkMatrixBackend,
E2eeType,
type LocalRTCMember,
ObservableScope,
@@ -36,7 +37,6 @@ import {
import {
captureSettings,
rtcParticipationOptions,
rtcSlotOptions,
} from "../src/room/InCallView";
import { createWidgetHostBridge } from "../src/HostBridge";
import { MediaDevices } from "../src/state/MediaDevices";
@@ -94,10 +94,9 @@ export async function createMatrixRTCSdk(
);
const encryptionSystem = { kind: E2eeType.PER_PARTICIPANT } as const;
const capture = captureSettings();
const slot = createRTCSlot(scope, client, room, {
...rtcSlotOptions(encryptionSystem),
application,
id,
const slot = createRTCSlot(scope, createSdkMatrixBackend(client, room), {
encryptionSystem,
slotDescription: { application, id },
});
let vm: CallViewModel | undefined;
const failed =
@@ -128,20 +127,23 @@ export async function createMatrixRTCSdk(
});
vm = createCallViewModel$(
scope,
participation,
room,
mediaDevices,
muteStates,
{
rtcParticipation: participation,
matrixRoom: room,
client,
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),
encryptionSystem,
capture,
hostBridge,
// The bundle owns its page, so the body is the space it has
windowSize$: scope.behavior(observeElementSize$(document.body)),
},
of({}),
of({}),
);
// Once the hang-up has gone through, unstick and ask the host to close us
vm.leave$
+7 -6
View File
@@ -19,6 +19,7 @@ nothing in Element Call's `src/`.
```ts
import {
createRTCSlot,
createSdkMatrixBackend,
E2eeType,
MatrixRTCMode,
ObservableScope,
@@ -28,15 +29,15 @@ import {
const scope = new ObservableScope();
const slot = createRTCSlot(
scope,
client, // a matrix-js-sdk MatrixClient, logged in and syncing
room, // the matrix-js-sdk Room, from client.getRoom() once the join has synced
{
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
matrixRTCMode: MatrixRTCMode.Compatibility,
},
createSdkMatrixBackend(
client, // a matrix-js-sdk MatrixClient, logged in and syncing
room, // the matrix-js-sdk Room, from client.getRoom() once the join has synced
),
{ encryptionSystem: { kind: E2eeType.PER_PARTICIPANT } }, // the room's call, m.call#ROOM
);
const participation = slot.join({
publish: [{ source: "microphone" }, { source: "camera" }],
matrixRTCMode: MatrixRTCMode.Compatibility,
});
// A <video> for each remote member's camera and an <audio> for its microphone.
+15 -13
View File
@@ -143,18 +143,18 @@ participation split in
[`client-into-slot-session-split-plan.md`](./client-into-slot-session-split-plan.md);
the sections below still describe `MatrixRTCClient` until that lands.
| Word | Meaning here | Elsewhere |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| slot | an `RTCSlot`: the namespace in a room that memberships join into, `application` plus `id`. It exists while the room does, with nobody in it too. Holds `members$`, its open or closed `status$`, and `join()` | the js-sdk `MatrixRTCSession` is one per slot; the MSC4143 slot event |
| participation | an `RTCParticipation`: the span between our `join()` of a slot and our `leave()`. Holds the connection and its `state$`, `localMember$`, `remoteMembers$`, the connected transports and the data channel. Made by `slot.join()`, never reused | "session" is not used here, because in the js-sdk it means the slot |
| member | an `RTCMember`: one membership in a slot with what the SDK derives from it, `rtcBackendIdentity`, `userId`, `deviceId`, `memberId`, `displayName$`, `avatarUrl$`, `transport$` and `applicationData$`. No media. What the slot hands out in `members$` | the js-sdk `CallMembership` behind it, which never leaves the SDK; Element Call's old "matrixLivekitMember" |
| local member, remote member | `LocalRTCMember` and `RemoteRTCMember`: an `RTCMember` plus its `MemberMedia`, which only a participation can carry. The local one's tracks carry the controls. What the participation hands out in `localMember$` and `remoteMembers$` | LiveKit `LocalParticipant` and `RemoteParticipant`, which never leave the SDK |
| media | a `MemberMedia`: what a member sends once it has arrived on its transport, `tracks$`, null while waiting, and `encryptionError$` beside it. The media backend supplies exactly these two fields per member | Element Call's `MediaViewModel` is a view of it |
| track | a `MediaTrack`: one publication of a member, audio or video, with `source`, `kind`, `id` and the behaviors on it. `LocalAudioMediaTrack` and `LocalVideoMediaTrack` add the controls over our own | LiveKit `TrackPublication` and `Track`, which never leave the SDK |
| publish request | a `PublishRequest`: a source, where to capture it from and how to encode it. Given at the join in `publish`, or later to `publish` on the participation | |
| attach, detach | handing a `<video>` or `<audio>` element to a track and taking it back. The SDK owns the stream and the observers on the element | LiveKit `Track.attach` |
| transport | an `RTCTransport`: where media is exchanged, a LiveKit service url today. Carries the raw js-sdk `Transport` from the membership and, in `resolved$`, what the backend fetched to connect to it | MSC4143 "focus" |
| media backend | a `MediaBackend`: what carries the media, behind `sdk/src/media-backend/api.ts`. One per participation, chosen with `backend` in the join options; LiveKit under `sdk/src/media-backend/livekit/` is the one that exists | "SFU", a LiveKit room, a peer connection |
| Word | Meaning here | Elsewhere |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| slot | an `RTCSlot`: the namespace in a room that memberships join into, `application` plus `id`. It exists while the room does, with nobody in it too. Holds `members$`, its open or closed `status$`, and `join()` | the js-sdk `MatrixRTCSession` is one per slot; the MSC4143 slot event |
| participation | an `RTCParticipation`: the span between our `join()` of a slot and our `leave()`. Holds the connection and its `state$`, `localMember$`, `remoteMembers$`, the connected transports and the data channel. Made by `slot.join()`, never reused | "session" is not used here, because in the js-sdk it means the slot |
| member | an `RTCMember`: one membership in a slot with what the SDK derives from it, `rtcBackendIdentity`, `userId`, `deviceId`, `memberId`, `matrixEventId$`, `displayName$`, `avatarUrl$`, `transport$` and `applicationData$`. No media. What the slot hands out in `members$` | the js-sdk `CallMembership` behind it, which never leaves the SDK; Element Call's old "matrixLivekitMember" |
| local member, remote member | `LocalRTCMember` and `RemoteRTCMember`: an `RTCMember` plus its `MemberMedia`, which only a participation can carry. The local one's tracks carry the controls. What the participation hands out in `localMember$` and `remoteMembers$` | LiveKit `LocalParticipant` and `RemoteParticipant`, which never leave the SDK |
| media | a `MemberMedia`: what a member sends once it has arrived on its transport, `tracks$`, null while waiting, and `encryptionError$` beside it. The media backend supplies exactly these two fields per member | Element Call's `MediaViewModel` is a view of it |
| track | a `MediaTrack`: one publication of a member, audio or video, with `source`, `kind`, `id` and the behaviors on it. `LocalAudioMediaTrack` and `LocalVideoMediaTrack` add the controls over our own | LiveKit `TrackPublication` and `Track`, which never leave the SDK |
| publish request | a `PublishRequest`: a source, where to capture it from and how to encode it. Given at the join in `publish`, or later to `publish` on the participation | |
| attach, detach | handing a `<video>` or `<audio>` element to a track and taking it back. The SDK owns the stream and the observers on the element | LiveKit `Track.attach` |
| transport | an `RTCTransport`: where media is exchanged, a LiveKit service url today. Carries the raw js-sdk `Transport` from the membership and, in `resolved$`, what the backend fetched to connect to it | MSC4143 "focus" |
| media backend | a `MediaBackend`: what carries the media, behind `sdk/src/media-backend/api.ts`. One per participation, chosen with `backend` in the join options; LiveKit under `sdk/src/media-backend/livekit/` is the one that exists | "SFU", a LiveKit room, a peer connection |
Names use `RTC` in capitals, as the js-sdk does: `RTCSlot`, `RTCParticipation`,
`RTCMember`, `matrixRTCMode`.
@@ -634,7 +634,9 @@ export type MediaSource =
| "unknown";
export type MediaStreamStats =
RTCInboundRtpStreamStats | RTCOutboundRtpStreamStats | undefined;
| RTCInboundRtpStreamStats
| RTCOutboundRtpStreamStats
| undefined;
/** One published track of a member. */
export interface MediaTrack {
+3 -2
View File
@@ -16,6 +16,7 @@ import { combineLatest, type Observable, of, switchMap } from "rxjs";
import {
type AudioMediaTrack,
createRTCSlot,
createSdkMatrixBackend,
E2eeType,
type LocalRTCMember,
MatrixRTCMode,
@@ -70,12 +71,12 @@ async function start(
const room = await joinRoom(client, roomIdOrAlias);
const scope = new ObservableScope();
const slot = createRTCSlot(scope, client, room, {
const slot = createRTCSlot(scope, createSdkMatrixBackend(client, room), {
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
matrixRTCMode: MatrixRTCMode.Compatibility,
});
const rtcParticipation = slot.join({
publish: [{ source: "microphone" }, { source: "camera" }],
matrixRTCMode: MatrixRTCMode.Compatibility,
});
rtcParticipation.state$.pipe(scope.bind()).subscribe((state) => {
status.textContent =
+5
View File
@@ -57,6 +57,11 @@ export * from "./src/media-api";
export * from "./src/media-backend/api";
export { trackBySource$, type TrackOfSource } from "./src/utils/tracks";
export { createRTCSlot } from "./src/RTCSlot";
export {
createSdkMatrixBackend,
type SdkMatrixBackend,
withEmitter,
} from "./src/SdkMatrixBackend";
export {
createLivekitBackend,
type LivekitBackendOptions,
+10
View File
@@ -152,6 +152,15 @@ describe("createLocalMedia", () => {
});
});
// As the built-in camera of a Mac
it("takes a camera that doesn't say which way it faces to face the user", async () => {
const media = createLocalMedia(fakeGetUserMedia());
const [camera] = (await media.capture([{ source: "camera" }])) as [
LocalVideoMediaTrack,
];
expect(camera.facingMode$.value).toBe("user");
});
it("releases one device and stops the rest", async () => {
const media = createLocalMedia(fakeGetUserMedia());
const [microphone, camera] = await media.capture([
@@ -198,6 +207,7 @@ function fakeTrack(
const track = {
kind,
id: `${kind}-${nextId++}`,
label: "",
enabled: true,
stop: vi.fn(),
getSettings: () => settings,
+4 -15
View File
@@ -19,6 +19,7 @@ import {
type VideoProcessor,
} from "./media-api";
import { constant } from "./reactive/Behavior";
import { facingModeOf } from "./utils/facingMode";
import { inTurn } from "./utils/processorTurns";
type Source = "microphone" | "camera";
@@ -161,9 +162,7 @@ function trackConstraints(request: Request): MediaTrackConstraints {
class CapturedTrack {
public readonly mediaTrack: LocalAudioMediaTrack | LocalVideoMediaTrack;
private readonly muted$ = new BehaviorSubject(false);
private readonly facingMode$: BehaviorSubject<
"user" | "environment" | undefined
>;
private readonly facingMode$: BehaviorSubject<"user" | "environment">;
private readonly elements = new Set<HTMLMediaElement>();
private processor: HandedOverTrack["processor"];
/** What the processor reads frames from; a processor needs a playing element. */
@@ -306,10 +305,9 @@ class CapturedTrack {
kind: "video",
facingMode$: this.facingMode$,
switchFacingMode: async () => {
const facingMode = this.facingMode$.value;
if (facingMode === undefined) return;
await this.reacquire({
facingMode: facingMode === "user" ? "environment" : "user",
facingMode:
this.facingMode$.value === "user" ? "environment" : "user",
});
return this.track.getSettings().deviceId;
},
@@ -325,12 +323,3 @@ function play(element: HTMLMediaElement, track: MediaStreamTrack): void {
const playing = element.play() as Promise<void> | undefined;
playing?.catch(() => undefined);
}
function facingModeOf(
track: MediaStreamTrack,
): "user" | "environment" | undefined {
const { facingMode } = track.getSettings();
return facingMode === "user" || facingMode === "environment"
? facingMode
: undefined;
}
+19 -16
View File
@@ -22,7 +22,6 @@ import {
type ParticipationState,
type RTCMember,
type RTCParticipationOptions,
type RTCSlot,
type TransportMetadata,
} from "./api";
import { defaultSessionTimings, MatrixRTCMode } from "./config";
@@ -86,6 +85,7 @@ function member(
rtcBackendIdentity: overrides.memberId,
backendIdentities: [overrides.memberId],
deviceId: "DEV",
matrixEventId$: constant(`$${overrides.memberId}`),
transport$: constant(metadata(transport)),
applicationData$: constant({}),
displayName$: constant(overrides.userId),
@@ -111,7 +111,6 @@ interface FakeBackend {
function setup(
options: Partial<RTCParticipationOptions> = {},
slotOptions: { matrixRTCMode?: MatrixRTCMode } = {},
{
homeserverTransports = [transport],
memberships = [],
@@ -140,8 +139,8 @@ function setup(
getDeviceId: () => deviceId,
getDomain: () => "example.org",
getSyncState: () => SyncState.Syncing,
_unstable_getRTCTransports: vi.fn().mockResolvedValue(homeserverTransports),
_unstable_getLivekitToken: vi.fn().mockResolvedValue({ jwt: publisherJWT }),
getRTCTransports: vi.fn().mockResolvedValue(homeserverTransports),
getLivekitToken: vi.fn().mockResolvedValue({ jwt: publisherJWT }),
} as unknown as MatrixClient;
const members$ = new BehaviorSubject<RTCMember[]>([]);
@@ -191,19 +190,24 @@ function setup(
scope,
{
client,
room,
slot: {} as RTCSlot,
jsSdkSession: mockedSession,
members$: scope.behavior(members$),
transports: { get: metadata, connected$: constant([]) },
slotOptions: {
matrixRTCMode: MatrixRTCMode.Compatibility,
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
...slotOptions,
slot: {
roomId: room.roomId,
application: "m.call",
id: "ROOM",
status$: constant(undefined),
members$: scope.behavior(members$),
},
jsSdkSession: mockedSession,
transports: { get: metadata, connected$: constant([]) },
slotOptions: { encryptionSystem: { kind: E2eeType.PER_PARTICIPANT } },
logger,
},
{ publish: [], backend: backendFactory, ...options },
{
publish: [],
matrixRTCMode: MatrixRTCMode.Compatibility,
backend: backendFactory,
...options,
},
);
const states: ParticipationState[] = [];
participation.state$.subscribe((state) => states.push(state));
@@ -254,7 +258,6 @@ describe("createRTCParticipation", () => {
fociPreferred: [{ type: "livekit", url: "wss://sfu.example.org" }],
});
const { join, fake } = setup(
{},
{},
{ homeserverTransports: [], memberships: [bobOnSfu] },
);
@@ -349,7 +352,7 @@ describe("createRTCParticipation", () => {
});
compatibility.scope.end();
const matrix2 = setup({}, { matrixRTCMode: MatrixRTCMode.Matrix_2_0 });
const matrix2 = setup({ matrixRTCMode: MatrixRTCMode.Matrix_2_0 });
const { memberId } = matrix2.fake.context.ownMembershipIdentity;
expect(memberId).not.toBe(legacyMemberId);
expect(memberId).toMatch(/^[0-9a-f-]{36}$/);
+53 -33
View File
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type MatrixClient, type Room } from "matrix-js-sdk";
import { type MatrixClient } from "matrix-js-sdk";
import { type Logger } from "matrix-js-sdk/lib/logger";
import {
type MatrixRTCSession as JsSdkRTCSession,
@@ -30,19 +30,17 @@ import {
import { defaultSessionTimings, MatrixRTCMode } from "./config";
import { E2eeType } from "./encryption";
import { type Behavior } from "./reactive/Behavior";
import { type ObservableScope } from "./reactive/ObservableScope";
import { generateItems } from "./reactive/observable";
import { mapScoped } from "./utils/mapScoped";
import {
type ParticipationSlot,
type DataMessage,
type LocalRTCMember,
type ParticipationState,
type RemoteRTCMember,
type RTCMember,
type RTCParticipation,
type RTCParticipationOptions,
type RTCSlot,
type RTCSlotOptions,
} from "./api";
import {
@@ -67,15 +65,34 @@ import { createKeyRotationSuppressed$ } from "./matrixrtc/JsRtcSessionBehaviors"
import { type TransportRegistry } from "./matrixrtc/Transports";
import { participationState } from "./participationState";
/** What the slot lends a participation. */
/** What is needed for our own participation. */
export interface ParticipationDeps {
client: MatrixClient;
room: Room;
slot: RTCSlot;
client: Pick<
MatrixClient,
// Our own membership identity
| "getUserId"
| "getDeviceId"
// Local transport discovery
| "getDomain"
| "getRTCTransports"
// LiveKit auth: `getOpenIdToken` for the JWT service flow, `getLivekitToken`
// for the client-server API flow (MSC4195), `delegateDelayedLeave` and
// `baseUrl` for the delayed leave delegation and its probe
| "getOpenIdToken"
| "getLivekitToken"
| "delegateDelayedLeave"
| "baseUrl"
// Homeserver connection: whether the client is syncing
| "getSyncState"
// `on`/`off`, to listen for:
// - `ClientEvent.Sync` (homeserver connection)
| "on"
| "off"
>;
slot: ParticipationSlot;
jsSdkSession: JsSdkRTCSession;
members$: Behavior<RTCMember[]>;
transports: TransportRegistry;
slotOptions: Pick<RTCSlotOptions, "matrixRTCMode" | "encryptionSystem">;
slotOptions: RTCSlotOptions;
logger: Logger;
}
@@ -94,16 +111,19 @@ export function createRTCParticipation(
scope: ObservableScope,
{
client,
room,
slot,
jsSdkSession,
members$,
transports,
slotOptions: { matrixRTCMode, encryptionSystem },
slotOptions: { encryptionSystem },
logger: parentLogger,
}: ParticipationDeps,
options: RTCParticipationOptions,
): ParticipationInternals {
const { matrixRTCMode } = options;
const { roomId, members$ } = slot;
// The full `{application}#{id}`, which the auth service and the other
// members key the media room on
const slotId = jsSdkSession.slotId;
const logger = parentLogger.getChild("[RTCParticipation]");
const userId = client.getUserId()!;
const deviceId = client.getDeviceId()!;
@@ -122,8 +142,8 @@ export function createRTCParticipation(
};
const backend = createBackend(scope, client, options, {
roomId: room.roomId,
slotId: jsSdkSession.slotId,
roomId,
slotId,
ownMembershipIdentity,
publish: options.publish,
encryptionSystem,
@@ -144,8 +164,8 @@ export function createRTCParticipation(
// to come back later rather than wait in a half-working lobby
memberships: jsSdkSession.memberships,
ownMembershipIdentity,
roomId: room.roomId,
slotId: jsSdkSession.slotId,
roomId,
slotId,
logger,
})
: null;
@@ -175,21 +195,15 @@ export function createRTCParticipation(
timings.syncDisconnectGracePeriodMs,
),
joinMatrixRTC: (transport, delayedLeave) =>
joinJsSdkSession(
room.roomId,
jsSdkSession,
ownMembershipIdentity,
transport,
{
encryptMedia: encryptionSystem.kind !== E2eeType.NONE,
matrixRTCMode,
sendNotificationType: options.sendNotificationType,
callIntent: options.callIntent,
applicationData: options.applicationData,
timings,
delayedLeave,
},
),
joinJsSdkSession(roomId, jsSdkSession, ownMembershipIdentity, transport, {
encryptMedia: encryptionSystem.kind !== E2eeType.NONE,
matrixRTCMode,
sendNotificationType: options.sendNotificationType,
callIntent: options.callIntent,
applicationData: options.applicationData,
timings,
delayedLeave,
}),
membershipManagerError$: fromEvent(
jsSdkSession,
MatrixRTCSessionEvent.MembershipManagerError,
@@ -315,7 +329,13 @@ export function createRTCParticipation(
/** The host's backend, or LiveKit configured from the participation options. */
function createBackend(
scope: ObservableScope,
client: MatrixClient,
client: Pick<
MatrixClient,
// LiveKit auth: `getOpenIdToken` for the JWT service flow, `getLivekitToken`
// for the client-server API flow (MSC4195), `delegateDelayedLeave` and
// `baseUrl` for the delayed leave delegation and its probe
"getOpenIdToken" | "getLivekitToken" | "delegateDelayedLeave" | "baseUrl"
>,
{ backend, mediaQuality }: RTCParticipationOptions,
context: MediaBackendContext,
): MediaBackend {
+132 -8
View File
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { type MatrixClient, type Room } from "matrix-js-sdk";
import { EventType } from "matrix-js-sdk/lib/@types/event";
import { type MatrixEvent } from "matrix-js-sdk/lib/models/event";
@@ -13,15 +13,26 @@ import {
type RoomState,
RoomStateEvent,
} from "matrix-js-sdk/lib/models/room-state";
import { RoomStickyEventsEvent } from "matrix-js-sdk/lib/models/room-sticky-events";
import {
MatrixRTCSessionEvent,
type MatrixRTCSessionEventHandlerMap,
} from "matrix-js-sdk/lib/matrixrtc";
import { createRTCSlot } from "./RTCSlot";
import { type SdkMatrixBackend } from "./SdkMatrixBackend";
import { ObservableScope } from "./reactive/ObservableScope";
import { type RTCSlotOptions } from "./api";
import { MatrixRTCMode } from "./config";
import { E2eeType } from "./encryption";
import { mockEmitter, MockRTCSession, testScope } from "./utils/test";
import {
mockEmitter,
mockRtcMembership,
MockRTCSession,
testScope,
} from "./utils/test";
const options: RTCSlotOptions = {
matrixRTCMode: MatrixRTCMode.Compatibility,
encryptionSystem: { kind: E2eeType.NONE },
};
@@ -34,28 +45,117 @@ function setup(): {
...mockEmitter(),
roomId: "!room:example.org",
getMembersWithMembership: (): [] => [],
// An empty room, for a session of the slot's own
getLiveTimeline: () => ({ getState: (): undefined => undefined }),
hasMembershipState: (): boolean => false,
getVersion: (): string => "11",
_unstable_getStickyEvents: (): [] => [],
} as unknown as Room;
const session = new MockRTCSession(room);
const client = {
...mockEmitter(),
getUserId: (): string => "@alice:example.org",
getDeviceId: (): string => "AAAA",
matrixRTC: { getRoomSession: (): MockRTCSession => session },
} as unknown as MatrixClient;
return { client, room, session };
}
function backendOf(client: MatrixClient, room: Room): SdkMatrixBackend {
return {
...client,
...room,
clientEmitter: client,
roomEmitter: room,
} as unknown as SdkMatrixBackend;
}
describe("createRTCSlot", () => {
describe("session", () => {
it("joins the room's call slot by default", () => {
const { client, room } = setup();
const slot = createRTCSlot(testScope(), backendOf(client, room), options);
expect(slot).toMatchObject({ application: "m.call", id: "ROOM" });
});
it("joins the slot the options name", () => {
const { client, room } = setup();
const slot = createRTCSlot(testScope(), backendOf(client, room), {
...options,
slotDescription: { application: "io.element.example", id: "" },
});
expect(slot).toMatchObject({ application: "io.element.example", id: "" });
});
it("stops its own session when the scope ends", async () => {
const { client, room } = setup();
const off = vi.spyOn(room, "off");
const scope = new ObservableScope();
createRTCSlot(scope, backendOf(client, room), options);
scope.end();
await vi.waitFor(() =>
expect(off).toHaveBeenCalledWith(
RoomStickyEventsEvent.Update,
expect.any(Function),
),
);
});
it("leaves a session it is given to its caller", () => {
const { client, room, session } = setup();
const given = session.asMockedSession();
given.stop = vi.fn();
const scope = new ObservableScope();
createRTCSlot(scope, backendOf(client, room), options, given);
scope.end();
expect(given.stop).not.toHaveBeenCalled();
});
it("has the session's statistics and sent call notifications", () => {
const { client, room, session } = setup();
const slot = createRTCSlot(
testScope(),
backendOf(client, room),
options,
session.asMockedSession(),
);
expect(slot.statistics).toBe(session.statistics);
const sent: unknown[] = [];
slot.sentCallNotification$.subscribe((n) => sent.push(n));
const notification = { event_id: "$notification" };
session.emit(
MatrixRTCSessionEvent.DidSendCallNotification,
notification as Parameters<
MatrixRTCSessionEventHandlerMap[MatrixRTCSessionEvent.DidSendCallNotification]
>[0],
);
expect(sent).toEqual([notification]);
});
});
describe("status$", () => {
it("is undefined while the room has no slot event", () => {
const { client, room } = setup();
const slot = createRTCSlot(testScope(), client, room, options);
const { client, room, session } = setup();
const slot = createRTCSlot(
testScope(),
backendOf(client, room),
options,
session.asMockedSession(),
);
expect(slot.status$.value).toBeUndefined();
});
it("follows the slot event", () => {
const { client, room, session } = setup();
session.rtcSlot = { status: "open" };
const slot = createRTCSlot(testScope(), client, room, options);
const slot = createRTCSlot(
testScope(),
backendOf(client, room),
options,
session.asMockedSession(),
);
expect(slot.status$.value).toBe("open");
session.rtcSlot = { status: "closed" };
@@ -68,4 +168,28 @@ describe("createRTCSlot", () => {
expect(slot.status$.value).toBe("closed");
});
});
describe("members$", () => {
it("keeps the member when its membership is sent again, with the new event id", () => {
const { client, room, session } = setup();
const first = mockRtcMembership("@bob:example.org", "BOB");
session.memberships = [first];
const slot = createRTCSlot(
testScope(),
backendOf(client, room),
options,
session.asMockedSession(),
);
const [bob] = slot.members$.value;
expect(bob.matrixEventId$.value).toBe(first.eventId);
const resent = mockRtcMembership("@bob:example.org", "BOB");
session.memberships = [resent];
session.emit(MatrixRTCSessionEvent.MembershipsChanged, [first], [resent]);
expect(slot.members$.value).toHaveLength(1);
expect(slot.members$.value[0]).toBe(bob);
expect(bob.matrixEventId$.value).toBe(resent.eventId);
expect(resent.eventId).not.toBe(first.eventId);
});
});
});
+124 -74
View File
@@ -5,12 +5,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type MatrixClient, type Room } from "matrix-js-sdk";
import { type MatrixClient } from "matrix-js-sdk";
import { EventType } from "matrix-js-sdk/lib/@types/event";
import { type Logger, logger as rootLogger } from "matrix-js-sdk/lib/logger";
import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
import {
type MatrixRTCSession as JsSdkRTCSession,
MatrixRTCSessionManager,
type Statistics,
MatrixRTCSession as JsMatrixRTCSession,
MatrixRTCSessionEvent,
type IRTCNotificationContent,
type SlotDescription,
} from "matrix-js-sdk/lib/matrixrtc";
import { type MatrixEvent } from "matrix-js-sdk/lib/models/event";
@@ -20,6 +22,7 @@ import {
filter,
fromEvent,
map,
type Observable,
of,
startWith,
switchMap,
@@ -28,6 +31,7 @@ import {
import { ObservableScope } from "./reactive/ObservableScope";
import { generateItems } from "./reactive/observable";
import {
type ParticipationSlot,
type RTCMember,
type RTCParticipation,
type RTCParticipationOptions,
@@ -50,33 +54,64 @@ import {
membershipKeys,
} from "./matrixrtc/Members";
import { createTransportRegistry } from "./matrixrtc/Transports";
import {
type createSdkMatrixBackend,
type SdkMatrixBackend,
withEmitter,
} from "./SdkMatrixBackend";
const ROOM_CALL_SLOT: SlotDescription = { application: "m.call", id: "ROOM" };
/**
* Takes the whole `MatrixClient` rather than a slice of it, and finds the
* MatrixRTC session itself. The js-sdk is the MatrixRTC implementation today;
* when the rust-rtc crate replaces it, the SDK has to bridge the crate to the
* js-sdk client, and only the SDK knows what that bridge needs. Holding the
* client keeps that change inside the SDK.
* The slot runs on a matrix-js-sdk session of its own, from the SDK's copy of
* matrix-js-sdk rather than the client's, and stops it when the scope ends.
*/
export function createRTCSlot(
scope: ObservableScope,
client: MatrixClient,
room: Room,
backend: SdkMatrixBackend,
options: RTCSlotOptions,
): RTCSlot {
/**
* @deprecated A session the caller owns and stops, in place of the slot's
* own; `options.slotDescription` is then the session's. Only for the
* standalone app, which still takes its session from its client's session
* manager.
*/
externalJsSdkSession?: JsMatrixRTCSession,
): RTCSlot & {
// STOP GAP: This should be its own external machine. It is call
// specific and should not live inside the sdk/rtc-slot.
// We only put it here today, to make sure the rtcSession is fully
// hidden inside the sdk.
// Next step. disable sending call notificaitons in the sdk, write a new
// notification sender in EC directly on client + room.
sentCallNotification$: Observable<
{
event_id: string;
} & IRTCNotificationContent
>;
// STOP GAP: the same as above. Has to live here. but should become a native
// SDK propery independent of the rtcSession
statistics: Statistics;
} {
// STOP GAP: the slot is still written against a client and a room. Both
// are refactored along with the backend.
const client = withEmitter(backend, backend.clientEmitter);
const room = withEmitter(backend, backend.roomEmitter);
const logger = rootLogger.getChild("[RTCSlot]");
const userId = client.getUserId();
const deviceId = client.getDeviceId();
const roomId = room.roomId;
if (!(userId && deviceId))
throw new MatrixRTCError("The client has to be logged in");
const { application = "m.call", id = "ROOM" } = options;
const jsSdkSession = sessionManager(
scope,
client,
{ application, id },
logger,
).getRoomSession(room);
const jsSdkSession =
externalJsSdkSession ??
createJsSdkSession(
scope,
client,
room,
options.slotDescription ?? ROOM_CALL_SLOT,
);
const memberships$ = createMemberships$(scope, jsSdkSession);
const active$ = new BehaviorSubject<ParticipationInternals | null>(null);
@@ -126,70 +161,85 @@ export function createRTCSlot(
),
);
const slot: RTCSlot = {
roomId: room.roomId,
application,
id,
const participationSlot: ParticipationSlot = {
roomId,
status$,
members$,
...jsSdkSession.slotDescription,
};
const join = (
participationOptions: RTCParticipationOptions,
): RTCParticipation => {
if (active$.value !== null)
throw new MatrixRTCError(
"Already in this slot: leave the participation before joining again",
);
const participationScope = new ObservableScope();
participationScopes.add(participationScope);
const internals = createRTCParticipation(
participationScope,
{
client,
slot: participationSlot,
jsSdkSession,
transports,
slotOptions: options,
logger,
},
participationOptions,
);
participationScope.onEnd(() => {
participationScopes.delete(participationScope);
if (active$.value === internals) active$.next(null);
});
active$.next(internals);
return internals.participation;
};
const slot = {
join,
participation$: scope.behavior(
active$.pipe(map((active) => active?.participation ?? null)),
),
join: (participationOptions: RTCParticipationOptions): RTCParticipation => {
if (active$.value !== null)
throw new MatrixRTCError(
"Already in this slot: leave the participation before joining again",
);
const participationScope = new ObservableScope();
participationScopes.add(participationScope);
const internals = createRTCParticipation(
participationScope,
{
client,
room,
slot,
jsSdkSession,
members$,
transports,
slotOptions: options,
logger,
},
participationOptions,
);
participationScope.onEnd(() => {
participationScopes.delete(participationScope);
if (active$.value === internals) active$.next(null);
});
active$.next(internals);
return internals.participation;
},
...participationSlot,
};
return slot;
return {
...slot,
sentCallNotification$: fromEvent(
jsSdkSession,
MatrixRTCSessionEvent.DidSendCallNotification,
(notification: { event_id: string } & IRTCNotificationContent) =>
notification,
),
statistics: jsSdkSession.statistics,
};
}
function createJsSdkSession(
scope: ObservableScope,
client: Pick<
MatrixClient,
keyof Parameters<typeof createSdkMatrixBackend>[0]
>,
room: ConstructorParameters<typeof JsMatrixRTCSession>[1],
slotDescription: SlotDescription,
): JsMatrixRTCSession {
const session = new JsMatrixRTCSession(
// The session's type also asks for `cancelPendingEvent`,
// `_unstable_updateDelayedEvent` and `decryptEventIfNeeded`, which it
// never calls
client as ConstructorParameters<typeof JsMatrixRTCSession>[0],
room,
slotDescription,
);
scope.onEnd(() => void session.stop());
return session;
}
function slotStatus(
session: Pick<JsSdkRTCSession, "getRtcSlot">,
session: Pick<JsMatrixRTCSession, "getRtcSlot">,
): "open" | "closed" | undefined {
return session.getRtcSlot()?.status;
}
/**
* The js-sdk keeps one session manager per slot. The client comes with the
* manager for the default slot; any other slot gets a manager of its own,
* which lives as long as the scope.
*/
function sessionManager(
scope: ObservableScope,
client: MatrixClient,
{ application, id }: SlotDescription,
logger: Logger,
): MatrixRTCSessionManager {
if (application === "m.call" && id === "ROOM") return client.matrixRTC;
const manager = new MatrixRTCSessionManager(logger, client, {
application,
id,
});
manager.start();
scope.onEnd(() => manager.stop());
return manager;
}
+85
View File
@@ -0,0 +1,85 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { describe, expect, it, vi } from "vitest";
import {
ClientEvent,
createClient,
type MatrixClient,
Room,
RoomEvent,
SyncState,
} from "matrix-js-sdk";
import { createSdkMatrixBackend, withEmitter } from "./SdkMatrixBackend";
describe("createSdkMatrixBackend", () => {
it("calls each member on the client or the room it came from", () => {
const { client, room } = setup();
const backend = createSdkMatrixBackend(client, room);
expect(backend.getUserId()).toBe("@alice:example.org");
expect(backend.roomId).toBe("!room:example.org");
expect(backend.getVersion()).toBe(room.getVersion());
});
it("keeps the client's and the room's events apart", () => {
const { client, room } = setup();
const backend = createSdkMatrixBackend(client, room);
const onClient = vi.fn();
const onRoom = vi.fn();
backend.clientEmitter.on(ClientEvent.Sync, onClient);
backend.roomEmitter.on(RoomEvent.Name, onRoom);
client.emit(ClientEvent.Sync, SyncState.Syncing, null);
expect(onClient).toHaveBeenCalledOnce();
expect(onRoom).not.toHaveBeenCalled();
room.emit(RoomEvent.Name, room);
expect(onRoom).toHaveBeenCalledOnce();
});
});
describe("withEmitter", () => {
it("is the backend with one side's events", () => {
const { client, room } = setup();
const backend = createSdkMatrixBackend(client, room);
const asRoom = withEmitter(backend, backend.roomEmitter);
const listener = vi.fn();
asRoom.on(RoomEvent.Name, listener);
room.emit(RoomEvent.Name, room);
expect(listener).toHaveBeenCalledOnce();
expect(asRoom.getUserId()).toBe("@alice:example.org");
});
it("reads the backend's getters through", () => {
const { room } = setup();
const asRoom = withEmitter(
{
get name() {
return room.name;
},
},
room,
);
room.name = "Renamed";
expect(asRoom.name).toBe("Renamed");
});
});
function setup(): { client: MatrixClient; room: Room } {
const client = createClient({
baseUrl: "https://matrix.example.org",
userId: "@alice:example.org",
deviceId: "DEVICE",
});
const room = new Room("!room:example.org", client, "@alice:example.org");
return { client, room };
}
+129
View File
@@ -0,0 +1,129 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type MatrixClient, type Room } from "matrix-js-sdk";
/** What the SDK needs of the client. */
type SdkClientPart = Pick<
MatrixClient,
// Our own membership identity
| "getUserId"
| "getDeviceId"
// The session: memberships, delayed leave events, sticky events, call
// notifications, and the media keys sent to device
| "fetchCapabilities"
| "getCachedCapabilities"
| "sendEvent"
| "sendStateEvent"
| "_unstable_sendDelayedStateEvent"
| "_unstable_cancelScheduledDelayedEvent"
| "_unstable_restartScheduledDelayedEvent"
| "_unstable_sendScheduledDelayedEvent"
| "_unstable_sendStickyEvent"
| "_unstable_sendStickyDelayedEvent"
| "encryptAndSendToDevice"
// Local transport discovery
| "getDomain"
| "getRTCTransports"
// LiveKit auth: `getOpenIdToken` for the JWT service flow, `getLivekitToken`
// for the client-server API flow (MSC4195), `delegateDelayedLeave` and
// `baseUrl` for the delayed leave delegation and its probe
| "getOpenIdToken"
| "getLivekitToken"
| "delegateDelayedLeave"
| "baseUrl"
// Homeserver connection: whether the client is syncing
| "getSyncState"
>;
/** What the SDK needs of the room. */
type SdkRoomPart = Pick<
Room,
| "roomId"
// The members' display names and avatars
| "getMembersWithMembership"
// The session: memberships from the room's state, timeline and sticky events
| "getLiveTimeline"
| "getVersion"
| "hasMembershipState"
| "_unstable_getStickyEvents"
>;
/**
* STOP GAP: what the SDK needs of a Matrix client and room, on one object.
* Only their emitters stay apart, since both have an `on` and an `off`. It is
* to converge, along with the SDK that takes it, on whichever API fits every
* layer best.
*/
export interface SdkMatrixBackend extends SdkClientPart, SdkRoomPart {
/**
* `ClientEvent.Sync` (homeserver connection) and `ClientEvent.ToDeviceEvent`
* (the session's media keys)
*/
clientEmitter: Pick<MatrixClient, "on" | "off">;
/** The room's state, member and sticky events */
roomEmitter: Pick<Room, "on" | "off">;
}
/** The SDK's backend from a client and a room. */
export function createSdkMatrixBackend(
client: SdkClientPart & Pick<MatrixClient, "on" | "off">,
room: SdkRoomPart & Pick<Room, "on" | "off">,
): SdkMatrixBackend {
return {
getUserId: client.getUserId.bind(client),
getDeviceId: client.getDeviceId.bind(client),
fetchCapabilities: client.fetchCapabilities.bind(client),
getCachedCapabilities: client.getCachedCapabilities.bind(client),
sendEvent: client.sendEvent.bind(client),
sendStateEvent: client.sendStateEvent.bind(client),
_unstable_sendDelayedStateEvent:
client._unstable_sendDelayedStateEvent.bind(client),
_unstable_cancelScheduledDelayedEvent:
client._unstable_cancelScheduledDelayedEvent.bind(client),
_unstable_restartScheduledDelayedEvent:
client._unstable_restartScheduledDelayedEvent.bind(client),
_unstable_sendScheduledDelayedEvent:
client._unstable_sendScheduledDelayedEvent.bind(client),
_unstable_sendStickyEvent: client._unstable_sendStickyEvent.bind(client),
_unstable_sendStickyDelayedEvent:
client._unstable_sendStickyDelayedEvent.bind(client),
encryptAndSendToDevice: client.encryptAndSendToDevice.bind(client),
getDomain: client.getDomain.bind(client),
getRTCTransports: client.getRTCTransports.bind(client),
getOpenIdToken: client.getOpenIdToken.bind(client),
getLivekitToken: client.getLivekitToken.bind(client),
delegateDelayedLeave: client.delegateDelayedLeave.bind(client),
baseUrl: client.baseUrl,
getSyncState: client.getSyncState.bind(client),
roomId: room.roomId,
getMembersWithMembership: room.getMembersWithMembership.bind(room),
getLiveTimeline: room.getLiveTimeline.bind(room),
getVersion: room.getVersion.bind(room),
hasMembershipState: room.hasMembershipState.bind(room),
_unstable_getStickyEvents: room._unstable_getStickyEvents.bind(room),
clientEmitter: client,
roomEmitter: room,
};
}
/**
* STOP GAP: the backend as the client (or the room) code written against one
* still expects, with that side's `on` and `off`.
*/
export function withEmitter<
Backend extends object,
Emitter extends {
on: (...args: never[]) => unknown;
off: (...args: never[]) => unknown;
},
>(backend: Backend, emitter: Emitter): Backend & Pick<Emitter, "on" | "off"> {
return Object.defineProperties<object>(
{ on: emitter.on.bind(emitter), off: emitter.off.bind(emitter) },
Object.getOwnPropertyDescriptors(backend),
) as Backend & Pick<Emitter, "on" | "off">;
}
+23 -7
View File
@@ -14,6 +14,7 @@ Please see LICENSE in the repository root for full details.
import {
type RTCCallIntent,
type RTCNotificationType,
type SlotDescription,
type Transport,
} from "matrix-js-sdk/lib/matrixrtc";
import { type Observable } from "rxjs";
@@ -43,13 +44,9 @@ export { MatrixRTCError } from "./errors";
// Slot
export interface RTCSlotOptions {
/** The application the slot belongs to, as named in the membership. Default `m.call`. */
application?: string;
/** The application's slot in the room. Default `ROOM`. */
id?: string;
/** How memberships and keys in this slot are written. Resolved by the host. */
matrixRTCMode: MatrixRTCMode;
encryptionSystem: EncryptionSystem;
/** Which slot of the room to join. Defaults to the room's call, `m.call#ROOM`. */
slotDescription?: SlotDescription;
}
/**
@@ -81,6 +78,12 @@ export interface RTCSlot {
join(options: RTCParticipationOptions): RTCParticipation; // Maybe MediaSession,
}
/**
* The slot as its participation sees it: members, status and identity, without
* `join` and `participation$`, which belong to whoever joins.
*/
export type ParticipationSlot = Omit<RTCSlot, "join" | "participation$">;
// ---------------------------------------------------------------------------
// Participation
@@ -95,6 +98,12 @@ export interface RTCParticipationOptions {
* before the first connection exists.
*/
publish: PublishRequest[] | LocalMedia;
/**
* How our membership and keys are written: the member id and whether the
* membership is a sticky event. Resolved by the host. Others' memberships
* are read whatever their mode.
*/
matrixRTCMode: MatrixRTCMode;
/**
* LEGACY
*
@@ -166,7 +175,8 @@ export type ParticipationState =
/** The span between our `join()` of a slot and our `leave()`. */
export interface RTCParticipation {
readonly slot: RTCSlot;
/** Required slot information (no `join` fn and `participation`) */
readonly slot: ParticipationSlot;
/** Sends the leave, tears the connections down and ends the participation. */
leave(): void;
state$: Behavior<ParticipationState>;
@@ -289,6 +299,12 @@ export interface RTCMember {
deviceId: string;
/** The membership's own id; what the Matrix 2.0 identity is derived from. */
memberId: string;
/**
* The Matrix event currently carrying the membership, which events about
* it (reactions, raised hands) relate to. Changes when the membership is
* sent again while the member stays the same.
*/
matrixEventId$: Behavior<string>;
/** Which transport this member is on; undefined when the membership has none. */
transport$: Behavior<TransportMetadata | undefined>;
/** What the member's application says about itself, e.g. `intent`. */
+69 -21
View File
@@ -8,7 +8,7 @@ Please see LICENSE in the repository root for full details.
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { EventEmitter } from "events";
import { ClientEvent, SyncState } from "matrix-js-sdk";
import { ClientEvent, type MatrixClient, SyncState } from "matrix-js-sdk";
import { MembershipManagerEvent, Status } from "matrix-js-sdk/lib/matrixrtc";
import { ObservableScope } from "../reactive/ObservableScope";
@@ -20,7 +20,7 @@ import { testScope, withTestScheduler } from "../utils/test";
```
createHomeserverConnected$(
scope: ObservableScope,
client: NodeStyleEventEmitter & Pick<MatrixClient, "getSyncState">,
client: Pick<MatrixClient, "getSyncState" | "on" | "off">,
matrixRTCSession: NodeStyleEventEmitter &
Pick<MatrixRTCSession, "membershipStatus" | "probablyLeft">,
)
@@ -34,12 +34,15 @@ class MockMatrixClient extends EventEmitter {
}
public setSyncState(state: SyncState): void {
this.syncState = state;
// Matrix's Sync event in createHomeserverConnected$ expects [SyncState]
this.emit(ClientEvent.Sync, [state]);
this.emit(ClientEvent.Sync, state);
}
public getSyncState(): SyncState {
return this.syncState;
}
/** `MatrixClient`'s `on`/`off` return the client itself, which no mock is. */
public get asClient(): Pick<MatrixClient, "getSyncState" | "on" | "off"> {
return this as unknown as Pick<MatrixClient, "getSyncState" | "on" | "off">;
}
}
/**
@@ -47,7 +50,7 @@ class MockMatrixClient extends EventEmitter {
```
createHomeserverConnected$(
scope: ObservableScope,
client: NodeStyleEventEmitter & Pick<MatrixClient, "getSyncState">,
client: Pick<MatrixClient, "getSyncState" | "on" | "off">,
matrixRTCSession: NodeStyleEventEmitter &
Pick<MatrixRTCSession, "membershipStatus" | "probablyLeft">,
)
@@ -99,18 +102,33 @@ describe("createHomeserverConnected$", () => {
// easy enough to read them so I think they can stay.
// Note: gracePeriodMs is set to 0 to avoid debouncing delays in tests
it("reports syncing reason when sync state is not Syncing", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
expect(hsConnected.disconnectReason$.value).toEqual("sync");
});
it("reports membership reason when sync is Syncing but membership is not Connected", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
client.setSyncState(SyncState.Syncing);
expect(hsConnected.disconnectReason$.value).toEqual("membership");
});
it("reports probablyLeft reason when membership transitions to Connected but ProbablyLeft is true", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
// Make sync loop OK
client.setSyncState(SyncState.Syncing);
// Indicate probable leave before connection
@@ -120,7 +138,12 @@ describe("createHomeserverConnected$", () => {
});
it("becomes null (connected) only when all three conditions are satisfied", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
// 1. Sync loop connected
client.setSyncState(SyncState.Syncing);
expect(hsConnected.disconnectReason$.value).toEqual("membership"); // not yet membership connected
@@ -130,7 +153,12 @@ describe("createHomeserverConnected$", () => {
});
it("returns syncing reason when sync loop leaves Syncing", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
// Reach connected state
client.setSyncState(SyncState.Syncing);
session.setMembershipStatus(Status.Connected);
@@ -142,7 +170,12 @@ describe("createHomeserverConnected$", () => {
});
it("returns membershipConnected reason when membership status becomes disconnected", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
client.setSyncState(SyncState.Syncing);
session.setMembershipStatus(Status.Connected);
expect(hsConnected.disconnectReason$.value).toEqual(null);
@@ -152,7 +185,12 @@ describe("createHomeserverConnected$", () => {
});
it("returns certainlyConnected reason when ProbablyLeft is emitted", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
client.setSyncState(SyncState.Syncing);
session.setMembershipStatus(Status.Connected);
expect(hsConnected.disconnectReason$.value).toEqual(null);
@@ -162,7 +200,12 @@ describe("createHomeserverConnected$", () => {
});
it("recovers to null (connected) if ProbablyLeft becomes false again while other conditions remain true", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
client.setSyncState(SyncState.Syncing);
session.setMembershipStatus(Status.Connected);
expect(hsConnected.disconnectReason$.value).toEqual(null);
@@ -176,7 +219,12 @@ describe("createHomeserverConnected$", () => {
});
it("composite sequence reflects each individual failure reason", () => {
const hsConnected = createHomeserverConnected$(scope, client, session, 0);
const hsConnected = createHomeserverConnected$(
scope,
client.asClient,
session,
0,
);
// Initially: sync error + membership disconnected → syncing wins (highest priority)
expect(hsConnected.disconnectReason$.value).toEqual("sync");
@@ -225,7 +273,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("is null when all three conditions are satisfied", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -237,7 +285,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("reports syncing when sync loop is not Syncing", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -248,7 +296,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("reports membershipConnected when sync is fine but membership is not Connected", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -260,7 +308,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("reports certainlyConnected when probablyLeft is true", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -273,7 +321,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("prioritises syncing over membershipConnected when both fail", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -284,7 +332,7 @@ describe("createHomeserverConnected$ - disconnectReason$ reason values", () => {
it("updates reason as conditions change", () => {
const { disconnectReason$ } = createHomeserverConnected$(
scope,
client,
client.asClient,
session,
0,
);
@@ -329,7 +377,7 @@ describe("createHomeserverConnected$ - Grace Period", () => {
});
const hsConnected = createHomeserverConnected$(
testScope(),
client,
client.asClient,
session,
GRACE_PERIOD,
);
+15 -6
View File
@@ -17,7 +17,6 @@ import {
startWith,
map,
tap,
type Observable,
distinctUntilChanged,
switchMap,
of,
@@ -61,7 +60,15 @@ export interface HomeserverConnected {
*/
export function createHomeserverConnected$(
scope: ObservableScope,
client: NodeStyleEventEmitter & Pick<MatrixClient, "getSyncState">,
client: Pick<
MatrixClient,
// Whether the client is syncing
| "getSyncState"
// `on`/`off`, to listen for:
// - `ClientEvent.Sync`
| "on"
| "off"
>,
matrixRTCSession: NodeStyleEventEmitter &
Pick<MatrixRTCSession, "membershipStatus" | "probablyLeft">,
gracePeriodMs?: number,
@@ -71,11 +78,13 @@ export function createHomeserverConnected$(
const graceMs =
gracePeriodMs ?? defaultSessionTimings.syncDisconnectGracePeriodMs;
const syncing$ = (
fromEvent(client, ClientEvent.Sync) as Observable<[SyncState]>
const syncing$ = fromEvent(
client,
ClientEvent.Sync,
(state: SyncState) => state,
).pipe(
startWith([client.getSyncState()]),
map(([state]) => state === SyncState.Syncing),
startWith(client.getSyncState()),
map((state) => state === SyncState.Syncing),
distinctUntilChanged(),
switchMap((isSyncing) => {
if (isSyncing || graceMs <= 0) {
+2 -2
View File
@@ -31,7 +31,7 @@ function client(
): Parameters<typeof discoverLocalTransport>[0] {
return {
getDomain: () => "example.org",
_unstable_getRTCTransports: vi.fn().mockResolvedValue(advertised),
getRTCTransports: vi.fn().mockResolvedValue(advertised),
};
}
@@ -54,7 +54,7 @@ describe("discoverLocalTransport", () => {
logger,
),
).resolves.toBe(hostTransport);
expect(c._unstable_getRTCTransports).not.toHaveBeenCalled();
expect(c.getRTCTransports).not.toHaveBeenCalled();
});
it("prefers the homeserver's transport over the host's fallback", async () => {
+1 -1
View File
@@ -22,7 +22,7 @@ import { TransportAutoDiscovery } from "./TransportAutoDiscovery";
* @throws {MatrixRTCTransportMissingError} where none of these exists.
*/
export async function discoverLocalTransport(
client: Pick<MatrixClient, "getDomain" | "_unstable_getRTCTransports">,
client: Pick<MatrixClient, "getDomain" | "getRTCTransports">,
transportTypes: readonly string[],
{
transport: override,
+5 -2
View File
@@ -23,7 +23,9 @@ export type RoomMemberMap = Map<
string,
Pick<RoomMember, "userId" | "getMxcAvatarUrl" | "rawDisplayName">
>;
export function roomToMembersMap(matrixRoom: MatrixRoom): RoomMemberMap {
export function roomToMembersMap(
matrixRoom: Pick<MatrixRoom, "getMembersWithMembership">,
): RoomMemberMap {
const members = matrixRoom
.getMembersWithMembership(KnownMembership.Join)
.concat(matrixRoom.getMembersWithMembership(KnownMembership.Invite));
@@ -37,9 +39,10 @@ export function roomToMembersMap(matrixRoom: MatrixRoom): RoomMemberMap {
}, new Map());
}
/** Listens for `RoomStateEvent.Members` on the room. */
export function createRoomMembers$(
scope: ObservableScope,
matrixRoom: MatrixRoom,
matrixRoom: Pick<MatrixRoom, "getMembersWithMembership" | "on" | "off">,
): Behavior<RoomMemberMap> {
return scope.behavior(
fromEvent(matrixRoom, RoomStateEvent.Members).pipe(
+6
View File
@@ -57,6 +57,12 @@ export function createRTCMember(
userId,
deviceId,
memberId,
matrixEventId$: scope.behavior(
membership$.pipe(
map((membership) => membership.eventId),
distinctUntilChanged(),
),
),
displayName$: scope.behavior(
metadata
.createDisplayNameBehavior$(scope, userId)
@@ -36,11 +36,7 @@ const configTransport: Transport = {
function makeClient(): MockedObject<DiscoveryClient> {
return {
getDomain: vi.fn().mockReturnValue("example.org"),
baseUrl: "https://matrix.example.org",
_unstable_getRTCTransports: vi.fn().mockResolvedValue([]),
getOpenIdToken: vi.fn(),
getDeviceId: vi.fn(),
getRTCTransports: vi.fn().mockResolvedValue([]),
} as unknown as MockedObject<DiscoveryClient>;
}
@@ -57,7 +53,7 @@ describe("TransportAutoDiscovery", () => {
"prefers backend transport other app config $transports",
async ({ transports }) => {
const client = makeClient();
client._unstable_getRTCTransports.mockResolvedValue(transports);
client.getRTCTransports.mockResolvedValue(transports);
const discovery = new TransportAutoDiscovery({
client,
@@ -71,7 +67,7 @@ describe("TransportAutoDiscovery", () => {
expect(discoveredTransport).toStrictEqual(backendTransport);
expect(discoveredTransport).not.toStrictEqual(configTransport);
expect(client._unstable_getRTCTransports).toHaveBeenCalledTimes(1);
expect(client.getRTCTransports).toHaveBeenCalledTimes(1);
},
);
@@ -81,10 +77,7 @@ describe("TransportAutoDiscovery", () => {
url: "wss://sfu.example.org",
};
const client = makeClient();
client._unstable_getRTCTransports.mockResolvedValue([
backendTransport,
mLivekit,
]);
client.getRTCTransports.mockResolvedValue([backendTransport, mLivekit]);
const discovery = new TransportAutoDiscovery({
client,
@@ -100,7 +93,7 @@ describe("TransportAutoDiscovery", () => {
it("Retries limit_exceeded backend transport", async () => {
const client = makeClient();
client._unstable_getRTCTransports
client.getRTCTransports
.mockRejectedValueOnce(
new MatrixError(
{
@@ -124,7 +117,7 @@ describe("TransportAutoDiscovery", () => {
backendTransport,
);
expect(client._unstable_getRTCTransports).toHaveBeenCalledTimes(2);
expect(client.getRTCTransports).toHaveBeenCalledTimes(2);
});
const INVALID_TEST_CASES: Array<{ transports: Transport[] }> = [
@@ -135,7 +128,7 @@ describe("TransportAutoDiscovery", () => {
"falls back to config when backend has no (valid) livekit transports $transports",
async ({ transports }) => {
const client = makeClient();
client._unstable_getRTCTransports.mockResolvedValue(transports);
client.getRTCTransports.mockResolvedValue(transports);
const discovery = new TransportAutoDiscovery({
client,
@@ -152,7 +145,7 @@ describe("TransportAutoDiscovery", () => {
it("returns null when backend and config are all unavailable", async () => {
const client = makeClient();
client._unstable_getRTCTransports.mockResolvedValue([]);
client.getRTCTransports.mockResolvedValue([]);
const discovery = new TransportAutoDiscovery({
client,
+2 -5
View File
@@ -10,10 +10,7 @@ import { type Logger } from "matrix-js-sdk/lib/logger";
import { doNetworkOperationWithRetry } from "../utils/network";
type TransportDiscoveryClient = Pick<
MatrixClient,
"getDomain" | "_unstable_getRTCTransports"
>;
type TransportDiscoveryClient = Pick<MatrixClient, "getRTCTransports">;
export interface TransportAutoDiscoveryProps {
client: TransportDiscoveryClient;
@@ -74,7 +71,7 @@ export class TransportAutoDiscovery {
this.logger.info("First try to use getRTCTransports end point ...");
try {
const transportList = await doNetworkOperationWithRetry(async () =>
client._unstable_getRTCTransports(),
client.getRTCTransports(),
);
for (const type of this.transportTypes) {
const first = transportList.find(
+6 -2
View File
@@ -151,12 +151,16 @@ export interface LocalAudioMediaTrack
extends AudioMediaTrack, LocalMediaTrack {}
export interface LocalVideoMediaTrack extends VideoMediaTrack, LocalMediaTrack {
/** For mirroring; undefined where the camera does not say which way it faces. */
/**
* For mirroring. A camera that does not say which way it faces is taken to
* face the user, unless it is known to film the room, as a phone used as a
* webcam. Undefined while there is no camera track.
*/
facingMode$: Behavior<"user" | "environment" | undefined>;
/**
* Restarts the camera facing the other way, on devices with a front and a
* back camera, and resolves with the id of the device now in use. Does
* nothing where the facing mode is unknown.
* nothing while there is no camera track.
*/
switchFacingMode(): Promise<string | undefined>;
/** Background blur and the like; undefined removes the processor. */
@@ -92,7 +92,7 @@ function setupTest(): void {
matrix_server_name: "example.org",
expires_in: 3600,
}),
_unstable_getLivekitToken: vi.fn().mockResolvedValue({ jwt: testJWTToken }),
getLivekitToken: vi.fn().mockResolvedValue({ jwt: testJWTToken }),
});
localParticipantEventEmiter = new EventEmitter();
@@ -191,7 +191,7 @@ describe("Start connection states", () => {
const deferred = Promise.withResolvers<LivekitGetTokenResponse>();
client._unstable_getLivekitToken.mockImplementation(
client.getLivekitToken.mockImplementation(
async (): Promise<LivekitGetTokenResponse> => {
return await deferred.promise;
},
@@ -235,7 +235,7 @@ describe("Start connection states", () => {
onTestFinished(() => s.unsubscribe());
const deferredSFU = Promise.withResolvers<void>();
client._unstable_getLivekitToken.mockImplementation(async () => {
client.getLivekitToken.mockImplementation(async () => {
await deferredSFU.promise;
throw new MatrixError(
{
@@ -378,7 +378,7 @@ describe("Start connection states", () => {
await connection.start();
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(client.getLivekitToken).not.toHaveBeenCalled();
expect(fetchMock.called(`${serviceUrl}/sfu/get`)).toBe(true);
expect(fakeLivekitRoom.connect).toHaveBeenCalledWith(
"wss://sfu",
@@ -33,7 +33,7 @@ const urlTransport: UnstableLivekitTransport = {
function client(): ClientGetTokenParts & ClientOpenIDParts {
return {
getOpenIdToken: vi.fn(),
_unstable_getLivekitToken: vi.fn().mockResolvedValue({ jwt: testJWTToken }),
getLivekitToken: vi.fn().mockResolvedValue({ jwt: testJWTToken }),
};
}
@@ -160,8 +160,8 @@ describe("createLivekitBackend", () => {
const client = {
baseUrl: homeserver,
getOpenIdToken: vi.fn(),
_unstable_getLivekitToken: vi.fn(),
_unstable_delegateDelayedLeave: vi.fn(),
getLivekitToken: vi.fn(),
delegateDelayedLeave: vi.fn(),
};
/** The connections the stubbed factory handed out, with their participants to drive. */
let connections: {
@@ -344,6 +344,7 @@ describe("createLivekitBackend", () => {
userId: "@bob:example.org",
deviceId: "DEV000",
memberId: legacyId,
matrixEventId$: constant("$bob"),
transport$: constant({
type: "livekit",
id: JSON.stringify(transport),
@@ -73,10 +73,7 @@ export interface LivekitBackendOptions {
*/
client: Pick<
MatrixClient,
| "getOpenIdToken"
| "_unstable_getLivekitToken"
| "_unstable_delegateDelayedLeave"
| "baseUrl"
"getOpenIdToken" | "getLivekitToken" | "delegateDelayedLeave" | "baseUrl"
>;
mediaQuality?: MediaQuality;
}
@@ -18,15 +18,7 @@ import {
TrackEvent,
type TrackPublication,
} from "livekit-client";
import {
afterEach,
beforeEach,
describe,
expect,
it,
onTestFinished,
vi,
} from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { ObservableScope } from "../../reactive/ObservableScope";
import {
@@ -233,10 +225,6 @@ describe("createLivekitMediaTrack", () => {
])(
"leaves a processed camera alone unless its device changes: $deviceId",
async ({ deviceId, switches }) => {
vi.stubGlobal("MediaStreamTrack", class {});
onTestFinished(() => {
vi.unstubAllGlobals();
});
const camera = Object.assign(Object.create(LocalVideoTrack.prototype), {
source: Track.Source.Camera,
_mediaStreamTrack: {
@@ -270,6 +258,41 @@ describe("createLivekitMediaTrack", () => {
},
);
it("takes the facing mode of a processed camera from the camera", async () => {
const source = {
readyState: "live",
label: "Back Camera",
getSettings: () => ({ facingMode: "environment" }),
};
const camera = Object.assign(Object.create(LocalVideoTrack.prototype), {
source: Track.Source.Camera,
_mediaStreamTrack: source,
mediaStream: { getVideoTracks: () => [source] },
processor: {
processedTrack: { label: "", getSettings: () => ({}) },
},
restartTrack: vi.fn().mockResolvedValue(undefined),
}) as LocalVideoTrack;
const { participant, publication, room } = fakes({
track: camera as unknown as FakeTrack,
});
const track = createLocalLivekitMediaTrack(
scope,
Object.assign(participant, {
isLocal: true,
}) as unknown as LocalParticipant,
publication as unknown as TrackPublication,
room,
vi.fn(),
) as LocalVideoMediaTrack;
expect(track.facingMode$.value).toBe("environment");
await track.switchFacingMode();
expect(camera.restartTrack).toHaveBeenCalledExactlyOnceWith({
facingMode: "user",
});
});
// LiveKit stops a camera that is turned off; the processor is built when it
// is turned on again
it.each([
@@ -279,10 +302,6 @@ describe("createLivekitMediaTrack", () => {
"gives a processor to a camera that $state: $takes",
async ({ isMuted, takes }) => {
// jsdom has none; LiveKit's facing mode checks against it
vi.stubGlobal("MediaStreamTrack", class {});
onTestFinished(() => {
vi.unstubAllGlobals();
});
const camera = Object.assign(Object.create(LocalVideoTrack.prototype), {
isMuted,
_mediaStreamTrack: {
@@ -11,7 +11,6 @@ import {
roomEventSelector,
} from "@livekit/components-core";
import {
facingModeFromLocalTrack,
type LocalParticipant,
LocalTrack,
LocalVideoTrack,
@@ -50,6 +49,7 @@ import {
type VideoMediaTrack,
} from "../../media-api";
import { MatrixRTCError } from "../../errors";
import { facingModeOf } from "../../utils/facingMode";
import { toLivekitProcessor, type LivekitProcessor } from "./videoProcessor";
export const mediaSources: Record<Track.Source, MediaSource> = {
@@ -231,10 +231,9 @@ export function createLocalLivekitMediaTrack(
switchFacingMode: async () => {
const track = videoTrack();
if (!track) return;
const { facingMode } = facingModeFromLocalTrack(track);
if (facingMode !== "user" && facingMode !== "environment") return;
await track.restartTrack({
facingMode: facingMode === "user" ? "environment" : "user",
facingMode:
facingModeOf(sourceTrack(track)) === "user" ? "environment" : "user",
});
return track.mediaStreamTrack.getSettings().deviceId;
},
@@ -288,6 +287,14 @@ async function rtpStreamStats(
return undefined;
}
/**
* The camera's own track. While a processor runs LiveKit's media stream track
* is the processed one, which says nothing of the camera.
*/
function sourceTrack(track: LocalVideoTrack): MediaStreamTrack {
return track.mediaStream?.getVideoTracks()[0] ?? track.mediaStreamTrack;
}
function facingMode$(
scope: ObservableScope,
track$: Behavior<Track | undefined>,
@@ -298,12 +305,7 @@ function facingMode$(
if (!(track instanceof LocalVideoTrack)) return of(undefined);
return fromEvent(track, TrackEvent.Restarted).pipe(
startWith(null),
map(() => {
const { facingMode } = facingModeFromLocalTrack(track);
return facingMode === "user" || facingMode === "environment"
? facingMode
: undefined;
}),
map(() => facingModeOf(sourceTrack(track))),
);
}),
),
@@ -84,7 +84,7 @@ describe("findRemotePublishLivekitTransport", () => {
beforeEach(() => {
client = {
_unstable_getLivekitToken: vi
getLivekitToken: vi
.fn()
.mockResolvedValue({ jwt: jwtWithPublishGrant(true) }),
};
@@ -92,8 +92,8 @@ describe("findRemotePublishLivekitTransport", () => {
it("publishes on the oldest member's SFU with its server_name", async () => {
await expect(find([carol, bob])).resolves.toEqual(bobsTransport);
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(1);
expect(client._unstable_getLivekitToken).toHaveBeenCalledWith({
expect(client.getLivekitToken).toHaveBeenCalledTimes(1);
expect(client.getLivekitToken).toHaveBeenCalledWith({
url: "wss://sfu.bob.com",
server_name: "bob.com",
room_id: "!room:example.org",
@@ -103,70 +103,68 @@ describe("findRemotePublishLivekitTransport", () => {
});
it("asks about an SFU once however many members are on it", async () => {
client._unstable_getLivekitToken.mockResolvedValue({
client.getLivekitToken.mockResolvedValue({
jwt: jwtWithPublishGrant(false),
});
await expect(find([dave, bobsLaptop, bob])).resolves.toBeNull();
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(1);
expect(client.getLivekitToken).toHaveBeenCalledTimes(1);
});
it("skips our own membership", async () => {
await expect(find([ourselves, bob])).resolves.toEqual(bobsTransport);
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(1);
expect(client.getLivekitToken).toHaveBeenCalledTimes(1);
});
it("ignores members publishing through a legacy JWT service", async () => {
await expect(find([legacyErin, bob])).resolves.toEqual(bobsTransport);
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(1);
expect(client.getLivekitToken).toHaveBeenCalledTimes(1);
});
it("moves on when a homeserver does not let us publish", async () => {
client._unstable_getLivekitToken.mockImplementation(
async ({ server_name }) =>
Promise.resolve({
jwt: jwtWithPublishGrant(server_name === "carol.com"),
}),
client.getLivekitToken.mockImplementation(async ({ server_name }) =>
Promise.resolve({
jwt: jwtWithPublishGrant(server_name === "carol.com"),
}),
);
await expect(find([bob, carol])).resolves.toEqual(carolsTransport);
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(2);
expect(client.getLivekitToken).toHaveBeenCalledTimes(2);
});
it("moves on when a homeserver refuses to issue a token", async () => {
client._unstable_getLivekitToken.mockImplementation(
async ({ server_name }) =>
server_name === "bob.com"
? Promise.reject(
new MatrixError(
{ errcode: "M_FORBIDDEN", error: "Not joined" },
403,
),
)
: Promise.resolve({ jwt: jwtWithPublishGrant(true) }),
client.getLivekitToken.mockImplementation(async ({ server_name }) =>
server_name === "bob.com"
? Promise.reject(
new MatrixError(
{ errcode: "M_FORBIDDEN", error: "Not joined" },
403,
),
)
: Promise.resolve({ jwt: jwtWithPublishGrant(true) }),
);
await expect(find([bob, carol])).resolves.toEqual(carolsTransport);
});
it("finds nothing once all candidates are exhausted", async () => {
client._unstable_getLivekitToken.mockResolvedValue({
client.getLivekitToken.mockResolvedValue({
jwt: jwtWithPublishGrant(false),
});
await expect(find([bob, carol])).resolves.toBeNull();
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(2);
expect(client.getLivekitToken).toHaveBeenCalledTimes(2);
});
it("gives up immediately if our homeserver lacks the CS API", async () => {
client._unstable_getLivekitToken.mockRejectedValue(csApiMissing);
client.getLivekitToken.mockRejectedValue(csApiMissing);
await expect(find([bob, carol])).resolves.toBeNull();
expect(client._unstable_getLivekitToken).toHaveBeenCalledTimes(1);
expect(client.getLivekitToken).toHaveBeenCalledTimes(1);
});
it("finds nothing where there are no other members", async () => {
await expect(find([ourselves])).resolves.toBeNull();
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(client.getLivekitToken).not.toHaveBeenCalled();
});
});
+4 -7
View File
@@ -20,10 +20,7 @@ function isNetworkError(e: unknown): boolean {
return e instanceof HTTPError || e instanceof ConnectionError;
}
export type ClientGetTokenParts = Pick<
MatrixClient,
"_unstable_getLivekitToken"
>;
export type ClientGetTokenParts = Pick<MatrixClient, "getLivekitToken">;
export interface GetSFUConfigParams {
client: ClientGetTokenParts;
@@ -48,7 +45,7 @@ export async function getSFUConfig({
}: GetSFUConfigParams): Promise<SFUConfig> {
const res = await doNetworkOperationWithRetry(
async () =>
client._unstable_getLivekitToken({
client.getLivekitToken({
url,
server_name: serverName,
room_id: roomId,
@@ -62,7 +59,7 @@ export async function getSFUConfig({
export type ClientDelegationParts = Pick<
MatrixClient,
"_unstable_delegateDelayedLeave" | "baseUrl"
"delegateDelayedLeave" | "baseUrl"
>;
export interface DelegateDelayedLeaveParams {
@@ -90,7 +87,7 @@ export async function delegateDelayedLeave({
}: DelegateDelayedLeaveParams): Promise<void> {
await doNetworkOperationWithRetry(
async () =>
client._unstable_delegateDelayedLeave({
client.delegateDelayedLeave({
url,
room_id: roomId,
slot_id: slotId,
@@ -33,8 +33,8 @@ const client: Mocked<
openID.ClientOpenIDParts
> = {
baseUrl: "https://matrix.example.org",
_unstable_getLivekitToken: vi.fn().mockResolvedValue({ jwt: csApiJWTToken }),
_unstable_delegateDelayedLeave: vi.fn().mockResolvedValue({}),
getLivekitToken: vi.fn().mockResolvedValue({ jwt: csApiJWTToken }),
delegateDelayedLeave: vi.fn().mockResolvedValue({}),
getOpenIdToken: vi
.fn()
.mockResolvedValue({ access_token: "mock-openID-token" }),
@@ -110,7 +110,7 @@ describe("getSFUConfig", () => {
livekitAlias: "via CS API",
}),
);
expect(client._unstable_getLivekitToken).toHaveBeenCalledWith({
expect(client.getLivekitToken).toHaveBeenCalledWith({
url: urlTransport.url,
server_name: "example.org",
room_id: roomId,
@@ -122,11 +122,11 @@ describe("getSFUConfig", () => {
it("does not fall back to OpenID with url transport", async () => {
mockJWTService();
client._unstable_getLivekitToken.mockRejectedValueOnce(unsupportedError);
client.getLivekitToken.mockRejectedValueOnce(unsupportedError);
await expect(
getSFUConfig({ ...defaultParams, transport: urlTransport }),
).rejects.toThrow(expect.any(NoMatrix2AuthorizationService));
expect(client._unstable_getLivekitToken).toHaveBeenCalled();
expect(client.getLivekitToken).toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual([]);
});
@@ -140,7 +140,7 @@ describe("getSFUConfig", () => {
livekitAlias: "via default endpoint",
}),
);
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(client.getLivekitToken).not.toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual(["/get_token"]);
});
@@ -157,7 +157,7 @@ describe("getSFUConfig", () => {
livekitAlias: "via default endpoint",
}),
);
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(client.getLivekitToken).not.toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual(["/get_token"]);
});
@@ -166,7 +166,7 @@ describe("getSFUConfig", () => {
const error = new Error(
"The rtc_livekit_get_token action is not supported by the client.",
);
client._unstable_getLivekitToken.mockRejectedValueOnce(error);
client.getLivekitToken.mockRejectedValueOnce(error);
await expect(
getSFUConfig({ ...defaultParams, transport: urlTransport }),
).rejects.toThrow(error);
@@ -182,13 +182,13 @@ describe("getSFUConfig", () => {
role: "publisher",
}),
).toEqual(expect.objectContaining({ jwt: csApiJWTToken }));
expect(client._unstable_getLivekitToken).toHaveBeenCalled();
expect(client.getLivekitToken).toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual([]);
});
it("does not fall back to OpenID when publishing with url transport", async () => {
mockJWTService();
client._unstable_getLivekitToken.mockRejectedValueOnce(unsupportedError);
client.getLivekitToken.mockRejectedValueOnce(unsupportedError);
await expect(
getSFUConfig({
...defaultParams,
@@ -196,7 +196,7 @@ describe("getSFUConfig", () => {
role: "publisher",
}),
).rejects.toThrow(expect.any(NoMatrix2AuthorizationService));
expect(client._unstable_getLivekitToken).toHaveBeenCalled();
expect(client.getLivekitToken).toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual([]);
});
@@ -216,7 +216,7 @@ describe("getSFUConfig", () => {
livekitAlias: "via legacy endpoint",
}),
);
expect(client._unstable_getLivekitToken).not.toHaveBeenCalled();
expect(client.getLivekitToken).not.toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual(["/sfu/get"]);
});
});
@@ -245,7 +245,7 @@ describe("delegateDelayedLeave", () => {
it("uses CS API with url transport", async () => {
mockJWTService();
await delegateDelayedLeave({ ...defaultParams, transport: urlTransport });
expect(client._unstable_delegateDelayedLeave).toHaveBeenCalledWith({
expect(client.delegateDelayedLeave).toHaveBeenCalledWith({
url: urlTransport.url,
room_id: roomId,
slot_id: slotId,
@@ -257,13 +257,11 @@ describe("delegateDelayedLeave", () => {
it("does not fall back to OpenID with url transport", async () => {
mockJWTService();
client._unstable_delegateDelayedLeave.mockRejectedValueOnce(
unsupportedError,
);
client.delegateDelayedLeave.mockRejectedValueOnce(unsupportedError);
await expect(
delegateDelayedLeave({ ...defaultParams, transport: urlTransport }),
).rejects.toThrow();
expect(client._unstable_delegateDelayedLeave).toHaveBeenCalled();
expect(client.delegateDelayedLeave).toHaveBeenCalled();
expect(jwtServiceCalls()).toEqual([]);
});
@@ -273,7 +271,7 @@ describe("delegateDelayedLeave", () => {
...defaultParams,
transport: serviceUrlTransport,
});
expect(client._unstable_delegateDelayedLeave).not.toHaveBeenCalled();
expect(client.delegateDelayedLeave).not.toHaveBeenCalled();
expect(delegationViaJWTService()).toEqual({
delay_id: "delay123",
delay_timeout: 3_600_000,
@@ -288,7 +286,7 @@ describe("delegateDelayedLeave", () => {
...defaultParams,
transport: urlAndServiceUrlTransport,
});
expect(client._unstable_delegateDelayedLeave).not.toHaveBeenCalled();
expect(client.delegateDelayedLeave).not.toHaveBeenCalled();
expect(delegationViaJWTService()).toEqual({
delay_id: "delay123",
delay_timeout: 3_600_000,
+43
View File
@@ -0,0 +1,43 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { describe, expect, it } from "vitest";
import { facingModeOf } from "./facingMode";
function camera(label: string, facingMode?: string): MediaStreamTrack {
return {
label,
getSettings: () => (facingMode === undefined ? {} : { facingMode }),
} as MediaStreamTrack;
}
describe("facingModeOf", () => {
it.each([
{ label: "Back Camera", facingMode: "environment", faces: "environment" },
{ label: "iPhone Camera", facingMode: "user", faces: "user" },
{ label: "FaceTime HD Camera", facingMode: undefined, faces: "user" },
{ label: "", facingMode: undefined, faces: "user" },
{
label: "Alice's iPhone Camera",
facingMode: undefined,
faces: "environment",
},
{ label: "iPad Camera", facingMode: undefined, faces: "environment" },
{
label: " OBS Virtual Camera ",
facingMode: undefined,
faces: "environment",
},
{ label: "Integrated Camera", facingMode: "left", faces: "user" },
])(
"takes $label ($facingMode) to face $faces",
({ label, facingMode, faces }) => {
expect(facingModeOf(camera(label, facingMode))).toBe(faces);
},
);
});
+23
View File
@@ -0,0 +1,23 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
/**
* Which way a camera faces. Laptop and desktop cameras don't say and face the
* user; of those, a phone used as a webcam (Continuity Camera) films with its
* rear camera and OBS shows a scene, so neither is taken to face the user.
* LiveKit makes the same guess.
*/
export function facingModeOf(track: MediaStreamTrack): "user" | "environment" {
const { facingMode } = track.getSettings();
if (facingMode === "user" || facingMode === "environment") return facingMode;
const label = track.label.trim().toLowerCase();
return label === "obs virtual camera" ||
label.includes("iphone") ||
label.includes("ipad")
? "environment"
: "user";
}
+1
View File
@@ -276,6 +276,7 @@ export class MockRTCSession extends TypedEventEmitter<
return this.joined;
}
public slotDescription = { application: "m.call", id: "ROOM" };
public slotId = "m.call#ROOM";
/** The id of the delayed leave event; undefined until the manager has sent one. */
public delayId: string | undefined = undefined;
+12 -2
View File
@@ -30,7 +30,7 @@ import { HomePage } from "./home/HomePage";
import { LoginPage } from "./auth/LoginPage";
import { RegisterPage } from "./auth/RegisterPage";
import { RoomPage } from "./room/RoomPage";
import { ClientProvider } from "./ClientContext";
import { type ClientLoader, ClientProvider } from "./ClientContext";
import { ErrorPage, LoadingPage } from "./FullScreenView";
import { Initializer } from "./initializer";
import { type WidgetHelpers } from "./widget";
@@ -57,6 +57,16 @@ import { LeaveToHomeProvider } from "./LeaveToHomeContext";
const SentryRoute = Sentry.withSentryReactRouterV7Routing(Route);
// Element Call's own session, for when no host supplies a client.
// - Passed in here, not imported by ClientProvider: this module is only in the
// app builds, so the client setup and the store worker behind it stay out of
// the component package (see the `loadClient` prop).
// - Imported on demand, as it was before, so that a widget, which gets its
// client from the host, never downloads it.
// - Module-level, so that the provider's effect sees one stable loader.
const loadStandaloneClient: ClientLoader = async (...args) =>
(await import("./utils/spa")).initSPA(...args);
interface SimpleProviderProps {
children: JSX.Element;
}
@@ -146,7 +156,7 @@ export const App: FC<Props> = ({ vm, widget }) => {
const content =
loaded && clientReady ? (
<ClientProvider client={widgetClient}>
<ClientProvider client={widgetClient} loadClient={loadStandaloneClient}>
<MediaDevicesContext value={vm.mediaDevices}>
<BackgroundEffectsProvider effects={vm.backgroundEffects}>
<Sentry.ErrorBoundary
+42
View File
@@ -0,0 +1,42 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { expect, test } from "vitest";
import { createClient, Room } from "matrix-js-sdk";
import { withEmitter } from "@element-hq/matrixrtc-sdk";
import { createCallMatrixBackend } from "./CallMatrixBackend";
test("has the SDK's part and the call's own", () => {
const { backend, room } = setup();
expect(backend.getUserId()).toBe("@alice:example.org");
expect(backend.getJoinRule()).toBe(room.getJoinRule());
expect(backend.relations).toBe(room.relations);
});
test("reads the room's name as it is now, also as a room", () => {
const { backend, room } = setup();
const asRoom = withEmitter(backend, backend.roomEmitter);
room.name = "Renamed";
expect(backend.name).toBe("Renamed");
expect(asRoom.name).toBe("Renamed");
});
function setup(): {
backend: ReturnType<typeof createCallMatrixBackend>;
room: Room;
} {
const client = createClient({
baseUrl: "https://matrix.example.org",
userId: "@alice:example.org",
deviceId: "DEVICE",
});
const room = new Room("!room:example.org", client, "@alice:example.org");
return { backend: createCallMatrixBackend(client, room), room };
}
+77
View File
@@ -0,0 +1,77 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type MatrixClient, type Room } from "matrix-js-sdk";
import {
createSdkMatrixBackend,
type SdkMatrixBackend,
} from "@element-hq/matrixrtc-sdk";
/** What a call needs of the client beyond the SDK's part. */
type CallClientPart = Pick<
MatrixClient,
// Reactions and raised hands: decrypting, and lowering a hand
| "decryptEventIfNeeded"
| "redactEvent"
// Our own display name and avatar
| "getUser"
// Changing them, where the host lets us (`supportsProfileChanges`)
| "setDisplayName"
| "setAvatarUrl"
| "uploadContent"
// Developer settings
| "doesServerSupportUnstableFeature"
| "getCrypto"
>;
/** What a call needs of the room beyond the SDK's part. */
type CallRoomPart = Pick<
Room,
// The header and the invite link
| "name"
| "getMxcAvatarUrl"
// Whether to offer the invite link
| "getJoinRule"
// Raised hands already in the room
| "relations"
>;
/**
* STOP GAP: everything a call needs from Matrix on one object. Its
* `clientEmitter` also carries `MatrixEventEvent.Decrypted` (reactions); its
* `roomEmitter` every room event.
*/
export interface CallMatrixBackend
extends SdkMatrixBackend, CallClientPart, CallRoomPart {}
/** A call's backend from a client and a room. */
export function createCallMatrixBackend(
client: Parameters<typeof createSdkMatrixBackend>[0] & CallClientPart,
room: Parameters<typeof createSdkMatrixBackend>[1] & CallRoomPart,
): CallMatrixBackend {
return {
...createSdkMatrixBackend(client, room),
decryptEventIfNeeded: client.decryptEventIfNeeded.bind(client),
redactEvent: client.redactEvent.bind(client),
getUser: client.getUser.bind(client),
setDisplayName: client.setDisplayName.bind(client),
setAvatarUrl: client.setAvatarUrl.bind(client),
uploadContent: client.uploadContent.bind(client),
doesServerSupportUnstableFeature:
client.doesServerSupportUnstableFeature.bind(client),
getCrypto: client.getCrypto.bind(client),
// Read through: the room is renamed while we show it
get name() {
return room.name;
},
getMxcAvatarUrl: room.getMxcAvatarUrl.bind(room),
getJoinRule: room.getJoinRule.bind(room),
get relations() {
return room.relations;
},
};
}
+25 -6
View File
@@ -11,7 +11,11 @@ import { BrowserRouter } from "react-router-dom";
import { type MatrixClient } from "matrix-js-sdk";
import { type FC } from "react";
import { ClientProvider, useClientState } from "./ClientContext";
import {
type ClientLoader,
ClientProvider,
useClientState,
} from "./ClientContext";
const mockClient = (userId = "@alice:example.org"): MatrixClient =>
({
@@ -95,13 +99,13 @@ test("follows the client when the host swaps it", () => {
test("finds a client of its own when the host supplies none", async () => {
const client = mockClient();
vi.doMock("./utils/spa", () => ({
initSPA: vi.fn().mockResolvedValue({ client, passwordlessUser: true }),
}));
const loadClient = vi
.fn<ClientLoader>()
.mockResolvedValue({ client, passwordlessUser: true });
const { container } = render(
<BrowserRouter>
<ClientProvider>
<ClientProvider loadClient={loadClient}>
<ShowClientState />
</ClientProvider>
</BrowserRouter>,
@@ -110,6 +114,21 @@ test("finds a client of its own when the host supplies none", async () => {
// Nothing to show until a session has been restored or created
expect(container.textContent).toBe("loading");
await waitFor(() => expect(container.textContent).toBe("@alice:example.org"));
// Given the session store to restore from and to clear on a stale session
expect(loadClient).toHaveBeenCalledWith(
expect.any(Function),
expect.any(Function),
);
});
vi.doUnmock("./utils/spa");
test("has no one signed in when given neither a client nor a way to load one", async () => {
const { container } = render(
<BrowserRouter>
<ClientProvider>
<ShowClientState />
</ClientProvider>
</BrowserRouter>,
);
await waitFor(() => expect(container.textContent).toBe("unauthenticated"));
});
+71 -13
View File
@@ -142,10 +142,73 @@ interface Props {
* itself — from the widget API, or by restoring or creating a session of its
* own.
*/
client?: MatrixClient;
client?: SuppliedClient;
/**
* How Element Call finds a client when none is supplied: the standalone app
* restores or creates a session of its own. Stable, as a hook dependency.
* Left out along with the client, no one is signed in.
*
* A prop, rather than this module importing `utils/spa` itself, because:
* - This module is in the component build, and so is everything it imports,
* dynamically or not: a dynamic import becomes a chunk in the package,
* not a module left out of it.
* - Behind `utils/spa` sits `utils/initClient` and the client store worker,
* which the bundler emits as soon as it loads the import (see there).
* - `App.tsx`, which the component never imports, is where the standalone
* app passes the loader in; the component passes nothing, having the
* host's client.
*/
loadClient?: ClientLoader;
}
export const ClientProvider: FC<Props> = ({ children, client }) => {
/**
* What is read of a supplied client under a call, and by this provider and
* analytics. Stable methods only, so a host's client, from the host's own copy
* of matrix-js-sdk, will do.
*/
export type SuppliedClient = Pick<
MatrixClient,
// The disconnected banner, and stopping a client opened elsewhere
| "on"
| "removeListener"
| "stopClient"
// Analytics, through `window.matrixclient`
| "getCrypto"
| "isGuest"
| "getAccountDataFromServer"
| "setAccountData"
// The room's encryption system
| "getRoom"
// Avatars
| "mxcUrlToHttp"
| "getAccessToken"
// Rageshakes: who sends them, their crypto state, and asking others for theirs
| "getUserId"
| "getUser"
| "credentials"
| "deviceId"
| "secretStorage"
| "isKeyBackupKeyStored"
| "sendEvent"
>;
/**
* Restores or creates a session of Element Call's own, kept where the given
* functions keep it. Resolves to null when no one is signed in.
*/
export type ClientLoader = (
loadSession: () => Session | undefined,
clearSession: () => void,
) => Promise<InitResult | null>;
export const ClientProvider: FC<Props> = ({
children,
client: suppliedClient,
loadClient,
}) => {
// STOP GAP: held as a whole client, as the standalone and widget pages need
// one. A component host's client is only read through `SuppliedClient`.
const client = suppliedClient as MatrixClient | undefined;
const leaveToHome = useLeaveToHome();
const hostBridge = useHostBridge();
@@ -179,9 +242,13 @@ export const ClientProvider: FC<Props> = ({ children, client }) => {
// React does in strict mode), we need to make sure not to doubly initialize
// the client.
if (initializing.current) return;
if (loadClient === undefined) {
setInitClientState(null);
return;
}
initializing.current = true;
loadClient()
loadClient(loadSession, clearSession)
.then((initResult) => {
setInitClientState(initResult);
if (PosthogAnalytics.instance.isEnabled())
@@ -189,7 +256,7 @@ export const ClientProvider: FC<Props> = ({ children, client }) => {
})
.catch((err) => logger.error(err))
.finally(() => (initializing.current = false));
}, [client]);
}, [client, loadClient]);
const changePassword = useCallback(
async (password: string) => {
@@ -360,15 +427,6 @@ export type InitResult = {
passwordlessUser: boolean;
};
/**
* Restores or creates a session of Element Call's own. Only reached when no
* client was supplied for it to use.
*/
async function loadClient(): Promise<InitResult | null> {
const { initSPA } = await import("./utils/spa");
return initSPA(loadSession, clearSession);
}
export interface Session {
user_id: string;
device_id: string;
+20 -22
View File
@@ -15,7 +15,7 @@ import {
afterAll,
} from "vitest";
import { logger } from "matrix-js-sdk/lib/logger";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { type Statistics } from "matrix-js-sdk/lib/matrixrtc";
import { PosthogAnalytics } from "./PosthogAnalytics";
import {
@@ -34,16 +34,14 @@ const defaultTotals = {
roomEventEncryptionKeysReceivedTotalAge: 500,
};
function createMockRtcSession(overrides?: {
function createMockStatistics(overrides?: {
counters?: Partial<typeof defaultCounters>;
totals?: Partial<typeof defaultTotals>;
}): MatrixRTCSession {
}): Statistics {
return {
statistics: {
counters: { ...defaultCounters, ...overrides?.counters },
totals: { ...defaultTotals, ...overrides?.totals },
},
} as unknown as MatrixRTCSession;
counters: { ...defaultCounters, ...overrides?.counters },
totals: { ...defaultTotals, ...overrides?.totals },
} as Statistics;
}
describe("CallEnded", () => {
@@ -65,9 +63,9 @@ describe("CallEnded", () => {
it("warns if startTime is missing when track is called", () => {
const warnSpy = vi.spyOn(logger, "warn");
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession();
const statistics = createMockStatistics();
tracker.track("test-call-id", 2, false, mockSession);
tracker.track("test-call-id", 2, false, statistics);
expect(warnSpy).toHaveBeenCalledWith(
"[PosthogEvents] Failed to send posthog callEnded event due to missing startTime",
@@ -77,11 +75,11 @@ describe("CallEnded", () => {
it("tracks event with correct properties when startTime is set", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession();
const statistics = createMockStatistics();
tracker.cacheStartCall(new Date(Date.now() - 60000));
tracker.cacheParticipantCountChanged(5);
tracker.track("test-call-id", 3, true, mockSession);
tracker.track("test-call-id", 3, true, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
{
@@ -105,13 +103,13 @@ describe("CallEnded", () => {
it("tracks maxParticipantsCount correctly across multiple changes", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession();
const statistics = createMockStatistics();
tracker.cacheStartCall(new Date());
tracker.cacheParticipantCountChanged(3);
tracker.cacheParticipantCountChanged(7);
tracker.cacheParticipantCountChanged(2);
tracker.track("test-call-id", 1, false, mockSession);
tracker.track("test-call-id", 1, false, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
@@ -123,12 +121,12 @@ describe("CallEnded", () => {
it("computes roomEventEncryptionKeysReceivedAverageAge as 0 when no keys received", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession({
const statistics = createMockStatistics({
counters: { roomEventEncryptionKeysReceived: 0 },
});
tracker.cacheStartCall(new Date());
tracker.track("test-call-id", 1, false, mockSession);
tracker.track("test-call-id", 1, false, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
@@ -140,13 +138,13 @@ describe("CallEnded", () => {
it("computes roomEventEncryptionKeysReceivedAverageAge correctly when keys are received", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession({
const statistics = createMockStatistics({
counters: { roomEventEncryptionKeysReceived: 4 },
totals: { roomEventEncryptionKeysReceivedTotalAge: 200 },
});
tracker.cacheStartCall(new Date());
tracker.track("test-call-id", 1, false, mockSession);
tracker.track("test-call-id", 1, false, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
@@ -158,10 +156,10 @@ describe("CallEnded", () => {
it("passes send_instantly option correctly", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession();
const statistics = createMockStatistics();
tracker.cacheStartCall(new Date());
tracker.track("test-call-id", 1, false, mockSession);
tracker.track("test-call-id", 1, false, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
expect.anything(),
@@ -171,14 +169,14 @@ describe("CallEnded", () => {
it("includes per-reason reconnecting counts in CallEnded", () => {
const tracker = new CallEndedTracker();
const mockSession = createMockRtcSession();
const statistics = createMockStatistics();
tracker.cacheStartCall(new Date());
tracker.cacheReconnecting("sync");
tracker.cacheReconnecting("sync");
tracker.cacheReconnecting("livekit");
tracker.cacheReconnecting("membership");
tracker.track("test-call-id", 1, false, mockSession);
tracker.track("test-call-id", 1, false, statistics);
expect(PosthogAnalytics.instance.trackEvent).toHaveBeenCalledWith(
expect.objectContaining({
+7 -8
View File
@@ -7,7 +7,7 @@ Please see LICENSE in the repository root for full details.
import { type DisconnectReason } from "livekit-client";
import { logger } from "matrix-js-sdk/lib/logger";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { type Statistics } from "matrix-js-sdk/lib/matrixrtc";
import {
type IPosthogEvent,
@@ -80,7 +80,7 @@ export class CallEndedTracker {
callId: string,
callParticipantsNow: number,
sendInstantly: boolean,
rtcSession: MatrixRTCSession,
statistics: Statistics,
): void {
if (this.cache.startTime) {
PosthogAnalytics.instance.trackEvent<CallEnded>(
@@ -91,14 +91,13 @@ export class CallEndedTracker {
callParticipantsOnLeave: callParticipantsNow,
callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000,
roomEventEncryptionKeysSent:
rtcSession.statistics.counters.roomEventEncryptionKeysSent,
statistics.counters.roomEventEncryptionKeysSent,
roomEventEncryptionKeysReceived:
rtcSession.statistics.counters.roomEventEncryptionKeysReceived,
statistics.counters.roomEventEncryptionKeysReceived,
roomEventEncryptionKeysReceivedAverageAge:
rtcSession.statistics.counters.roomEventEncryptionKeysReceived > 0
? rtcSession.statistics.totals
.roomEventEncryptionKeysReceivedTotalAge /
rtcSession.statistics.counters.roomEventEncryptionKeysReceived
statistics.counters.roomEventEncryptionKeysReceived > 0
? statistics.totals.roomEventEncryptionKeysReceivedTotalAge /
statistics.counters.roomEventEncryptionKeysReceived
: 0,
callReconnectingCount: this.cache.reconnectingCount,
callReconnectingCountSync: this.cache.reconnectingCountByReason.sync,
+1 -1
View File
@@ -13,7 +13,7 @@ import {
type MatrixClient,
} from "matrix-js-sdk";
import { initClient } from "../utils/matrix";
import { initClient } from "../utils/initClient";
import { type Session } from "../ClientContext";
/**
* This provides the login method to login using user credentials.
+1 -1
View File
@@ -14,7 +14,7 @@ import {
} from "matrix-js-sdk";
import { logger } from "matrix-js-sdk/lib/logger";
import { initClient } from "../utils/matrix";
import { initClient } from "../utils/initClient";
import { type Session } from "../ClientContext";
import { Config } from "../config/Config";
import { useUrlParams } from "../UrlParams";
+35 -27
View File
@@ -10,13 +10,13 @@ import { expect, test } from "vitest";
import { TooltipProvider } from "@vector-im/compound-web";
import { userEvent } from "@testing-library/user-event";
import { type ReactNode } from "react";
import { type MatrixClient, type Room } from "matrix-js-sdk";
import { ReactionToggleButton } from "./ReactionToggleButton";
import { ElementCallReactionEventType } from "../reactions";
import { type CallViewModel } from "../state/CallViewModel/CallViewModel";
import { getBasicCallViewModelEnvironment } from "../utils/test-viewmodel";
import { alice, local, localRtcMember } from "../utils/test-fixtures";
import { type MockRTCSession } from "../utils/test";
import { ReactionsSenderProvider } from "../reactions/useReactionsSender";
import { initializeWidget } from "../widget";
initializeWidget();
@@ -24,18 +24,17 @@ initializeWidget();
const localIdent = `${localRtcMember.userId}:${localRtcMember.deviceId}`;
function TestComponent({
rtcSession,
matrixRoom,
client,
vm,
}: {
rtcSession: MockRTCSession;
matrixRoom: Room;
client: MatrixClient;
vm: CallViewModel;
}): ReactNode {
return (
<TooltipProvider>
<ReactionsSenderProvider
vm={vm}
rtcSession={rtcSession.asMockedSession()}
>
<ReactionsSenderProvider vm={vm} room={matrixRoom} client={client}>
<ReactionToggleButton
reactionData={{
reactions$: vm.reactions$,
@@ -50,9 +49,9 @@ function TestComponent({
test("Can open menu", async () => {
const user = userEvent.setup();
const { vm, rtcSession } = getBasicCallViewModelEnvironment([alice]);
const { vm, matrixRoom, client } = getBasicCallViewModelEnvironment([alice]);
const { getByLabelText, container } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
expect(container).toMatchSnapshot();
@@ -60,15 +59,15 @@ test("Can open menu", async () => {
test("Can raise hand", async () => {
const user = userEvent.setup();
const { vm, rtcSession, handRaisedSubject$ } =
const { vm, matrixRoom, client, handRaisedSubject$ } =
getBasicCallViewModelEnvironment([local, alice]);
const { getByLabelText, container } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
await user.click(getByLabelText("Raise hand"));
expect(rtcSession.room.client.sendEvent).toHaveBeenCalledWith(
rtcSession.room.roomId,
expect(client.sendEvent).toHaveBeenCalledWith(
matrixRoom.roomId,
"m.reaction",
{
"m.relates_to": {
@@ -94,10 +93,10 @@ test("Can raise hand", async () => {
test("Can lower hand", async () => {
const reactionEventId = "$my-reaction-event:example.org";
const user = userEvent.setup();
const { vm, rtcSession, handRaisedSubject$ } =
const { vm, matrixRoom, client, handRaisedSubject$ } =
getBasicCallViewModelEnvironment([local, alice]);
const { getByLabelText, container } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
await user.click(getByLabelText("Raise hand"));
@@ -112,8 +111,8 @@ test("Can lower hand", async () => {
});
await user.click(getByLabelText("Reactions"));
await user.click(getByLabelText("Lower hand"));
expect(rtcSession.room.client.redactEvent).toHaveBeenCalledWith(
rtcSession.room.roomId,
expect(client.redactEvent).toHaveBeenCalledWith(
matrixRoom.roomId,
reactionEventId,
);
act(() => {
@@ -125,14 +124,17 @@ test("Can lower hand", async () => {
test("Can react with emoji", async () => {
const user = userEvent.setup();
const { vm, rtcSession } = getBasicCallViewModelEnvironment([local, alice]);
const { vm, matrixRoom, client } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getByLabelText, getByText } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
await user.click(getByText("🐶"));
expect(rtcSession.room.client.sendEvent).toHaveBeenCalledWith(
rtcSession.room.roomId,
expect(client.sendEvent).toHaveBeenCalledWith(
matrixRoom.roomId,
ElementCallReactionEventType,
{
"m.relates_to": {
@@ -147,16 +149,19 @@ test("Can react with emoji", async () => {
test("Can fully expand emoji picker", async () => {
const user = userEvent.setup();
const { vm, rtcSession } = getBasicCallViewModelEnvironment([local, alice]);
const { vm, matrixRoom, client } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getByLabelText, container, getByText } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
await user.click(getByLabelText("Show more"));
expect(container).toMatchSnapshot();
await user.click(getByText("🦗"));
expect(rtcSession.room.client.sendEvent).toHaveBeenCalledWith(
rtcSession.room.roomId,
expect(client.sendEvent).toHaveBeenCalledWith(
matrixRoom.roomId,
ElementCallReactionEventType,
{
"m.relates_to": {
@@ -171,9 +176,12 @@ test("Can fully expand emoji picker", async () => {
test("Can close reaction dialog", async () => {
const user = userEvent.setup();
const { vm, rtcSession } = getBasicCallViewModelEnvironment([local, alice]);
const { vm, matrixRoom, client } = getBasicCallViewModelEnvironment([
local,
alice,
]);
const { getByLabelText, container } = render(
<TestComponent vm={vm} rtcSession={rtcSession} />,
<TestComponent vm={vm} matrixRoom={matrixRoom} client={client} />,
);
await user.click(getByLabelText("Reactions"));
await user.click(getByLabelText("Show more"));
+1 -1
View File
@@ -45,7 +45,7 @@ interface Props {
/** Offers to add a background of one's own. Omit to leave that tile out. */
onAdd?: () => void;
addLabel?: string;
/** Removes a removable one, never the one in force. Omit to offer none. */
/** Removes a removable one, unless it is the selected one. Omit to offer none. */
onRemove?: (id: string) => void;
removeLabel?: string;
}
+68 -193
View File
@@ -22,7 +22,7 @@ import { MediaDevices } from "../state/MediaDevices";
import { globalScope } from "../state/ObservableScope";
import { constant } from "../state/Behavior";
import { type LayoutMode } from "../state/LayoutSwitchViewModel";
import { shippedBackgrounds } from "../tracks/backgroundEffectCatalog";
import { type MediaMenuSnapshot } from "./MediaMenuViewModel";
// consts for tests
const reactionIdentifier = "@user:example.com:DEVICE";
@@ -35,10 +35,57 @@ const mediaDevices = new MediaDevices(globalScope, {
controlledAudioDevices: false,
});
function menu(
kind: "audio" | "video",
withDevices: boolean,
): MediaMenuSnapshot {
const device = kind === "audio" ? "Microphone" : "Camera";
return {
enabled: true,
busy: false,
toggle: fn(),
options: withDevices
? [
{ id: "1", label: { type: "name", name: `${device} 1` } },
{ id: "2", label: { type: "name", name: `${device} 2` } },
]
: [],
selected: "1",
select: fn(),
outputOptions:
withDevices && kind === "audio"
? [
{
id: "default",
label: { type: "default", name: "Built-in Output" },
},
]
: [],
selectedOutput: "default",
selectOutput: fn(),
backgroundEffect: "none",
backgroundEffects:
kind === "video"
? [
{ id: "none", kind: "none" },
{ id: "blur", kind: "blur" },
]
: [],
backgroundEffectNotice: undefined,
backgroundEffectSettling: false,
backgroundImageRefusal: undefined,
selectBackgroundEffect: fn(),
addBackgroundImage: undefined,
removeBackgroundEffect: undefined,
cameraTrack: null,
};
}
/**
* A wrapper component that is used for:
* - exposing the snapshot via props so the storybook documents the snapshot properties (basically unpack them form the vm)
* - constructing the layout switch view model
* - constructing the layout switch and the menus' view models; the menus'
* own states are in the MediaMenuButton stories
* - Add additional react context
* The paraeters are all params from the FooterSnapshot,
* the Snapshot of the vm, the wrapper will create a mocked vm from it and pass it to the CallFooter.
@@ -49,15 +96,22 @@ function CallFooterStoryWrapper({
children,
layout,
setLayout,
withDevices,
...vmSnapshot
}: Omit<FooterSnapshot, "layoutSwitchVm"> & {
}: Omit<FooterSnapshot, "layoutSwitchVm" | "audioMenuVm" | "cameraMenuVm"> & {
children?: false | JSX.Element | JSX.Element[] | undefined;
layout: LayoutMode | null;
setLayout: (value: LayoutMode) => void;
/** Whether the menus have devices to pick, or are plain mute buttons. */
withDevices: boolean;
}): ReactNode {
const audioMenuVm = useStaticViewModel(menu("audio", withDevices));
const cameraMenuVm = useStaticViewModel(menu("video", withDevices));
const vm = useStaticViewModel({
...vmSnapshot,
layoutSwitchVm: layout && { layout$: constant(layout), setLayout },
audioMenuVm,
cameraMenuVm,
});
return (
<MediaDevicesContext value={mediaDevices}>
@@ -102,8 +156,6 @@ const meta = {
},
toggleScreenSharing: fnArgType,
openSettings: fnArgType,
toggleAudio: fnArgType,
toggleVideo: fnArgType,
hangup: fnArgType,
},
} satisfies Meta<typeof CallFooterStoryWrapper>;
@@ -116,32 +168,9 @@ export const Default: Story = {
showLogo: false,
layout: "grid",
setLayout: fn(),
audioEnabled: true,
audioBusy: false,
videoEnabled: true,
videoBusy: false,
withDevices: false,
openSettings: fn(),
toggleAudio: fn(),
toggleVideo: fn(),
toggleScreenSharing: fn(),
selectBackgroundEffect: fn(),
backgroundEffect: "blur",
backgroundEffects: [
{ id: "none", kind: "none", removable: false },
{ id: "blur", kind: "blur", removable: false },
...shippedBackgrounds.map((background) => ({
id: `image:${background.id}`,
kind: "image" as const,
imageUrl: background.imagePath,
removable: false,
})),
],
backgroundEffectNotice: undefined,
backgroundEffectSettling: false,
backgroundImageRefusal: undefined,
addBackgroundImage: fn(),
removeBackgroundEffect: fn(),
cameraTrack: null,
hangup: fn(),
buttonSize: "lg",
showFooter: true,
@@ -154,49 +183,17 @@ export const Default: Story = {
reactionData: undefined,
debugTileLayout: false,
tileStoreGeneration: undefined,
audioOptions: [],
audioOutputOptions: [],
videoOptions: [],
selectedAudio: undefined,
selectedAudioOutput: undefined,
selectedVideo: undefined,
selectAudioButtonOption: undefined,
selectAudioOutputOption: undefined,
selectVideoButtonOption: undefined,
},
parameters: {
layout: "fullscreen",
},
};
export const WithAudioAndVideoOptions: Story = {
...Default,
args: {
...Default.args,
audioEnabled: false,
videoEnabled: true,
audioOptions: [
{ label: { type: "name", name: "Microphone 1" }, id: "1" },
{ label: { type: "name", name: "Microphone 2" }, id: "2" },
],
audioOutputOptions: [
{ label: { type: "default", name: "Built-in Output" }, id: "default" },
{ label: { type: "name", name: "Headset" }, id: "2" },
],
videoOptions: [
{ label: { type: "name", name: "Camera 1" }, id: "1" },
{ label: { type: "name", name: "Camera 2" }, id: "2" },
],
selectedAudio: "2",
selectedAudioOutput: "default",
selectedVideo: "1",
},
};
export const StaysWhileAMenuIsOpen: Story = {
...Default,
args: {
...WithAudioAndVideoOptions.args,
...Default.args,
withDevices: true,
// In a short window the footer overlays the call and hides itself.
asOverlay: true,
showFooter: true,
@@ -219,25 +216,6 @@ export const StaysWhileAMenuIsOpen: Story = {
},
};
export const AudioBusy: Story = {
...Default,
args: {
...Default.args,
audioEnabled: true,
audioBusy: true,
videoEnabled: true,
},
};
export const VideoBusy: Story = {
...Default,
args: {
...Default.args,
audioEnabled: true,
videoEnabled: true,
videoBusy: true,
},
};
export const WithLogo: Story = {
...Default,
args: {
@@ -246,45 +224,7 @@ export const WithLogo: Story = {
},
};
export const AudioVideoEnabled: Story = {
...Default,
args: {
...Default.args,
audioEnabled: true,
videoEnabled: true,
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const spotlightRadio = canvas.getByRole("radio", { name: "Spotlight" });
await userEvent.click(spotlightRadio);
await expect(args.setLayout).toHaveBeenCalledWith("spotlight");
const micButtonMute = canvas.getByRole("switch", {
name: "Mute microphone",
});
await userEvent.click(micButtonMute);
await expect(args.toggleAudio).toHaveBeenCalled();
const videoMuteButton = canvas.getByRole("switch", {
name: "Stop video",
});
await userEvent.click(videoMuteButton);
await expect(args.toggleVideo).toHaveBeenCalled();
const screenShare = canvas.getByRole("switch", {
name: "Share screen",
});
await userEvent.click(screenShare);
await expect(args.toggleScreenSharing).toHaveBeenCalled();
const endCall = canvas.getByRole("button", {
name: "End call",
});
await userEvent.click(endCall);
await expect(args.hangup).toHaveBeenCalled();
},
};
/** used to test switching to grid mode */
/** Switching to grid, and the footer's own buttons, act. */
export const SpotlightMode: Story = {
...Default,
args: {
@@ -293,10 +233,12 @@ export const SpotlightMode: Story = {
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const spotlightRadio = canvas.getByRole("radio", { name: "Grid" });
await userEvent.click(spotlightRadio);
await userEvent.click(canvas.getByRole("radio", { name: "Grid" }));
await expect(args.setLayout).toHaveBeenCalledWith("grid");
await userEvent.click(canvas.getByRole("switch", { name: "Share screen" }));
await expect(args.toggleScreenSharing).toHaveBeenCalled();
await userEvent.click(canvas.getByRole("button", { name: "End call" }));
await expect(args.hangup).toHaveBeenCalled();
},
};
@@ -330,34 +272,10 @@ export const Pip: Story = {
buttonSize: "md",
layout: null,
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
play: async ({ canvasElement }) => {
await expect(
canvas.queryByRole("radio", { name: "Spotlight" }),
within(canvasElement).queryByRole("radio", { name: "Spotlight" }),
).not.toBeInTheDocument();
const micButtonMute = canvas.getByRole("switch", {
name: "Mute microphone",
});
await userEvent.click(micButtonMute);
await expect(args.toggleAudio).toHaveBeenCalled();
const videoMuteButton = canvas.getByRole("switch", {
name: "Stop video",
});
await userEvent.click(videoMuteButton);
await expect(args.toggleVideo).toHaveBeenCalled();
const screenShare = canvas.getByRole("switch", {
name: "Share screen",
});
await userEvent.click(screenShare);
await expect(args.toggleScreenSharing).toHaveBeenCalled();
const endCall = canvas.getByRole("button", {
name: "End call",
});
await userEvent.click(endCall);
await expect(args.hangup).toHaveBeenCalled();
},
};
export const NoControlsWithLogo: Story = {
@@ -378,18 +296,6 @@ export const DebugData: Story = {
},
};
export const UnavailableMediaDevices: Story = {
...Default,
args: {
...Default.args,
audioEnabled: false,
videoEnabled: false,
toggleAudio: undefined,
toggleVideo: undefined,
audioOutputSwitcher: undefined,
},
};
export const MobileLayout: Story = {
...Default,
args: {
@@ -420,37 +326,6 @@ export const Lobby: Story = {
},
};
export const LobbyMobile: Story = {
...Default,
args: {
...Default.args,
showLogo: false,
layout: null,
toggleScreenSharing: undefined,
},
globals: {
viewport: { value: "mobile2", isRotated: false },
},
parameters: {
...Default.parameters,
},
};
export const LobbyRecentButton: Story = {
...Default,
args: {
...Default.args,
children: <Link>Back To Recents</Link>,
showLogo: false,
layout: null,
toggleScreenSharing: undefined,
},
parameters: {
...Default.parameters,
},
};
export const LobbyRecentButtonMobile: Story = {
...Default,
args: {
+20 -165
View File
@@ -7,14 +7,11 @@ Please see LICENSE in the repository root for full details.
import { type FC, type JSX, type Ref, useMemo } from "react";
import classNames from "classnames";
import { useTranslation } from "react-i18next";
import LogoMark from "../icons/LogoMark.svg?react";
import LogoType from "../icons/LogoType.svg?react";
import {
EndCallButton,
MicButton,
VideoButton,
ShareScreenButton,
SettingsButton,
ReactionToggleButton,
@@ -23,23 +20,13 @@ import {
type ReactionData,
} from "../button";
import styles from "./CallFooter.module.css";
import {
MediaMuteAndSwitchButton,
type MenuOptions,
} from "./MediaMuteAndSwitchButton";
import { type Behavior } from "../state/Behavior";
import { type ViewModel } from "../state/ViewModel";
import { useBehavior } from "../useBehavior";
import { type LayoutSwitchViewModel } from "../state/LayoutSwitchViewModel";
import { LayoutSwitch } from "../room/LayoutSwitch";
import { type BackgroundEffectGridItem } from "./BackgroundEffectGrid";
import { SelfPreview } from "./SelfPreview";
import { type UnusableReason } from "../tracks/backgroundImages";
import { type LocalVideoMediaTrack } from "@element-hq/matrixrtc-sdk";
export interface BackgroundImageRefusal {
reason: UnusableReason | "not-kept";
}
import { type MediaMenuViewModel } from "./MediaMenuViewModel";
import { MediaMenuButton } from "./MediaMenuButton";
export interface AudioOutputSwitcher {
targetOutput: string;
@@ -61,16 +48,6 @@ export interface AudioOutputSwitcher {
*/
export type FooterSnapshot = FooterActions & FooterState;
export interface FooterActions {
/** Also controls if the audioMute button is disabled */
toggleAudio: (() => void) | undefined;
/** Also controls if the videoMute button is disabled */
toggleVideo: (() => void) | undefined;
/** Undefined where background effects can't be chosen. */
selectBackgroundEffect: ((id: string) => void) | undefined;
/** Undefined where no background can be added. */
addBackgroundImage: ((file: File) => void) | undefined;
/** Removes an added background by its option id; never the one in force. */
removeBackgroundEffect: ((id: string) => void) | undefined;
toggleScreenSharing: (() => void) | undefined;
/** Also controls if the settings button is visible */
openSettings: (() => void) | undefined;
@@ -80,22 +57,8 @@ export interface FooterActions {
// we do not use any ? optional properties so that the vm type is including all fields.
export interface FooterState {
audioEnabled: boolean;
audioBusy: boolean;
videoEnabled: boolean;
videoBusy: boolean;
/** The background effect in force, as its option id. */
backgroundEffect: string;
/** Every effect on offer, in the order they are shown. */
backgroundEffects: BackgroundEffectGridItem[];
/** What the user is told about effects here, if anything. */
backgroundEffectNotice: "unavailable" | "slow" | undefined;
/** Whether the first effect chosen is still being prepared. */
backgroundEffectSettling: boolean;
/** Why the last file offered couldn't be kept, if it couldn't. */
backgroundImageRefusal: BackgroundImageRefusal | undefined;
/** The camera to preview, with the effect in force; null while it is off. */
cameraTrack: LocalVideoMediaTrack | null;
audioMenuVm: MediaMenuViewModel;
cameraMenuVm: MediaMenuViewModel;
showFooter: boolean;
/* This is needed for WindowMode = "flat" */
@@ -122,19 +85,6 @@ export interface FooterState {
// debug stuff
debugTileLayout: boolean;
tileStoreGeneration: number | undefined;
/** Providing no options `[]` or `undefined` will imply that we dont have a audio fast switcher */
audioOptions: MenuOptions[];
/** Output (speaker) devices. */
audioOutputOptions: MenuOptions[];
/** Providing no options `[]` or `undefined` will imply that we dont have a audio fast switcher */
videoOptions: MenuOptions[];
selectedAudio: string | undefined;
selectedAudioOutput: string | undefined;
selectedVideo: string | undefined;
selectAudioButtonOption: ((deviceId: string) => void) | undefined;
selectAudioOutputOption: ((deviceId: string) => void) | undefined;
selectVideoButtonOption: ((option: string) => void) | undefined;
}
export interface FooterProps {
@@ -150,19 +100,14 @@ export const CallFooter: FC<FooterProps> = ({
children,
vm,
}) => {
const { t } = useTranslation();
const asOverlay = useBehavior(vm.asOverlay$);
const showFooter = useBehavior(vm.showFooter$);
const hideControls = useBehavior(vm.hideControls$);
const showModals = useBehavior(vm.showModals$);
const layoutSwitchVm = useBehavior(vm.layoutSwitchVm$);
const audioMenuVm = useBehavior(vm.audioMenuVm$);
const cameraMenuVm = useBehavior(vm.cameraMenuVm$);
const openSettings = useBehavior(vm.openSettings$);
const audioEnabled = useBehavior(vm.audioEnabled$);
const audioBusy = useBehavior(vm.audioBusy$);
const videoEnabled = useBehavior(vm.videoEnabled$);
const videoBusy = useBehavior(vm.videoBusy$);
const toggleAudio = useBehavior(vm.toggleAudio$);
const toggleVideo = useBehavior(vm.toggleVideo$);
const sharingScreen = useBehavior(vm.sharingScreen$);
const toggleScreenSharing = useBehavior(vm.toggleScreenSharing$);
const reactionIdentifier = useBehavior(vm.reactionIdentifier$);
@@ -170,38 +115,6 @@ export const CallFooter: FC<FooterProps> = ({
const audioOutputSwitcher = useBehavior(vm.audioOutputSwitcher$);
const hangup = useBehavior(vm.hangup$);
const debugTileLayout = useBehavior(vm.debugTileLayout$);
const videoOptions = useBehavior(vm.videoOptions$);
const selectedVideo = useBehavior(vm.selectedVideo$);
const audioOptions = useBehavior(vm.audioOptions$);
const selectedAudio = useBehavior(vm.selectedAudio$);
const selectAudioButtonOption = useBehavior(vm.selectAudioButtonOption$);
const audioOutputOptions = useBehavior(vm.audioOutputOptions$);
const selectedAudioOutput = useBehavior(vm.selectedAudioOutput$);
const selectAudioOutputOption = useBehavior(vm.selectAudioOutputOption$);
const selectVideoButtonOption = useBehavior(vm.selectVideoButtonOption$);
const backgroundEffect = useBehavior(vm.backgroundEffect$);
const selectBackgroundEffect = useBehavior(vm.selectBackgroundEffect$);
const backgroundEffectNotice = useBehavior(vm.backgroundEffectNotice$);
const backgroundEffectSettling = useBehavior(vm.backgroundEffectSettling$);
const addBackgroundImage = useBehavior(vm.addBackgroundImage$);
const removeBackgroundEffect = useBehavior(vm.removeBackgroundEffect$);
const cameraTrack = useBehavior(vm.cameraTrack$);
const refusal = useBehavior(vm.backgroundImageRefusal$);
const refusalMessage = useMemo(() => {
switch (refusal?.reason) {
case undefined:
return undefined;
case "not-an-image":
return { text: t("error.background_not_an_image") };
case "animated":
return { text: t("error.background_animated") };
case "undecodable":
return { text: t("error.background_undecodable") };
case "not-kept":
return { text: t("error.background_not_kept") };
}
}, [refusal, t]);
const backgroundEffects = useBehavior(vm.backgroundEffects$);
const buttonSize = useBehavior(vm.buttonSize$);
const showLogo = useBehavior(vm.showLogo$);
@@ -221,78 +134,20 @@ export const CallFooter: FC<FooterProps> = ({
);
}
if ((audioOptions?.length ?? 0) > 0) {
buttons.push(
<MediaMuteAndSwitchButton
key="audio"
iconsAndLabels="audio"
enabled={audioEnabled ?? false}
busy={audioBusy ?? false}
onMuteClick={toggleAudio}
data-testid="incall_mute"
options={audioOptions}
selectedOption={selectedAudio}
onSelect={selectAudioButtonOption}
outputOptions={audioOutputOptions}
selectedOutputOption={selectedAudioOutput}
onSelectOutput={selectAudioOutputOption}
/>,
);
} else {
buttons.push(
<MicButton
size={buttonSize}
key="audio"
enabled={audioEnabled ?? false}
busy={audioBusy ?? false}
onClick={toggleAudio}
disabled={(audioBusy ?? false) || toggleAudio === undefined}
data-testid="incall_mute"
/>,
);
}
if ((videoOptions?.length ?? 0) > 0) {
buttons.push(
<MediaMuteAndSwitchButton
key="video"
iconsAndLabels="video"
enabled={videoEnabled ?? false}
busy={videoBusy ?? false}
onMuteClick={toggleVideo}
options={videoOptions}
selectedOption={selectedVideo}
onSelect={selectVideoButtonOption}
backgroundEffects={backgroundEffects}
selectedBackgroundEffect={backgroundEffect}
onSelectBackgroundEffect={selectBackgroundEffect}
backgroundEffectSettling={backgroundEffectSettling}
onAddBackgroundImage={addBackgroundImage}
onRemoveBackgroundEffect={removeBackgroundEffect}
selfPreview={<SelfPreview track={cameraTrack} />}
backgroundImageRefusal={refusalMessage}
backgroundEffectNotice={
backgroundEffectNotice === "unavailable"
? t("background_effects.unavailable")
: backgroundEffectNotice === "slow"
? t("background_effects.slow")
: undefined
}
/>,
);
} else {
buttons.push(
<VideoButton
size={buttonSize}
key="video"
enabled={videoEnabled ?? false}
busy={videoBusy ?? false}
onClick={toggleVideo}
disabled={(videoBusy ?? false) || toggleVideo === undefined}
data-testid="incall_videomute"
/>,
);
}
buttons.push(
<MediaMenuButton
key="audio"
kind="audio"
vm={audioMenuVm}
size={buttonSize}
/>,
<MediaMenuButton
key="video"
kind="video"
vm={cameraMenuVm}
size={buttonSize}
/>,
);
if (toggleScreenSharing !== undefined) {
buttons.push(
+63 -446
View File
@@ -5,18 +5,15 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { afterEach, describe, expect, it, vi } from "vitest";
import { BehaviorSubject } from "rxjs";
import { type LocalVideoMediaTrack } from "@element-hq/matrixrtc-sdk";
import { describe, expect, it, vi } from "vitest";
import {
flushPromises,
testScope,
mockMuteStates,
mockMediaDevices,
mockVideoTrack,
} from "../utils/test";
import { type Behavior, constant } from "../state/Behavior";
import { constant } from "../state/Behavior";
import { type BackgroundEffectsState } from "../state/BackgroundEffects";
import type { CallViewModel } from "../state/CallViewModel/CallViewModel";
import type { Layout } from "../state/layout-types";
@@ -27,15 +24,6 @@ import {
createLobbyFooterViewModel,
} from "./CallFooterViewModel";
import { HeaderStyle } from "../UrlParams";
import { backgroundEffect as backgroundEffectSetting } from "../settings/settings";
import { shippedBackgrounds } from "../tracks/backgroundEffectCatalog";
import type * as BackgroundImages from "../tracks/backgroundImages";
import {
type AddedBackground,
addedBackgrounds,
maxAddedBackgrounds,
UnusableImage,
} from "../tracks/backgroundImages";
const platformMock = vi.hoisted(() => vi.fn(() => "desktop"));
vi.mock("../Platform", () => ({
@@ -44,35 +32,6 @@ vi.mock("../Platform", () => ({
},
}));
// The SDK's own check needs WebGL and canvas APIs jsdom does not have.
const sdkSupportMock = vi.hoisted(() => vi.fn(() => false));
const modernRouteMock = vi.hoisted(() => vi.fn(() => true));
vi.mock("@livekit/track-processors", () => ({
supportsBackgroundProcessors: (): boolean => sdkSupportMock(),
supportsModernBackgroundProcessors: (): boolean => modernRouteMock(),
}));
const store = vi.hoisted(() => ({
add: vi.fn<(file: Blob) => Promise<string>>(),
remove: vi.fn<(id: string) => Promise<void>>(),
}));
vi.mock("../tracks/backgroundImages", async (original) => {
const { BehaviorSubject } = await import("rxjs");
return {
...(await original<typeof BackgroundImages>()),
addedBackgrounds: {
added$: new BehaviorSubject<AddedBackground[] | undefined>([]),
add: store.add,
remove: store.remove,
},
};
});
const outputSelectionMock = vi.hoisted(() => vi.fn(() => true));
vi.mock("livekit-client", () => ({
supportsAudioOutputSelection: (): boolean => outputSelectionMock(),
}));
/**
* Returns the minimum set of CallViewModel fields required by
* createCallFooterViewModel, with all other properties stubbed to
@@ -113,424 +72,82 @@ const pipLayout: Layout = {
spotlight: {} as SpotlightTileViewModel,
};
const noPipeline = constant<BackgroundEffectsState>({
supported: false,
const pipeline = constant<BackgroundEffectsState>({
supported: true,
processor: undefined,
});
/** The provider's verdict, which the SDK's check stands for here. */
function pipelineAsTheSdkSays(): Behavior<BackgroundEffectsState> {
return constant({ supported: sdkSupportMock(), processor: undefined });
}
const twoMicsAndOneCamMediaDevices = mockMediaDevices({
audioInput: {
available$: constant(
new Map<string, DeviceLabel>([
["mic1", { type: "number", number: 1 }],
["mic2", { type: "name", name: "Microphone 2" }],
]),
),
selected$: constant(undefined),
select: vi.fn(),
},
videoInput: {
available$: constant(
new Map<string, DeviceLabel>([
["cam1", { type: "name", name: "Camera 1" }],
]),
),
selected$: constant(undefined),
select: vi.fn(),
},
const oneOfEach = {
available$: constant(
new Map<string, DeviceLabel>([["1", { type: "number", number: 1 }]]),
),
selected$: constant(undefined),
select: vi.fn(),
};
const devices = mockMediaDevices({
audioInput: oneOfEach,
videoInput: oneOfEach,
});
describe("createCallFooterViewModel", () => {
describe("selectAudioOutputOption", () => {
function buildFooterVm(): ReturnType<typeof createCallFooterViewModel> {
platformMock.mockReturnValue("desktop");
return createCallFooterViewModel(
testScope(),
buildMinimalCallViewModel(gridLayout),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
noPipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
}
it("is withheld where the platform cannot route audio to a chosen device", () => {
outputSelectionMock.mockReturnValue(false);
expect(buildFooterVm().selectAudioOutputOption$.value).toBeUndefined();
});
it("is offered where the platform can route audio to a chosen device", () => {
outputSelectionMock.mockReturnValue(true);
expect(buildFooterVm().selectAudioOutputOption$.value).toBeDefined();
});
});
describe("audioOutputOptions", () => {
it("is an empty list, not absent, where the platform enumerates no outputs", () => {
platformMock.mockReturnValue("desktop");
outputSelectionMock.mockReturnValue(true);
const vm = createCallFooterViewModel(
testScope(),
buildMinimalCallViewModel(gridLayout),
mockMuteStates(),
mockMediaDevices({
audioInput: {
available$: constant(
new Map<string, DeviceLabel>([
["mic1", { type: "name", name: "Microphone 1" }],
]),
),
selected$: constant(undefined),
select: vi.fn(),
},
// As Safari: no outputs listed.
audioOutput: {
available$: constant(new Map<string, DeviceLabel>()),
selected$: constant(undefined),
select: vi.fn(),
},
}),
noPipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
// Empty, not undefined: undefined would hide the section.
expect(vm.audioOutputOptions$.value).toEqual([]);
});
});
describe("audioOptions and videoOptions", () => {
function checkEmptyFor(platform: string, layout: Layout): void {
it.each([
["desktop", "grid", true, gridLayout],
["ios", "grid", false, gridLayout],
["desktop", "pip", false, pipLayout],
] as const)(
"on %s in a %s layout, offers the device menus: %s",
(platform, _, offered, layout) => {
platformMock.mockReturnValue(platform);
const vm = createCallFooterViewModel(
testScope(),
buildMinimalCallViewModel(layout),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
noPipeline,
devices,
pipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
const audio = vm.audioMenuVm$.value;
const camera = vm.cameraMenuVm$.value;
expect(audio.options$.value.length > 0).toBe(offered);
expect(camera.options$.value.length > 0).toBe(offered);
expect(camera.selectBackgroundEffect$.value !== undefined).toBe(offered);
},
);
expect(vm.audioOptions$.value).toEqual([]);
expect(vm.videoOptions$.value).toEqual([]);
}
it("are both empty when the platform is iOS", () => {
checkEmptyFor("ios", gridLayout);
});
it("are both empty when the layout is pip", () => {
checkEmptyFor("desktop", pipLayout);
});
it("are populated when the platform is desktop and the layout is not PiP", () => {
platformMock.mockReturnValue("desktop");
const vm = createCallFooterViewModel(
testScope(),
buildMinimalCallViewModel(gridLayout),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
noPipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
expect(vm.audioOptions$?.value).toEqual([
{
id: "mic1",
label: {
number: 1,
type: "number",
},
},
{
id: "mic2",
label: {
name: "Microphone 2",
type: "name",
},
},
]);
expect(vm.videoOptions$?.value).toEqual([
{
id: "cam1",
label: {
name: "Camera 1",
type: "name",
},
},
]);
});
it("previews the call's camera", () => {
const track = mockVideoTrack({});
const vm = createCallFooterViewModel(
testScope(),
{ ...buildMinimalCallViewModel(gridLayout), camera$: constant(track) },
mockMuteStates(),
devices,
pipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
expect(vm.cameraMenuVm$.value.cameraTrack$.value).toBe(track);
});
describe("background effects", () => {
afterEach(() => backgroundEffectSetting.setValue("none"));
// The lobby, because in a call the whole device switcher is already
// withheld on a phone, whatever the verdict says.
function lobbyOn(
platform: string,
): ReturnType<typeof createLobbyFooterViewModel> {
platformMock.mockReturnValue(platform);
return createLobbyFooterViewModel(
testScope(),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
pipelineAsTheSdkSays(),
/* camera$ */ constant(null),
/* openSettings */ undefined,
/* hangup */ undefined,
/* showLogo */ false,
);
}
it("offers them on a phone whose browser can run them", () => {
sdkSupportMock.mockReturnValue(true);
expect(lobbyOn("ios").selectBackgroundEffect$.value).toBeDefined();
});
it("offers them on a desktop whose browser can run them", () => {
sdkSupportMock.mockReturnValue(true);
expect(lobbyOn("desktop").selectBackgroundEffect$.value).toBeDefined();
});
it("offers nothing where the browser itself cannot run them", () => {
sdkSupportMock.mockReturnValue(false);
expect(lobbyOn("desktop").selectBackgroundEffect$.value).toBeUndefined();
expect(lobbyOn("desktop").addBackgroundImage$.value).toBeUndefined();
});
it("puts no effect in force where the browser cannot run them", () => {
backgroundEffectSetting.setValue("blur");
sdkSupportMock.mockReturnValue(false);
expect(lobbyOn("desktop").backgroundEffect$.value).toBe("none");
sdkSupportMock.mockReturnValue(true);
expect(lobbyOn("desktop").backgroundEffect$.value).toBe("blur");
});
it("stores the effect chosen", () => {
sdkSupportMock.mockReturnValue(true);
const vm = lobbyOn("desktop");
vm.selectBackgroundEffect$.value?.("image:arc");
expect(vm.backgroundEffect$.value).toBe("image:arc");
// What isn't an effect on offer is stored as none.
vm.selectBackgroundEffect$.value?.("image:gone");
expect(backgroundEffectSetting.getValue()).toBe("none");
});
it("says they run slowly where only the slower route exists", () => {
sdkSupportMock.mockReturnValue(true);
modernRouteMock.mockReturnValue(false);
const slow = lobbyOn("desktop");
expect(slow.backgroundEffectNotice$.value).toBe("slow");
expect(slow.selectBackgroundEffect$.value).toBeDefined();
modernRouteMock.mockReturnValue(true);
expect(lobbyOn("desktop").backgroundEffectNotice$.value).toBeUndefined();
});
it("offers every effect in order, the added ones removable", () => {
sdkSupportMock.mockReturnValue(true);
const added$ = addedBackgrounds.added$ as BehaviorSubject<
AddedBackground[] | undefined
>;
added$.next([{ id: "mine", url: "blob:mine" }]);
expect(lobbyOn("desktop").backgroundEffects$.value).toEqual([
{ id: "none", kind: "none", removable: false },
{ id: "blur", kind: "blur", removable: false },
...shippedBackgrounds.map((background) => ({
id: `image:${background.id}`,
kind: "image",
imageUrl: background.imagePath,
removable: false,
})),
{
id: "added:mine",
kind: "image",
imageUrl: "blob:mine",
removable: true,
},
]);
added$.next([]);
});
it("says they are unavailable where they cannot be chosen", () => {
sdkSupportMock.mockReturnValue(false);
expect(lobbyOn("desktop").backgroundEffectNotice$.value).toBe(
"unavailable",
);
});
it("passes on the wait for the first effect", () => {
platformMock.mockReturnValue("desktop");
const pipeline$ = new BehaviorSubject<BackgroundEffectsState>({
supported: true,
processor: undefined,
wait: "settling",
});
const vm = createLobbyFooterViewModel(
testScope(),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
pipeline$,
/* camera$ */ constant(null),
/* openSettings */ undefined,
/* hangup */ undefined,
/* showLogo */ false,
);
expect(vm.backgroundEffectSettling$.value).toBe(true);
pipeline$.next({ ...pipeline$.value, wait: undefined });
expect(vm.backgroundEffectSettling$.value).toBe(false);
});
it("offers nothing once the pipeline fails to build, keeping the choice", () => {
platformMock.mockReturnValue("desktop");
backgroundEffectSetting.setValue("blur");
const pipeline$ = new BehaviorSubject<BackgroundEffectsState>({
supported: true,
processor: undefined,
});
const vm = createLobbyFooterViewModel(
testScope(),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
pipeline$,
/* camera$ */ constant(null),
/* openSettings */ undefined,
/* hangup */ undefined,
/* showLogo */ false,
);
expect(vm.backgroundEffect$.value).toBe("blur");
pipeline$.next({ supported: false, processor: undefined });
expect(vm.selectBackgroundEffect$.value).toBeUndefined();
expect(vm.addBackgroundImage$.value).toBeUndefined();
expect(vm.backgroundEffect$.value).toBe("none");
expect(backgroundEffectSetting.getValue()).toBe("blur");
});
it("adding is unavailable at the limit", () => {
sdkSupportMock.mockReturnValue(true);
const added$ = addedBackgrounds.added$ as BehaviorSubject<
AddedBackground[] | undefined
>;
const vm = lobbyOn("desktop");
expect(vm.addBackgroundImage$.value).toBeDefined();
added$.next(
Array.from({ length: maxAddedBackgrounds }, (_, i) => ({
id: `${i}`,
url: `blob:${i}`,
})),
);
expect(vm.addBackgroundImage$.value).toBeUndefined();
added$.next(added$.value!.slice(1));
expect(vm.addBackgroundImage$.value).toBeDefined();
added$.next([]);
});
it("says why each refused file was refused", async () => {
sdkSupportMock.mockReturnValue(true);
const vm = lobbyOn("desktop");
store.add.mockRejectedValue(new UnusableImage("animated"));
vm.addBackgroundImage$.value!(new File(["x"], "a.gif"));
await flushPromises();
const first = vm.backgroundImageRefusal$.value;
expect(first).toEqual({ reason: "animated" });
// The same again is a refusal of its own, so it is shown again.
vm.addBackgroundImage$.value!(new File(["x"], "a.gif"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value).toEqual({ reason: "animated" });
expect(vm.backgroundImageRefusal$.value).not.toBe(first);
store.add.mockRejectedValue(new Error("quota"));
vm.addBackgroundImage$.value!(new File(["x"], "b.png"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value).toEqual({ reason: "not-kept" });
store.add.mockResolvedValue("kept");
vm.addBackgroundImage$.value!(new File(["x"], "c.png"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value).toBeUndefined();
});
it("never removes the background in force", () => {
sdkSupportMock.mockReturnValue(true);
store.remove.mockResolvedValue();
const vm = lobbyOn("desktop");
backgroundEffectSetting.setValue("added:worn");
vm.removeBackgroundEffect$.value!("added:worn");
expect(store.remove).not.toHaveBeenCalled();
vm.removeBackgroundEffect$.value!("added:spare");
expect(store.remove).toHaveBeenCalledWith("spare");
});
it("previews the lobby's camera while there is one", () => {
const track = mockVideoTrack({});
const camera$ = new BehaviorSubject<LocalVideoMediaTrack | null>(track);
const vm = createLobbyFooterViewModel(
testScope(),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
noPipeline,
camera$,
/* openSettings */ undefined,
/* hangup */ undefined,
/* showLogo */ false,
);
expect(vm.cameraTrack$.value).toBe(track);
// The lobby releases the camera when it is turned off
camera$.next(null);
expect(vm.cameraTrack$.value).toBeNull();
});
it("previews the call's camera only while it is not muted", () => {
const muted$ = new BehaviorSubject(false);
const track = mockVideoTrack({ muted$ });
const vm = createCallFooterViewModel(
testScope(),
{ ...buildMinimalCallViewModel(gridLayout), camera$: constant(track) },
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
noPipeline,
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
expect(vm.cameraTrack$.value).toBe(track);
muted$.next(true);
expect(vm.cameraTrack$.value).toBeNull();
muted$.next(false);
expect(vm.cameraTrack$.value).toBe(track);
});
it("availability is the same before and during a call", () => {
for (const supported of [true, false]) {
sdkSupportMock.mockReturnValue(supported);
const lobby = lobbyOn("desktop");
const inCall = createCallFooterViewModel(
testScope(),
buildMinimalCallViewModel(gridLayout),
mockMuteStates(),
twoMicsAndOneCamMediaDevices,
pipelineAsTheSdkSays(),
/* reactionIdentifier */ undefined,
{ showControls: true, header: HeaderStyle.Standard },
);
const offeredInLobby =
lobby.selectBackgroundEffect$.value !== undefined;
expect(inCall.selectBackgroundEffect$.value !== undefined).toBe(
offeredInLobby,
);
expect(offeredInLobby).toBe(supported);
}
});
});
describe("createLobbyFooterViewModel", () => {
it("offers the device menus even on a phone, previewing the lobby's camera", () => {
platformMock.mockReturnValue("ios");
const track = mockVideoTrack({});
const vm = createLobbyFooterViewModel(
testScope(),
mockMuteStates(),
devices,
pipeline,
constant(track),
/* openSettings */ undefined,
/* hangup */ undefined,
/* showLogo */ false,
);
const camera = vm.cameraMenuVm$.value;
expect(vm.audioMenuVm$.value.options$.value).not.toEqual([]);
expect(camera.options$.value).not.toEqual([]);
expect(camera.selectBackgroundEffect$.value).toBeDefined();
expect(camera.cameraTrack$.value).toBe(track);
});
});
+54 -305
View File
@@ -5,253 +5,24 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import {
BehaviorSubject,
combineLatest,
distinctUntilChanged,
map,
type Observable,
of,
switchMap,
} from "rxjs";
import { supportsAudioOutputSelection } from "livekit-client";
import { combineLatest, map, type Observable } from "rxjs";
import { type LocalVideoMediaTrack } from "@element-hq/matrixrtc-sdk";
import { supportsModernBackgroundProcessors } from "@livekit/track-processors";
import { logger } from "matrix-js-sdk/lib/logger";
import {
parseEffect,
serializeEffect,
shippedBackgrounds,
} from "../tracks/backgroundEffectCatalog";
import {
type AddedBackground,
addedBackgrounds,
maxAddedBackgrounds,
UnusableImage,
} from "../tracks/backgroundImages";
import { type CallViewModel } from "../state/CallViewModel/CallViewModel";
import { type BackgroundEffectsState } from "../state/BackgroundEffects";
import { type MenuOptions } from "./MediaMuteAndSwitchButton";
import { type MediaDevices } from "../state/MediaDevices";
import {
backgroundEffect as backgroundEffectSetting,
debugTileLayout as debugTileLayoutSetting,
} from "../settings/settings";
import { debugTileLayout as debugTileLayoutSetting } from "../settings/settings";
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 { HeaderStyle } from "../UrlParams";
import { platform } from "../Platform";
import { type BackgroundImageRefusal, type FooterSnapshot } from "./CallFooter";
import { type BackgroundEffectGridItem } from "./BackgroundEffectGrid";
/**
* Shared helper: maps MuteStates into the audio/video enabled + toggle behaviors
* needed by FooterSnapshot.
*/
function buildMuteBehaviors(
scope: ObservableScope,
muteStates: MuteStates,
): Pick<
ViewModel<FooterSnapshot>,
| "audioEnabled$"
| "audioBusy$"
| "toggleAudio$"
| "videoEnabled$"
| "videoBusy$"
| "toggleVideo$"
> {
return {
audioEnabled$: muteStates.audio.enabled$,
audioBusy$: muteStates.audio.syncing$,
toggleAudio$: scope.behavior(
muteStates.audio.toggle$.pipe(map((t) => t ?? undefined)),
),
videoEnabled$: muteStates.video.enabled$,
videoBusy$: muteStates.video.syncing$,
toggleVideo$: scope.behavior(
muteStates.video.toggle$.pipe(map((t) => t ?? undefined)),
),
};
}
/**
* Shared helper: maps MediaDevices into the audio/video device-list behaviors
* needed by FooterSnapshot (options, selection, callbacks, background effect).
*/
function buildDeviceBehaviors(
scope: ObservableScope,
mediaDevices: MediaDevices,
/** return empty arrays for audioOptions and videoOptions*/
disableSwitcher$: Behavior<boolean>,
backgroundEffectsState$: Observable<BackgroundEffectsState>,
/** The camera as the pipeline has it, for the menu's preview. */
camera$: Observable<LocalVideoMediaTrack | null | undefined>,
): Pick<
ViewModel<FooterSnapshot>,
| "audioOptions$"
| "selectedAudio$"
| "selectAudioButtonOption$"
| "audioOutputOptions$"
| "selectedAudioOutput$"
| "selectAudioOutputOption$"
| "videoOptions$"
| "selectedVideo$"
| "selectVideoButtonOption$"
| "backgroundEffect$"
| "selectBackgroundEffect$"
| "backgroundEffects$"
| "backgroundEffectNotice$"
| "backgroundEffectSettling$"
| "addBackgroundImage$"
| "backgroundImageRefusal$"
| "removeBackgroundEffect$"
| "cameraTrack$"
> {
const options$ = (
available$: Behavior<Map<string, MenuOptions["label"]>>,
): Observable<MenuOptions[]> =>
disableSwitcher$.pipe(
switchMap((disable) =>
disable
? constant([] as MenuOptions[])
: available$.pipe(
map((available) =>
[...available.entries()].map(([id, label]) => ({ id, label })),
),
),
),
);
// Also false once the pipeline has failed to build this session.
const supported$ = backgroundEffectsState$.pipe(
map(({ supported }) => supported === true),
distinctUntilChanged(),
);
const slow = !supportsModernBackgroundProcessors();
const offered$ = combineLatest([disableSwitcher$, supported$]).pipe(
map(([switcherDisabled, supported]) => !switcherDisabled && supported),
);
// A new object for each refusal, so the same one twice is shown twice.
const refusal$ = new BehaviorSubject<BackgroundImageRefusal | undefined>(
undefined,
);
return {
audioOptions$: scope.behavior(options$(mediaDevices.audioInput.available$)),
selectedAudio$: scope.behavior(
mediaDevices.audioInput.selected$.pipe(map((s) => s?.id)),
),
selectAudioButtonOption$: constant(mediaDevices.audioInput.select),
audioOutputOptions$: scope.behavior(
options$(mediaDevices.audioOutput.available$),
),
selectedAudioOutput$: scope.behavior(
mediaDevices.audioOutput.selected$.pipe(map((s) => s?.id)),
),
// Withheld where the platform can't route audio to a chosen device, which
// disables the speaker section.
selectAudioOutputOption$: constant(
supportsAudioOutputSelection()
? mediaDevices.audioOutput.select
: undefined,
),
videoOptions$: scope.behavior(options$(mediaDevices.videoInput.available$)),
selectedVideo$: scope.behavior(
mediaDevices.videoInput.selected$.pipe(map((s) => s?.id)),
),
selectVideoButtonOption$: constant(mediaDevices.videoInput.select),
backgroundEffect$: scope.behavior(
combineLatest([backgroundEffectSetting.value$, supported$]).pipe(
map(([raw, supported]) =>
supported ? serializeEffect(parseEffect(raw)) : "none",
),
),
),
selectBackgroundEffect$: scope.behavior(
offered$.pipe(
map((offered) =>
offered
? (id: string): void =>
backgroundEffectSetting.setValue(
serializeEffect(parseEffect(id)),
)
: undefined,
),
),
),
backgroundEffects$: scope.behavior(
addedBackgrounds.added$.pipe(
map((added) => backgroundEffectChoices(added ?? [])),
),
),
backgroundEffectNotice$: scope.behavior(
offered$.pipe(
map((offered) =>
!offered ? "unavailable" : slow ? "slow" : undefined,
),
),
),
backgroundEffectSettling$: scope.behavior(
backgroundEffectsState$.pipe(
map(({ wait }) => wait !== undefined),
distinctUntilChanged(),
),
false,
),
// Kept and offered, not put on: that waits for the user to choose it.
addBackgroundImage$: scope.behavior(
combineLatest([offered$, addedBackgrounds.added$]).pipe(
map(([offered, added]) =>
offered && (added?.length ?? 0) < maxAddedBackgrounds
? (file: File): void => {
refusal$.next(undefined);
addedBackgrounds.add(file).catch((e) => {
logger.warn("Could not keep that background", e);
refusal$.next({
reason: e instanceof UnusableImage ? e.reason : "not-kept",
});
});
}
: undefined,
),
),
),
backgroundImageRefusal$: refusal$,
// None while muted: the call mutes its track rather than releasing it.
cameraTrack$: scope.behavior(
camera$.pipe(
switchMap((camera) =>
camera
? camera.muted$.pipe(map((muted) => (muted ? null : camera)))
: of(null),
),
),
null,
),
// Never the one in force: taking it away would leave nothing chosen.
removeBackgroundEffect$: scope.behavior(
offered$.pipe(
map((offered) =>
offered
? (optionId: string): void => {
const effect = parseEffect(optionId);
if (effect.kind !== "added") return;
if (backgroundEffectSetting.getValue() === optionId) return;
addedBackgrounds
.remove(effect.id)
.catch((e) =>
logger.warn("Could not remove that background", e),
);
}
: undefined,
),
),
),
};
}
import { type FooterSnapshot } from "./CallFooter";
import {
createAudioMenuViewModel,
createCameraMenuViewModel,
} from "./MediaMenuViewModel";
/**
* Creates the ViewModel for the CallFooter.
@@ -286,13 +57,23 @@ export function createCallFooterViewModel(
isPip$.pipe(map((isPip) => isPip || platform !== "desktop")),
);
return {
...buildMuteBehaviors(scope, muteStates),
...buildDeviceBehaviors(
scope,
mediaDevices,
disableDeviceSwitcher$,
backgroundEffectsState$,
callModel.camera$,
audioMenuVm$: constant(
createAudioMenuViewModel(
scope,
muteStates,
mediaDevices,
disableDeviceSwitcher$,
),
),
cameraMenuVm$: constant(
createCameraMenuViewModel(
scope,
muteStates,
mediaDevices,
disableDeviceSwitcher$,
backgroundEffectsState$,
callModel.camera$,
),
),
// candidat to move into the FooterViewModel
showFooter$: callModel.showFooter$,
@@ -372,72 +153,40 @@ export function createLobbyFooterViewModel(
hangup: (() => void) | undefined,
showLogo: boolean,
): ViewModel<FooterSnapshot> {
return {
...createStaticViewModel({
// we can safly skip any props that we do not need.
// The view model will then have less keys.
// But as soon as we call `useViewModel` and convert back to a snapshot the missing props will
// be correcty matching the snapshot type.
showLogo,
hideControls: false,
asOverlay: false,
showModals: true,
buttonSize: "lg",
openSettings,
hangup,
debugTileLayout: false,
showFooter: true,
toggleAudio: undefined,
toggleVideo: undefined,
toggleScreenSharing: undefined,
audioEnabled: undefined,
audioBusy: false,
videoEnabled: undefined,
videoBusy: false,
layoutSwitchVm: null,
sharingScreen: false,
audioOutputSwitcher: undefined,
reactionIdentifier: undefined,
reactionData: undefined,
tileStoreGeneration: undefined,
audioOptions: undefined,
audioOutputOptions: undefined,
videoOptions: undefined,
selectedAudio: undefined,
selectedAudioOutput: undefined,
selectedVideo: undefined,
selectAudioButtonOption: undefined,
selectAudioOutputOption: undefined,
selectVideoButtonOption: undefined,
}),
...buildMuteBehaviors(scope, muteStates),
...buildDeviceBehaviors(
return createStaticViewModel({
// we can safly skip any props that we do not need.
// The view model will then have less keys.
// But as soon as we call `useViewModel` and convert back to a snapshot the missing props will
// be correcty matching the snapshot type.
showLogo,
hideControls: false,
asOverlay: false,
showModals: true,
buttonSize: "lg",
openSettings,
hangup,
debugTileLayout: false,
showFooter: true,
toggleScreenSharing: undefined,
layoutSwitchVm: null,
sharingScreen: false,
audioOutputSwitcher: undefined,
reactionIdentifier: undefined,
reactionData: undefined,
tileStoreGeneration: undefined,
audioMenuVm: createAudioMenuViewModel(
scope,
muteStates,
mediaDevices,
constant(false),
),
cameraMenuVm: createCameraMenuViewModel(
scope,
muteStates,
mediaDevices,
constant(false),
backgroundEffectsState$,
camera$,
),
};
}
function backgroundEffectChoices(
added: AddedBackground[],
): BackgroundEffectGridItem[] {
return [
{ id: serializeEffect({ kind: "none" }), kind: "none", removable: false },
{ id: serializeEffect({ kind: "blur" }), kind: "blur", removable: false },
...shippedBackgrounds.map((background) => ({
id: serializeEffect({ kind: "shipped", id: background.id }),
kind: "image" as const,
imageUrl: background.imagePath,
removable: false,
})),
...added.map((background) => ({
id: serializeEffect({ kind: "added", id: background.id }),
kind: "image" as const,
imageUrl: background.url,
removable: true,
})),
];
});
}
+193
View File
@@ -0,0 +1,193 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { expect, fn, userEvent, within } from "storybook/test";
import { type JSX, type ReactNode } from "react";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { MediaMenuButton } from "./MediaMenuButton";
import { type MediaMenuSnapshot } from "./MediaMenuViewModel";
import { useStaticViewModel } from "../state/ViewModel";
import { MediaDevicesContext } from "../MediaDevicesContext";
import { MediaDevices } from "../state/MediaDevices";
import { globalScope } from "../state/ObservableScope";
const mediaDevices = new MediaDevices(globalScope, {
controlledAudioDevices: false,
});
/** Builds the view model from the story's args, so each field is a control. */
function MediaMenuButtonStoryWrapper({
kind,
...snapshot
}: MediaMenuSnapshot & { kind: "audio" | "video" }): ReactNode {
const vm = useStaticViewModel(snapshot);
return <MediaMenuButton kind={kind} vm={vm} size="lg" />;
}
const meta = {
component: MediaMenuButtonStoryWrapper,
decorators: [
(Story): JSX.Element => (
<MediaDevicesContext value={mediaDevices}>
<Story />
</MediaDevicesContext>
),
],
} satisfies Meta<typeof MediaMenuButtonStoryWrapper>;
export default meta;
type Story = StoryObj<typeof meta>;
const empty = {
outputOptions: [],
selectedOutput: undefined,
selectOutput: undefined,
backgroundEffect: undefined,
backgroundEffects: [],
backgroundEffectNotice: undefined,
backgroundEffectSettling: false,
backgroundImageRefusal: undefined,
selectBackgroundEffect: undefined,
addBackgroundImage: undefined,
removeBackgroundEffect: undefined,
cameraTrack: null,
} satisfies Partial<MediaMenuSnapshot>;
export const Microphone: Story = {
args: {
...empty,
kind: "audio",
enabled: true,
busy: false,
toggle: fn(),
options: [
{ id: "mic1", label: { type: "name", name: "Microphone 1" } },
{ id: "mic2", label: { type: "name", name: "Microphone 2" } },
],
selected: "mic1",
select: fn(),
outputOptions: [
{ id: "default", label: { type: "default", name: "Built-in Output" } },
],
selectedOutput: "default",
selectOutput: fn(),
},
play: async ({ args, canvasElement }) => {
await userEvent.click(
within(canvasElement).getByRole("switch", { name: "Mute microphone" }),
);
await expect(args.toggle).toHaveBeenCalled();
},
};
export const Camera: Story = {
args: {
...empty,
kind: "video",
enabled: true,
busy: false,
toggle: fn(),
options: [{ id: "cam1", label: { type: "name", name: "Camera 1" } }],
selected: "cam1",
select: fn(),
backgroundEffect: "none",
backgroundEffects: [
{ id: "none", kind: "none" },
{ id: "blur", kind: "blur" },
],
selectBackgroundEffect: fn(),
},
play: async ({ args, canvasElement }) => {
await userEvent.click(
within(canvasElement).getByRole("switch", { name: "Stop video" }),
);
await expect(args.toggle).toHaveBeenCalled();
},
};
export const CameraBusy: Story = {
args: { ...Camera.args, busy: true },
};
/** Opens the effects, for the stories that check what they say. */
async function openEffects(canvasElement: HTMLElement): Promise<HTMLElement> {
await userEvent.click(
within(canvasElement).getByRole("button", { name: "Camera" }),
);
return within(document.body).findByRole("group", {
name: "Background effects",
});
}
/** The view model says why; the view says it in words. */
export const CameraEffectsUnavailable: Story = {
args: {
...Camera.args,
selectBackgroundEffect: undefined,
backgroundEffectNotice: "unavailable",
},
play: async ({ canvasElement }) => {
const section = await openEffects(canvasElement);
await expect(
within(section).getByRole("group"),
).toHaveAccessibleDescription(
"Background effects are not supported on this platform.",
);
},
};
export const CameraEffectsSlow: Story = {
args: {
...Camera.args,
backgroundEffectNotice: "slow",
},
play: async ({ canvasElement }) => {
const section = await openEffects(canvasElement);
await expect(
within(section).getByRole("group"),
).toHaveAccessibleDescription(
"Background effects run slowly on this platform, which may cause your video to stutter.",
);
},
};
export const CameraFileRefused: Story = {
args: {
...Camera.args,
addBackgroundImage: fn(),
backgroundImageRefusal: { reason: "not-an-image", dismiss: fn() },
},
play: async ({ canvasElement }) => {
await openEffects(canvasElement);
await expect(
await within(document.body).findByText(
"That file is not a supported image",
),
).toBeInTheDocument();
},
};
/** No devices to pick and none to mute: a plain, disabled mute button. */
export const WithoutDevices: Story = {
args: {
...Camera.args,
enabled: false,
toggle: undefined,
options: [],
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await expect(
canvas.queryByRole("button", { name: "Camera" }),
).not.toBeInTheDocument();
await expect(canvas.getByTestId("incall_videomute")).toHaveAttribute(
"aria-disabled",
"true",
);
},
};
+124
View File
@@ -0,0 +1,124 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type FC, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { MicButton, VideoButton } from "../button";
import { MediaMuteAndSwitchButton } from "./MediaMuteAndSwitchButton";
import { type MediaMenuViewModel } from "./MediaMenuViewModel";
import { SelfPreview } from "./SelfPreview";
import { useBehavior } from "../useBehavior";
interface Props {
vm: MediaMenuViewModel;
kind: "audio" | "video";
size: "md" | "lg";
}
/**
* The microphone's or the camera's mute button: with a menu to pick the
* device while there are devices to offer, a plain mute button otherwise.
*/
export const MediaMenuButton: FC<Props> = ({ vm, kind, size }) => {
const { t } = useTranslation();
const enabled = useBehavior(vm.enabled$);
const busy = useBehavior(vm.busy$);
const toggle = useBehavior(vm.toggle$);
const options = useBehavior(vm.options$);
const selected = useBehavior(vm.selected$);
const select = useBehavior(vm.select$);
const outputOptions = useBehavior(vm.outputOptions$);
const selectedOutput = useBehavior(vm.selectedOutput$);
const selectOutput = useBehavior(vm.selectOutput$);
const backgroundEffect = useBehavior(vm.backgroundEffect$);
const backgroundEffects = useBehavior(vm.backgroundEffects$);
const notice = useBehavior(vm.backgroundEffectNotice$);
const settling = useBehavior(vm.backgroundEffectSettling$);
const refusal = useBehavior(vm.backgroundImageRefusal$);
const selectBackgroundEffect = useBehavior(vm.selectBackgroundEffect$);
const addBackgroundImage = useBehavior(vm.addBackgroundImage$);
const removeBackgroundEffect = useBehavior(vm.removeBackgroundEffect$);
const cameraTrack = useBehavior(vm.cameraTrack$);
const testId = kind === "audio" ? "incall_mute" : "incall_videomute";
const noticeText = useMemo(() => {
switch (notice) {
case undefined:
return undefined;
case "unavailable":
return t("background_effects.unavailable");
case "slow":
return t("background_effects.slow");
}
}, [notice, t]);
const refusalText = useMemo(() => {
switch (refusal?.reason) {
case undefined:
return undefined;
case "not-an-image":
return t("error.background_not_an_image");
case "animated":
return t("error.background_animated");
case "undecodable":
return t("error.background_undecodable");
case "not-kept":
return t("error.background_not_kept");
}
}, [refusal, t]);
if (options.length === 0) {
const PlainButton = kind === "audio" ? MicButton : VideoButton;
return (
<PlainButton
size={size}
enabled={enabled}
busy={busy}
onClick={toggle}
disabled={busy || toggle === undefined}
data-testid={testId}
/>
);
}
return kind === "audio" ? (
<MediaMuteAndSwitchButton
iconsAndLabels="audio"
enabled={enabled}
busy={busy}
onMuteClick={toggle}
data-testid={testId}
options={options}
selectedOption={selected}
onSelect={select}
outputOptions={outputOptions}
selectedOutputOption={selectedOutput}
onSelectOutput={selectOutput}
/>
) : (
<MediaMuteAndSwitchButton
iconsAndLabels="video"
enabled={enabled}
busy={busy}
onMuteClick={toggle}
options={options}
selectedOption={selected}
onSelect={select}
backgroundEffects={backgroundEffects}
selectedBackgroundEffect={backgroundEffect}
onSelectBackgroundEffect={selectBackgroundEffect}
backgroundEffectSettling={settling}
onAddBackgroundImage={addBackgroundImage}
onRemoveBackgroundEffect={removeBackgroundEffect}
selfPreview={<SelfPreview track={cameraTrack} />}
backgroundImageRefusal={refusalText}
onDismissBackgroundImageRefusal={refusal?.dismiss}
backgroundEffectNotice={noticeText}
/>
);
};
+294
View File
@@ -0,0 +1,294 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { afterEach, describe, expect, it, vi } from "vitest";
import { BehaviorSubject, type Observable } from "rxjs";
import { type LocalVideoMediaTrack } from "@element-hq/matrixrtc-sdk";
import {
flushPromises,
testScope,
mockMuteStates,
mockMediaDevices,
mockVideoTrack,
} from "../utils/test";
import { constant } from "../state/Behavior";
import { type BackgroundEffectsState } from "../state/BackgroundEffects";
import type { DeviceLabel } from "../state/MediaDevices";
import {
createAudioMenuViewModel,
createCameraMenuViewModel,
type MediaMenuViewModel,
} from "./MediaMenuViewModel";
import { backgroundEffect as backgroundEffectSetting } from "../settings/settings";
import { shippedBackgrounds } from "../tracks/backgroundEffectCatalog";
import type * as BackgroundImages from "../tracks/backgroundImages";
import {
type AddedBackground,
addedBackgrounds,
maxAddedBackgrounds,
UnusableImage,
} from "../tracks/backgroundImages";
const modernRouteMock = vi.hoisted(() => vi.fn(() => true));
vi.mock("@livekit/track-processors", () => ({
supportsModernBackgroundProcessors: (): boolean => modernRouteMock(),
}));
const outputSelectionMock = vi.hoisted(() => vi.fn(() => true));
vi.mock("livekit-client", () => ({
supportsAudioOutputSelection: (): boolean => outputSelectionMock(),
}));
const store = vi.hoisted(() => ({
add: vi.fn<(file: Blob) => Promise<string>>(),
remove: vi.fn<(id: string) => Promise<void>>(),
}));
vi.mock("../tracks/backgroundImages", async (original) => {
const { BehaviorSubject } = await import("rxjs");
return {
...(await original<typeof BackgroundImages>()),
addedBackgrounds: {
added$: new BehaviorSubject<AddedBackground[] | undefined>([]),
add: store.add,
remove: store.remove,
},
};
});
const added$ = addedBackgrounds.added$ as BehaviorSubject<
AddedBackground[] | undefined
>;
const devices = mockMediaDevices({
audioInput: {
available$: constant(
new Map<string, DeviceLabel>([
["mic1", { type: "number", number: 1 }],
["mic2", { type: "name", name: "Microphone 2" }],
]),
),
selected$: constant(undefined),
select: vi.fn(),
},
// As Safari: no outputs listed.
audioOutput: {
available$: constant(new Map<string, DeviceLabel>()),
selected$: constant(undefined),
select: vi.fn(),
},
});
function audioMenu(disableSwitcher = false): MediaMenuViewModel {
return createAudioMenuViewModel(
testScope(),
mockMuteStates(),
devices,
constant(disableSwitcher),
);
}
function cameraMenu({
supported = true,
disableSwitcher = false,
pipeline$ = constant({ supported, processor: undefined }),
camera$ = constant(null),
}: {
supported?: boolean;
disableSwitcher?: boolean;
pipeline$?: Observable<BackgroundEffectsState>;
camera$?: Observable<LocalVideoMediaTrack | null>;
} = {}): MediaMenuViewModel {
return createCameraMenuViewModel(
testScope(),
mockMuteStates(),
devices,
constant(disableSwitcher),
pipeline$,
camera$,
);
}
describe("createAudioMenuViewModel", () => {
it("lists the devices, unless the switcher is withheld", () => {
expect(audioMenu().options$.value).toEqual([
{ id: "mic1", label: { type: "number", number: 1 } },
{ id: "mic2", label: { type: "name", name: "Microphone 2" } },
]);
expect(audioMenu(true).options$.value).toEqual([]);
});
it("lists no outputs as an empty list, which keeps the section", () => {
expect(audioMenu().outputOptions$.value).toEqual([]);
});
it.each([true, false])(
"offers to pick an output only where the platform can route to it (%s)",
(canRoute) => {
outputSelectionMock.mockReturnValue(canRoute);
expect(audioMenu().selectOutput$.value !== undefined).toBe(canRoute);
},
);
});
describe("createCameraMenuViewModel", () => {
afterEach(() => {
backgroundEffectSetting.setValue("none");
added$.next([]);
});
it("offers effects where they run, saying where they run slowly", () => {
modernRouteMock.mockReturnValue(true);
const vm = cameraMenu();
expect(vm.selectBackgroundEffect$.value).toBeDefined();
expect(vm.addBackgroundImage$.value).toBeDefined();
expect(vm.backgroundEffectNotice$.value).toBeUndefined();
modernRouteMock.mockReturnValue(false);
const slow = cameraMenu();
expect(slow.selectBackgroundEffect$.value).toBeDefined();
expect(slow.backgroundEffectNotice$.value).toBe("slow");
modernRouteMock.mockReturnValue(true);
});
it("offers nothing while the switcher is withheld", () => {
const vm = cameraMenu({ disableSwitcher: true });
expect(vm.options$.value).toEqual([]);
expect(vm.selectBackgroundEffect$.value).toBeUndefined();
expect(vm.backgroundEffectNotice$.value).toBe("unavailable");
});
it("offers nothing once the pipeline fails to build, keeping the choice", () => {
backgroundEffectSetting.setValue("blur");
const pipeline$ = new BehaviorSubject<BackgroundEffectsState>({
supported: true,
processor: undefined,
});
const vm = cameraMenu({ pipeline$ });
expect(vm.backgroundEffect$.value).toBe("blur");
pipeline$.next({ supported: false, processor: undefined });
expect(vm.selectBackgroundEffect$.value).toBeUndefined();
expect(vm.addBackgroundImage$.value).toBeUndefined();
expect(vm.removeBackgroundEffect$.value).toBeUndefined();
expect(vm.backgroundEffectNotice$.value).toBe("unavailable");
expect(vm.backgroundEffect$.value).toBe("none");
expect(backgroundEffectSetting.getValue()).toBe("blur");
});
it("saves the effect chosen, and none for one not on offer", () => {
const vm = cameraMenu();
vm.selectBackgroundEffect$.value!("image:arc");
expect(vm.backgroundEffect$.value).toBe("image:arc");
vm.selectBackgroundEffect$.value!("image:gone");
expect(backgroundEffectSetting.getValue()).toBe("none");
});
it("offers every effect in order, the added ones removable", () => {
added$.next([{ id: "mine", url: "blob:mine" }]);
expect(cameraMenu().backgroundEffects$.value).toEqual([
{ id: "none", kind: "none", removable: false },
{ id: "blur", kind: "blur", removable: false },
...shippedBackgrounds.map((background) => ({
id: `image:${background.id}`,
kind: "image",
imageUrl: background.imagePath,
removable: false,
})),
{
id: "added:mine",
kind: "image",
imageUrl: "blob:mine",
removable: true,
},
]);
});
it("passes on the wait for the first effect", () => {
const pipeline$ = new BehaviorSubject<BackgroundEffectsState>({
supported: true,
processor: undefined,
wait: "settling",
});
const vm = cameraMenu({ pipeline$ });
expect(vm.backgroundEffectSettling$.value).toBe(true);
pipeline$.next({ ...pipeline$.value, wait: undefined });
expect(vm.backgroundEffectSettling$.value).toBe(false);
});
it("offers adding only below the limit", () => {
const vm = cameraMenu();
added$.next(
Array.from({ length: maxAddedBackgrounds }, (_, i) => ({
id: `${i}`,
url: `blob:${i}`,
})),
);
expect(vm.addBackgroundImage$.value).toBeUndefined();
added$.next(added$.value!.slice(1));
expect(vm.addBackgroundImage$.value).toBeDefined();
});
it("says why each refused file was refused", async () => {
const vm = cameraMenu();
store.add.mockRejectedValue(new UnusableImage("animated"));
vm.addBackgroundImage$.value!(new File(["x"], "a.gif"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value?.reason).toBe("animated");
store.add.mockRejectedValue(new Error("quota"));
vm.addBackgroundImage$.value!(new File(["x"], "b.png"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value?.reason).toBe("not-kept");
store.add.mockResolvedValue("kept");
vm.addBackgroundImage$.value!(new File(["x"], "c.png"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value).toBeUndefined();
});
it("drops a refusal once dismissed, and only that one", async () => {
const vm = cameraMenu();
store.add.mockRejectedValue(new UnusableImage("animated"));
vm.addBackgroundImage$.value!(new File(["x"], "a.gif"));
await flushPromises();
const first = vm.backgroundImageRefusal$.value!;
first.dismiss();
expect(vm.backgroundImageRefusal$.value).toBeUndefined();
// The same again is a refusal of its own, which the first can't dismiss.
vm.addBackgroundImage$.value!(new File(["x"], "a.gif"));
await flushPromises();
expect(vm.backgroundImageRefusal$.value?.reason).toBe("animated");
first.dismiss();
expect(vm.backgroundImageRefusal$.value?.reason).toBe("animated");
});
it("never removes the selected background", () => {
store.remove.mockResolvedValue();
const vm = cameraMenu();
backgroundEffectSetting.setValue("added:worn");
vm.removeBackgroundEffect$.value!("added:worn");
expect(store.remove).not.toHaveBeenCalled();
vm.removeBackgroundEffect$.value!("added:spare");
expect(store.remove).toHaveBeenCalledWith("spare");
});
it("previews the camera only while there is one and it is not muted", () => {
const muted$ = new BehaviorSubject(false);
const track = mockVideoTrack({ muted$ });
const camera$ = new BehaviorSubject<LocalVideoMediaTrack | null>(track);
const vm = cameraMenu({ camera$ });
expect(vm.cameraTrack$.value).toBe(track);
muted$.next(true);
expect(vm.cameraTrack$.value).toBeNull();
muted$.next(false);
expect(vm.cameraTrack$.value).toBe(track);
camera$.next(null);
expect(vm.cameraTrack$.value).toBeNull();
});
});
+324
View File
@@ -0,0 +1,324 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import {
BehaviorSubject,
combineLatest,
distinctUntilChanged,
map,
type Observable,
of,
switchMap,
} from "rxjs";
import { supportsAudioOutputSelection } from "livekit-client";
import { type LocalVideoMediaTrack } from "@element-hq/matrixrtc-sdk";
import { supportsModernBackgroundProcessors } from "@livekit/track-processors";
import { logger } from "matrix-js-sdk/lib/logger";
import {
parseEffect,
serializeEffect,
shippedBackgrounds,
} from "../tracks/backgroundEffectCatalog";
import {
type AddedBackground,
addedBackgrounds,
maxAddedBackgrounds,
type UnusableReason,
UnusableImage,
} from "../tracks/backgroundImages";
import { type BackgroundEffectsState } from "../state/BackgroundEffects";
import { type MenuOptions } from "./MediaMuteAndSwitchButton";
import { type MediaDevices } from "../state/MediaDevices";
import { backgroundEffect as backgroundEffectSetting } from "../settings/settings";
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 { type BackgroundEffectGridItem } from "./BackgroundEffectGrid";
export interface BackgroundImageRefusal {
reason: UnusableReason | "not-kept";
/** Done with it: once read, or once the menu showing it closes. */
dismiss: () => void;
}
/**
* A mute button with a menu to pick the device, shared by the microphone and
* the camera. Fields that belong to the other device are left empty.
*/
export interface MediaMenuSnapshot {
/** Whether the device is on. (muted/unmuted state) */
enabled: boolean;
busy: boolean;
/** Turns the device on or off. Undefined while it can't be toggled. (disable interaction state) */
toggle: (() => void) | undefined;
options: MenuOptions[];
selected: string | undefined;
select: ((id: string) => void) | undefined;
/** Output (speaker) devices. Microphone only. */
outputOptions: MenuOptions[];
selectedOutput: string | undefined;
/** Undefined if the output device is not configurable. */
selectOutput: ((id: string) => void) | undefined;
/** The selected background effect, as its option id. Camera only. */
backgroundEffect: string | undefined;
/** Every effect on offer, in the order they are shown. */
backgroundEffects: BackgroundEffectGridItem[];
/** What the user is told about effects here, if anything. */
backgroundEffectNotice: "unavailable" | "slow" | undefined;
/** Whether the first effect chosen is still being prepared. */
backgroundEffectSettling: boolean;
/** Why the last file offered couldn't be kept, if it couldn't. */
backgroundImageRefusal: BackgroundImageRefusal | undefined;
/** Undefined where background effects can't be chosen. */
selectBackgroundEffect: ((id: string) => void) | undefined;
/** Undefined where no background can be added. */
addBackgroundImage: ((file: File) => void) | undefined;
/** Removes an added background by its option id, unless it is the selected one. */
removeBackgroundEffect: ((id: string) => void) | undefined;
/** The camera to preview, with the selected effect; null while it is off. */
cameraTrack: LocalVideoMediaTrack | null;
}
export type MediaMenuViewModel = ViewModel<MediaMenuSnapshot>;
const noBackgroundEffects = {
backgroundEffect: undefined,
backgroundEffects: [],
backgroundEffectNotice: undefined,
backgroundEffectSettling: false,
backgroundImageRefusal: undefined,
selectBackgroundEffect: undefined,
addBackgroundImage: undefined,
removeBackgroundEffect: undefined,
cameraTrack: null,
} satisfies Partial<MediaMenuSnapshot>;
function options$(
disableSwitcher$: Behavior<boolean>,
available$: Behavior<Map<string, MenuOptions["label"]>>,
): Observable<MenuOptions[]> {
return disableSwitcher$.pipe(
switchMap((disable) =>
disable
? constant([] as MenuOptions[])
: available$.pipe(
map((available) =>
[...available.entries()].map(([id, label]) => ({ id, label })),
),
),
),
);
}
/**
* The microphone's mute button and menu, with the speaker choice.
*
* @param disableSwitcher$ - True to leave out the menu.
*/
export function createAudioMenuViewModel(
scope: ObservableScope,
muteStates: MuteStates,
mediaDevices: MediaDevices,
disableSwitcher$: Behavior<boolean>,
): MediaMenuViewModel {
const { audio } = muteStates;
return {
...createStaticViewModel(noBackgroundEffects),
enabled$: audio.enabled$,
busy$: audio.syncing$,
toggle$: scope.behavior(audio.toggle$.pipe(map((t) => t ?? undefined))),
options$: scope.behavior(
options$(disableSwitcher$, mediaDevices.audioInput.available$),
),
selected$: scope.behavior(
mediaDevices.audioInput.selected$.pipe(map((s) => s?.id)),
),
select$: constant(mediaDevices.audioInput.select),
outputOptions$: scope.behavior(
options$(disableSwitcher$, mediaDevices.audioOutput.available$),
),
selectedOutput$: scope.behavior(
mediaDevices.audioOutput.selected$.pipe(map((s) => s?.id)),
),
selectOutput$: constant(
supportsAudioOutputSelection()
? mediaDevices.audioOutput.select
: undefined,
),
};
}
/**
* The camera's mute button and menu, with the background effects and a
* preview of the camera.
*
* @param disableSwitcher$ - True to leave out the menu.
* @param backgroundEffectsState$ - The background pipeline's state: whether
* effects run here, and the wait for the first.
* @param camera$ - The camera as the pipeline has it, for the preview.
*/
export function createCameraMenuViewModel(
scope: ObservableScope,
muteStates: MuteStates,
mediaDevices: MediaDevices,
disableSwitcher$: Behavior<boolean>,
backgroundEffectsState$: Observable<BackgroundEffectsState>,
camera$: Observable<LocalVideoMediaTrack | null | undefined>,
): MediaMenuViewModel {
const { video } = muteStates;
// Also false once the pipeline has failed to build this session.
const supported$ = backgroundEffectsState$.pipe(
map(({ supported }) => supported === true),
distinctUntilChanged(),
);
const slow = !supportsModernBackgroundProcessors();
const offered$ = combineLatest([disableSwitcher$, supported$]).pipe(
map(([switcherDisabled, supported]) => !switcherDisabled && supported),
);
const refusal$ = new BehaviorSubject<BackgroundImageRefusal | undefined>(
undefined,
);
const refuse = (reason: BackgroundImageRefusal["reason"]): void => {
const refusal: BackgroundImageRefusal = {
reason,
// A later refusal is not this one's to dismiss.
dismiss: () => {
if (refusal$.value === refusal) refusal$.next(undefined);
},
};
refusal$.next(refusal);
};
return {
...createStaticViewModel({
outputOptions: [],
selectedOutput: undefined,
selectOutput: undefined,
}),
enabled$: video.enabled$,
busy$: video.syncing$,
toggle$: scope.behavior(video.toggle$.pipe(map((t) => t ?? undefined))),
options$: scope.behavior(
options$(disableSwitcher$, mediaDevices.videoInput.available$),
),
selected$: scope.behavior(
mediaDevices.videoInput.selected$.pipe(map((s) => s?.id)),
),
select$: constant(mediaDevices.videoInput.select),
backgroundEffect$: scope.behavior(
combineLatest([backgroundEffectSetting.value$, supported$]).pipe(
map(([raw, supported]) =>
supported ? serializeEffect(parseEffect(raw)) : "none",
),
),
),
selectBackgroundEffect$: scope.behavior(
offered$.pipe(
map((offered) =>
offered
? (id: string): void =>
backgroundEffectSetting.setValue(
serializeEffect(parseEffect(id)),
)
: undefined,
),
),
),
backgroundEffects$: scope.behavior(
addedBackgrounds.added$.pipe(
map((added) => backgroundEffectChoices(added ?? [])),
),
),
backgroundEffectNotice$: scope.behavior(
offered$.pipe(
map((offered) =>
!offered ? "unavailable" : slow ? "slow" : undefined,
),
),
),
backgroundEffectSettling$: scope.behavior(
backgroundEffectsState$.pipe(
map(({ wait }) => wait !== undefined),
distinctUntilChanged(),
),
false,
),
// Kept and offered, not put on: that waits for the user to choose it.
addBackgroundImage$: scope.behavior(
combineLatest([offered$, addedBackgrounds.added$]).pipe(
map(([offered, added]) =>
offered && (added?.length ?? 0) < maxAddedBackgrounds
? (file: File): void => {
refusal$.next(undefined);
addedBackgrounds.add(file).catch((e) => {
logger.warn("Could not keep that background", e);
refuse(e instanceof UnusableImage ? e.reason : "not-kept");
});
}
: undefined,
),
),
),
backgroundImageRefusal$: refusal$,
// Muting stops the camera, and so its light.
// The track outlives the mute, so its mute state is checked.
cameraTrack$: scope.behavior(
camera$.pipe(
switchMap((camera) =>
camera
? camera.muted$.pipe(map((muted) => (muted ? null : camera)))
: of(null),
),
),
null,
),
removeBackgroundEffect$: scope.behavior(
offered$.pipe(
map((offered) =>
offered
? (optionId: string): void => {
const effect = parseEffect(optionId);
if (effect.kind !== "added") return;
// The selected effect can't be removed: that would leave no
// effect selected.
if (backgroundEffectSetting.getValue() === optionId) return;
addedBackgrounds
.remove(effect.id)
.catch((e) =>
logger.warn("Could not remove that background", e),
);
}
: undefined,
),
),
),
};
}
function backgroundEffectChoices(
added: AddedBackground[],
): BackgroundEffectGridItem[] {
return [
{ id: serializeEffect({ kind: "none" }), kind: "none", removable: false },
{ id: serializeEffect({ kind: "blur" }), kind: "blur", removable: false },
...shippedBackgrounds.map((background) => ({
id: serializeEffect({ kind: "shipped", id: background.id }),
kind: "image" as const,
imageUrl: background.imagePath,
removable: false,
})),
...added.map((background) => ({
id: serializeEffect({ kind: "added", id: background.id }),
kind: "image" as const,
imageUrl: background.url,
removable: true,
})),
];
}
@@ -404,7 +404,7 @@ export const BackgroundImageRefused: Story = {
selectedBackgroundEffect: "blur",
backgroundEffectNotice:
"Background effects run slowly on this platform, which may cause your video to stutter.",
backgroundImageRefusal: { text: "That file is not a supported image" },
backgroundImageRefusal: "That file is not a supported image",
},
decorators: [
(Story): JSX.Element => (
@@ -440,7 +440,7 @@ function swatch(colour: string): string {
)}`;
}
/** One's own backgrounds are removable, never the one in force. */
/** One's own backgrounds are removable, unless one is the selected one. */
export const AddedBackgroundsCanBeRemoved: Story = {
args: {
...VideoUnmute.args,
@@ -437,7 +437,7 @@ describe("MediaMuteAndSwitchButton", () => {
}
});
test("a refusal can be dismissed and does not outlive the menu", async () => {
test("a refusal is dismissed when closed, or with the menu", async () => {
const user = userEvent.setup();
// jsdom lays nothing out, so has nothing to scroll.
const scroll = Element.prototype.scrollIntoView;
@@ -445,7 +445,8 @@ describe("MediaMuteAndSwitchButton", () => {
onTestFinished(() => {
Element.prototype.scrollIntoView = scroll;
});
const menu = (refusal?: { text: string }): JSX.Element =>
const onDismiss = vi.fn();
const menu = (refusal?: string): JSX.Element =>
withProviders(
<MediaMuteAndSwitchButton
iconsAndLabels="video"
@@ -457,28 +458,22 @@ describe("MediaMuteAndSwitchButton", () => {
onSelectBackgroundEffect={vi.fn()}
onAddBackgroundImage={vi.fn()}
backgroundImageRefusal={refusal}
onDismissBackgroundImageRefusal={onDismiss}
/>,
);
const { rerender, getByRole } = render(menu());
await user.click(getByRole("button", { name: "Camera" }));
rerender(menu({ text: "That file is not a supported image" }));
rerender(menu("That file is not a supported image"));
expect(
screen.getByText("That file is not a supported image"),
).toBeVisible();
screen.getByRole("menuitemradio", { name: "Blur", checked: true });
await user.click(screen.getByRole("button", { name: "Close" }));
expect(screen.queryByText("That file is not a supported image")).toBeNull();
// The next refusal is shown, even if it says the same.
rerender(menu({ text: "That file is not a supported image" }));
expect(
screen.getByText("That file is not a supported image"),
).toBeVisible();
expect(onDismiss).toHaveBeenCalledTimes(1);
await user.keyboard("{Escape}");
await user.click(getByRole("button", { name: "Camera" }));
expect(screen.queryByText("That file is not a supported image")).toBeNull();
expect(onDismiss).toHaveBeenCalledTimes(2);
});
test("offers the background effects in a phone's drawer", async () => {
+17 -16
View File
@@ -85,10 +85,12 @@ export interface MediaMuteAndSwitchButtonProps {
backgroundEffectSettling?: boolean;
/** Called with the file chosen from the add tile. Omit to leave it out. */
onAddBackgroundImage?: (file: File) => void;
/** Removes a removable effect, never the one in force. */
/** Removes a removable effect, unless it is the selected one. */
onRemoveBackgroundEffect?: (id: string) => void;
/** Why the last file offered couldn't be used; a new object each time. */
backgroundImageRefusal?: { text: string };
/** Why the last file offered couldn't be used, if it couldn't. */
backgroundImageRefusal?: string;
/** Called as the refusal is closed, or the menu showing it. */
onDismissBackgroundImageRefusal?: () => void;
/** The user's own camera, shown at the top of the camera menu. */
selfPreview?: ReactNode;
/**
@@ -135,6 +137,7 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
onAddBackgroundImage,
onRemoveBackgroundEffect,
backgroundImageRefusal,
onDismissBackgroundImageRefusal,
selfPreview,
onSelect,
}) => {
@@ -149,20 +152,18 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
// elsewhere; it is held open until the picker is done.
const choosingFile = useRef(false);
const fileInput = useRef<HTMLInputElement | null>(null);
// A refusal is about the attempt that caused it: shown until dismissed or
// until the menu closes, and again for the next one.
const [seenRefusal, setSeenRefusal] = useState<object>();
const refusal =
backgroundImageRefusal !== seenRefusal ? backgroundImageRefusal : undefined;
const onOpenChange = useCallback(
(open: boolean): void => {
if (!open && choosingFile.current) return;
setMenuOpen(open);
// Drop a request that never arrived.
if (!open) setPlannedSelection(null);
if (!open) setSeenRefusal(backgroundImageRefusal);
if (!open) {
// Drop a request that never arrived.
setPlannedSelection(null);
// A refusal is about the attempt that caused it.
onDismissBackgroundImageRefusal?.();
}
},
[backgroundImageRefusal],
[onDismissBackgroundImageRefusal],
);
// Scrolled to as it appears, as the list may be scrolled away from it.
const scrollIntoView = useCallback((element: HTMLElement | null): void => {
@@ -512,7 +513,7 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
removeLabel={t("action.remove")}
/>
{/* In the list, so the menu grows no taller for it. */}
{refusal !== undefined && (
{backgroundImageRefusal !== undefined && (
<div
ref={scrollIntoView}
role="none"
@@ -520,12 +521,12 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
>
<Alert
type="critical"
title={refusal.text}
onClose={(): void => setSeenRefusal(refusal)}
title={backgroundImageRefusal}
onClose={onDismissBackgroundImageRefusal}
/>
</div>
)}
{refusal === undefined &&
{backgroundImageRefusal === undefined &&
backgroundEffectNotice !== undefined && (
<div id={noticeId} role="none" className={styles.notice}>
<InfoIcon width={20} height={20} />
+122
View File
@@ -0,0 +1,122 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { renderHook } from "@testing-library/react";
import {
EventType,
JoinRule,
KnownMembership,
type MatrixClient,
MatrixEvent,
type Room,
} from "matrix-js-sdk";
import { describe, expect, test } from "vitest";
import { useGroupCallRooms } from "./useGroupCallRooms";
import { mockMatrixRoom } from "../utils/test";
describe("useGroupCallRooms", () => {
test("lists a joined room with legacy call member state", () => {
const room = mockCallRoom({ legacyMemberState: true });
expect(listedRoomIds([room])).toEqual([room.roomId]);
});
test("lists a joined room with a sticky RTC membership", () => {
const room = mockCallRoom({
stickyEvents: [new MatrixEvent({ type: EventType.RTCMembership })],
});
expect(listedRoomIds([room])).toEqual([room.roomId]);
});
test("lists a joined room with an RTC membership in its timeline", () => {
const room = mockCallRoom({
timelineEvents: [new MatrixEvent({ type: EventType.RTCMembership })],
});
expect(listedRoomIds([room])).toEqual([room.roomId]);
});
test("lists a knocked room without any call events", () => {
const room = mockCallRoom({
membership: KnownMembership.Knock,
joinRule: JoinRule.Knock,
});
expect(listedRoomIds([room])).toEqual([room.roomId]);
});
test("omits a joined room without any call events", () => {
const room = mockCallRoom({
stickyEvents: [new MatrixEvent({ type: EventType.RoomMessage })],
timelineEvents: [new MatrixEvent({ type: EventType.RoomMessage })],
});
expect(listedRoomIds([room])).toEqual([]);
});
test.each([KnownMembership.Invite, KnownMembership.Leave])(
"omits a room with %s membership despite call events",
(membership) => {
const room = mockCallRoom({
membership,
legacyMemberState: true,
stickyEvents: [new MatrixEvent({ type: EventType.RTCMembership })],
timelineEvents: [new MatrixEvent({ type: EventType.RTCMembership })],
});
expect(listedRoomIds([room])).toEqual([]);
},
);
});
function listedRoomIds(rooms: Room[]): string[] {
const client = {
getRooms: () => rooms,
getUserId: () => "@alice:example.org",
on: () => {},
off: () => {},
matrixRTC: {
getRoomSession: () => ({ memberships: [] }),
on: () => {},
off: () => {},
},
} as unknown as MatrixClient;
const { result } = renderHook(() => useGroupCallRooms(client));
return result.current.map(({ room }) => room.roomId);
}
let nextRoomId = 0;
function mockCallRoom({
membership = KnownMembership.Join,
joinRule = JoinRule.Public,
legacyMemberState = false,
stickyEvents = [],
timelineEvents = [],
}: {
membership?: KnownMembership;
joinRule?: JoinRule;
legacyMemberState?: boolean;
stickyEvents?: MatrixEvent[];
timelineEvents?: MatrixEvent[];
}): Room {
const stateEvents = new Map(
legacyMemberState ? [[EventType.GroupCallMemberPrefix, new Map()]] : [],
);
return mockMatrixRoom({
roomId: `!room${nextRoomId++}:example.org`,
name: "Call room",
getMyMembership: () => membership,
getJoinRule: () => joinRule,
hasEncryptionStateEvent: () => true,
getCanonicalAlias: () => null,
getMxcAvatarUrl: () => null,
getLiveTimeline: () =>
({
getState: () => ({ events: stateEvents }),
getEvents: () => timelineEvents,
}) as unknown as ReturnType<Room["getLiveTimeline"]>,
_unstable_getStickyEvents: () =>
stickyEvents as unknown as ReturnType<Room["_unstable_getStickyEvents"]>,
});
}
+4 -6
View File
@@ -141,7 +141,7 @@ const roomHasCallMembershipEvents = (room: Room): boolean => {
return true;
}
// Check for *active* calls using sticky events.
// Check for recent calls using sticky events.
for (const sticky of room._unstable_getStickyEvents()) {
if (sticky.getType() === EventType.RTCMembership) {
return true;
@@ -150,11 +150,9 @@ const roomHasCallMembershipEvents = (room: Room): boolean => {
// Otherwise, check recent event history to see if anyone had
// sent a call membership in here.
return timeline.getEvents().some(
(e) =>
// Membership events only count if both of these are true
e.unstableStickyInfo && e.getType() === EventType.GroupCallMemberPrefix,
);
return timeline
.getEvents()
.some((e) => e.getType() === EventType.RTCMembership);
// Otherwise, it's *unlikely* this room was ever a call.
};
+2 -1
View File
@@ -22,7 +22,8 @@ and their fonts, where a host embedding the component supplies its own. The
@import url("@fontsource/inconsolata/400.css");
@import url("@fontsource/inconsolata/700.css");
@import url("@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css") layer(compound);
@import url("@vector-im/compound-design-tokens/assets/web/css/compound-design-tokens.css")
layer(compound);
@import url("@vector-im/compound-web/dist/style.css") layer(compound.components);
body {
+6 -1
View File
@@ -37,7 +37,12 @@ interface UseProfile extends ProfileLoadState {
saveProfile: ProfileSaveCallback;
}
export function useProfile(client: MatrixClient | undefined): UseProfile {
export type ProfileClientParts = Pick<
MatrixClient,
"getUserId" | "getUser" | "setDisplayName" | "setAvatarUrl" | "uploadContent"
>;
export function useProfile(client: ProfileClientParts | undefined): UseProfile {
const [{ success, loading, displayName, avatarUrl, error }, setState] =
useState<ProfileLoadState>(() => {
let user: User | undefined = undefined;
+173 -57
View File
@@ -23,30 +23,130 @@ import {
localRtcMember,
} from "../utils/test-fixtures";
import { getBasicRTCSession } from "../utils/test-viewmodel";
import { testScope, withTestScheduler } from "../utils/test";
import { mockRtcMembership, testScope, withTestScheduler } from "../utils/test";
import { ElementCallReactionEventType, ReactionSet } from ".";
afterEach(() => {
vitest.useRealTimers();
});
test("handles a hand raised reaction", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
function raiseLocalHand(
matrixRoom: ReturnType<typeof getBasicRTCSession>["matrixRoom"],
reactionEventId: string,
localTimestamp: Date,
): void {
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
origin_server_ts: localTimestamp.getTime(),
content: {
"m.relates_to": { event_id: localRtcMember.eventId, key: "🖐️" },
},
}),
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
);
}
test("lowers the hand of a member who leaves", () => {
const { members$, matrixRoom, client, rtcMemberships$ } = getBasicRTCSession([
local,
alice,
]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule("abc", {
a: () => {},
b: () => raiseLocalHand(matrixRoom, reactionEventId, localTimestamp),
c: () => rtcMemberships$.next([aliceRtcMember]),
});
expectObservable(raisedHands$).toBe("abc", {
a: {},
b: {
[`${localRtcMember.userId}:${localRtcMember.deviceId}`]: {
reactionEventId,
membershipEventId: localRtcMember.eventId,
time: localTimestamp,
},
},
c: {},
});
});
});
});
test("lowers the hand of a member whose membership is sent again", () => {
const { members$, matrixRoom, client, rtcMemberships$ } = getBasicRTCSession([
local,
alice,
]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
const resent = mockRtcMembership(
localRtcMember.userId,
localRtcMember.deviceId,
);
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
members$,
matrixRoom,
client,
);
schedule("abc", {
a: () => {},
b: () => raiseLocalHand(matrixRoom, reactionEventId, localTimestamp),
c: () => rtcMemberships$.next([resent, aliceRtcMember]),
});
expectObservable(raisedHands$).toBe("abc", {
a: {},
b: {
[`${localRtcMember.userId}:${localRtcMember.deviceId}`]: {
reactionEventId,
membershipEventId: localRtcMember.eventId,
time: localTimestamp,
},
},
c: {},
});
});
});
});
test("handles a hand raised reaction", () => {
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
members$,
matrixRoom,
client,
);
schedule("ab", {
a: () => {},
b: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
@@ -58,7 +158,7 @@ test("handles a hand raised reaction", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
@@ -80,22 +180,24 @@ test("handles a hand raised reaction", () => {
});
test("handles a redaction", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule("abc", {
a: () => {},
b: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
@@ -107,23 +209,23 @@ test("handles a redaction", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
);
},
c: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Redaction,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.RoomRedaction,
redacts: reactionEventId,
}),
rtcSession.room,
matrixRoom,
undefined,
);
},
@@ -144,20 +246,22 @@ test("handles a redaction", () => {
});
test("handles waiting for event decryption", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule("abc", {
a: () => {},
b: () => {
const encryptedEvent = new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
@@ -171,20 +275,20 @@ test("handles waiting for event decryption", () => {
});
// Should ignore encrypted events that are still encrypting
encryptedEvent["decryptionPromise"] = Promise.resolve();
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
encryptedEvent,
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
);
},
c: () => {
rtcSession.room.client.emit(
client.emit(
MatrixEventEvent.Decrypted,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
@@ -214,22 +318,24 @@ test("handles waiting for event decryption", () => {
});
test("hands rejecting events without a proper membership", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const localTimestamp = new Date();
withTestScheduler(({ schedule, expectObservable }) => {
renderHook(() => {
const { raisedHands$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule("ab", {
a: () => {},
b: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: EventType.Reaction,
@@ -241,7 +347,7 @@ test("hands rejecting events without a proper membership", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
@@ -256,7 +362,7 @@ test("hands rejecting events without a proper membership", () => {
});
test("handles a reaction", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const reaction = ReactionSet[1];
@@ -267,15 +373,17 @@ test("handles a reaction", () => {
renderHook(() => {
const { reactions$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule(`abc`, {
a: () => {},
b: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -287,7 +395,7 @@ test("handles a reaction", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
@@ -316,7 +424,11 @@ test("handles a reaction", () => {
});
test("ignores bad reaction events", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const {
members$,
matrixRoom: room,
client,
} = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const reaction = ReactionSet[1];
@@ -326,31 +438,33 @@ test("ignores bad reaction events", () => {
renderHook(() => {
const { reactions$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
room,
client,
);
schedule("ab", {
a: () => {},
b: () => {
// Missing content
rtcSession.room.emit(
room.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: room.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
content: {},
}),
rtcSession.room,
room,
undefined,
false,
{} as IRoomTimelineData,
);
// Wrong relates event
rtcSession.room.emit(
room.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: room.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -362,16 +476,16 @@ test("ignores bad reaction events", () => {
},
},
}),
rtcSession.room,
room,
undefined,
false,
{} as IRoomTimelineData,
);
// Wrong rtc member event
rtcSession.room.emit(
room.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: room.roomId,
event_id: reactionEventId,
sender: aliceRtcMember.userId,
type: ElementCallReactionEventType,
@@ -383,16 +497,16 @@ test("ignores bad reaction events", () => {
},
},
}),
rtcSession.room,
room,
undefined,
false,
{} as IRoomTimelineData,
);
// No emoji
rtcSession.room.emit(
room.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: room.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -403,16 +517,16 @@ test("ignores bad reaction events", () => {
},
},
}),
rtcSession.room,
room,
undefined,
false,
{} as IRoomTimelineData,
);
// Invalid emoji
rtcSession.room.emit(
room.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: room.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -424,7 +538,7 @@ test("ignores bad reaction events", () => {
},
},
}),
rtcSession.room,
room,
undefined,
false,
{} as IRoomTimelineData,
@@ -439,7 +553,7 @@ test("ignores bad reaction events", () => {
});
test("that reactions cannot be spammed", () => {
const { rtcSession } = getBasicRTCSession([local, alice]);
const { members$, matrixRoom, client } = getBasicRTCSession([local, alice]);
const reactionEventId = "$my_event_id:example.org";
const reactionA = ReactionSet[1];
const reactionB = ReactionSet[2];
@@ -451,15 +565,17 @@ test("that reactions cannot be spammed", () => {
renderHook(() => {
const { reactions$ } = new ReactionsReader(
testScope(),
rtcSession.asMockedSession(),
members$,
matrixRoom,
client,
);
schedule("abcd", {
a: () => {},
b: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -471,17 +587,17 @@ test("that reactions cannot be spammed", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
);
},
c: () => {
rtcSession.room.emit(
matrixRoom.emit(
MatrixRoomEvent.Timeline,
new MatrixEvent({
room_id: rtcSession.room.roomId,
room_id: matrixRoom.roomId,
event_id: reactionEventId,
sender: localRtcMember.userId,
type: ElementCallReactionEventType,
@@ -493,7 +609,7 @@ test("that reactions cannot be spammed", () => {
},
},
}),
rtcSession.room,
matrixRoom,
undefined,
false,
{} as IRoomTimelineData,
+87 -66
View File
@@ -5,20 +5,28 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import {
type CallMembership,
MatrixRTCSessionEvent,
type MatrixRTCSession,
} from "matrix-js-sdk/lib/matrixrtc";
import { logger } from "matrix-js-sdk/lib/logger";
import { type MatrixEvent, MatrixEventEvent } from "matrix-js-sdk";
import {
type MatrixClient,
type MatrixEvent,
MatrixEventEvent,
type Room,
} from "matrix-js-sdk";
import { type ReactionEventContent } from "matrix-js-sdk/lib/types";
import {
RelationType,
EventType,
RoomEvent as MatrixRoomEvent,
} from "matrix-js-sdk";
import { BehaviorSubject, delay } from "rxjs";
import {
BehaviorSubject,
combineLatest,
delay,
map,
of,
switchMap,
} from "rxjs";
import { type RTCMember } from "@element-hq/matrixrtc-sdk";
import {
ElementCallReactionEventType,
@@ -29,13 +37,20 @@ import {
type ReactionInfo,
} from ".";
import { type ObservableScope } from "../state/ObservableScope";
import { type Behavior } from "../state/Behavior";
export const REACTION_ACTIVE_TIME_MS = 3000;
/** A member's membership event, which its reactions relate to. */
interface MembershipEvent {
userId: string;
deviceId: string;
eventId: string;
}
/**
* Listens for reactions from a RTCSession and populates subjects
* for consumption by the CallViewModel.
* @param rtcSession
* Listens for reactions to the slot members' memberships and populates
* subjects for consumption by the CallViewModel.
*/
export class ReactionsReader {
private readonly raisedHandsSubject$ = new BehaviorSubject<
@@ -55,9 +70,33 @@ export class ReactionsReader {
*/
public readonly reactions$ = this.reactionsSubject$.asObservable();
private memberships: MembershipEvent[] = [];
public constructor(
private readonly scope: ObservableScope,
private readonly rtcSession: MatrixRTCSession,
members$: Behavior<RTCMember[]>,
private readonly room: Pick<
Room,
// To ignore events from other rooms
| "roomId"
// The raised hands already in the room, as reactions to memberships
| "relations"
// `on`/`off`, to listen for:
// - `RoomEvent.Timeline` (new reactions)
// - `RoomEvent.Redaction` (lowered hands)
// - `RoomEvent.LocalEchoUpdated` (the real id of our own reactions)
| "on"
| "off"
>,
private readonly client: Pick<
MatrixClient,
// Reactions that arrived encrypted
| "decryptEventIfNeeded"
// `on`/`off`, to listen for:
// - `MatrixEventEvent.Decrypted` (reactions once decrypted)
| "on"
| "off"
>,
) {
// Hide reactions after a given time.
this.reactionsSubject$
@@ -76,62 +115,44 @@ export class ReactionsReader {
// TODO: Convert this class to the functional reactive style and get rid of
// all this manual setup and teardown for event listeners
this.rtcSession.room.on(MatrixRoomEvent.Timeline, this.handleReactionEvent);
this.room.on(MatrixRoomEvent.Timeline, this.handleReactionEvent);
this.scope.onEnd(() =>
this.rtcSession.room.off(
MatrixRoomEvent.Timeline,
this.handleReactionEvent,
),
this.room.off(MatrixRoomEvent.Timeline, this.handleReactionEvent),
);
this.rtcSession.room.on(
MatrixRoomEvent.Redaction,
this.handleReactionEvent,
);
this.room.on(MatrixRoomEvent.Redaction, this.handleReactionEvent);
this.scope.onEnd(() =>
this.rtcSession.room.off(
MatrixRoomEvent.Redaction,
this.handleReactionEvent,
),
this.room.off(MatrixRoomEvent.Redaction, this.handleReactionEvent),
);
this.rtcSession.room.client.on(
MatrixEventEvent.Decrypted,
this.handleReactionEvent,
);
this.client.on(MatrixEventEvent.Decrypted, this.handleReactionEvent);
this.scope.onEnd(() =>
this.rtcSession.room.client.off(
MatrixEventEvent.Decrypted,
this.handleReactionEvent,
),
this.client.off(MatrixEventEvent.Decrypted, this.handleReactionEvent),
);
// We listen for a local echo to get the real event ID, as timeline events
// may still be sending.
this.rtcSession.room.on(
MatrixRoomEvent.LocalEchoUpdated,
this.handleReactionEvent,
);
this.room.on(MatrixRoomEvent.LocalEchoUpdated, this.handleReactionEvent);
this.scope.onEnd(() =>
this.rtcSession.room.off(
MatrixRoomEvent.LocalEchoUpdated,
this.handleReactionEvent,
),
this.room.off(MatrixRoomEvent.LocalEchoUpdated, this.handleReactionEvent),
);
this.rtcSession.on(
MatrixRTCSessionEvent.MembershipsChanged,
this.onMembershipsChanged,
);
this.scope.onEnd(() =>
this.rtcSession.off(
MatrixRTCSessionEvent.MembershipsChanged,
this.onMembershipsChanged,
),
);
// Run this once to ensure we have fetched the state from the call.
this.onMembershipsChanged([]);
members$
.pipe(
switchMap((members) =>
members.length === 0
? of([])
: combineLatest(
members.map(({ userId, deviceId, matrixEventId$ }) =>
matrixEventId$.pipe(
map((eventId) => ({ userId, deviceId, eventId })),
),
),
),
),
this.scope.bind(),
)
.subscribe(this.onMembershipsChanged);
}
/**
@@ -145,7 +166,7 @@ export class ReactionsReader {
membershipEventId: string,
expectedSender: string,
): MatrixEvent | undefined {
const relations = this.rtcSession.room.relations.getChildEventsForEvent(
const relations = this.room.relations.getChildEventsForEvent(
membershipEventId,
RelationType.Annotation,
EventType.Reaction,
@@ -162,22 +183,23 @@ export class ReactionsReader {
/**
* Will remove any hand raises by old members, and look for any
* existing hand raises by new members.
* @param oldMemberships Any members who have left the call.
* @param memberships The membership events of everyone in the call now.
*/
private onMembershipsChanged = (oldMemberships: CallMembership[]): void => {
private onMembershipsChanged = (memberships: MembershipEvent[]): void => {
this.memberships = memberships;
// Remove any raised hands for users no longer joined to the call.
const present = new Set(
memberships.map((m) => `${m.userId}:${m.deviceId}`),
);
for (const identifier of Object.keys(this.raisedHandsSubject$.value).filter(
(rhId) => oldMemberships.find((u) => u.userId == rhId),
(rhId) => !present.has(rhId),
)) {
this.removeRaisedHand(identifier);
}
// For each member in the call, check to see if a reaction has
// been raised and adjust.
for (const m of this.rtcSession.memberships) {
if (!m.userId || !m.eventId) {
continue;
}
for (const m of memberships) {
const identifier = `${m.userId}:${m.deviceId}`;
if (
this.raisedHandsSubject$.value[identifier] &&
@@ -235,9 +257,8 @@ export class ReactionsReader {
* @param event The incoming matrix event, which may or may not be decrypted.
*/
private handleReactionEvent = (event: MatrixEvent): void => {
const room = this.rtcSession.room;
// Decrypted events might come from a different room
if (event.getRoomId() !== room.roomId) return;
if (event.getRoomId() !== this.room.roomId) return;
// Skip any events that are still sending.
if (event.isSending()) return;
@@ -246,7 +267,7 @@ export class ReactionsReader {
// Skip any event without a sender or event ID.
if (!sender || !reactionEventId) return;
room.client
this.client
.decryptEventIfNeeded(event)
.catch((e) => logger.warn(`Failed to decrypt ${event.getId()}`, e));
if (event.isBeingDecrypted() || event.isDecryptionFailure()) return;
@@ -255,7 +276,7 @@ export class ReactionsReader {
const content: ECallReactionEventContent = event.getContent();
const membershipEventId = content?.["m.relates_to"]?.event_id;
const membershipEvent = this.rtcSession.memberships.find(
const membershipEvent = this.memberships.find(
(e) => e.eventId === membershipEventId && e.userId === sender,
);
// Check to see if this reaction was made to a membership event (and the
@@ -315,7 +336,7 @@ export class ReactionsReader {
// Check to see if this reaction was made to a membership event (and the
// sender of the reaction matches the membership)
const membershipEvent = this.rtcSession.memberships.find(
const membershipEvent = this.memberships.find(
(e) => e.eventId === membershipEventId && e.userId === sender,
);
if (!membershipEvent) {
+40 -38
View File
@@ -5,7 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { EventType, RelationType } from "matrix-js-sdk";
import {
EventType,
type MatrixClient,
RelationType,
type Room,
} from "matrix-js-sdk";
import {
createContext,
use,
@@ -14,14 +19,15 @@ import {
useMemo,
type JSX,
} from "react";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { logger } from "matrix-js-sdk/lib/logger";
import { useMatrixRTCSessionMemberships } from "../useMatrixRTCSessionMemberships";
import { useClientState } from "../ClientContext";
import { ElementCallReactionEventType, type ReactionOption } from ".";
import { type CallViewModel } from "../state/CallViewModel/CallViewModel";
import { useBehavior } from "../useBehavior";
import { constant } from "../state/Behavior";
const noMembershipEvent$ = constant(undefined);
interface ReactionsSenderContextType {
supportsReactions: boolean;
@@ -46,28 +52,34 @@ export const useReactionsSender = (): ReactionsSenderContextType => {
*/
export const ReactionsSenderProvider = ({
children,
rtcSession,
room,
client,
vm,
}: {
children: ReactNode;
rtcSession: MatrixRTCSession;
/** The room the reactions are sent in. */
room: Pick<Room, "roomId">;
client: Pick<
MatrixClient,
// Our own identity, which reactions and raised hands are keyed by
| "getUserId"
| "getDeviceId"
// Sending reactions and raising a hand
| "sendEvent"
// Lowering a hand
| "redactEvent"
>;
/** Our own membership, which the reactions relate to, and the current reactions. */
vm: CallViewModel;
}): JSX.Element => {
const memberships = useMatrixRTCSessionMemberships(rtcSession);
const clientState = useClientState();
const supportsReactions =
clientState?.state === "valid" && clientState.supportedFeatures.reactions;
const room = rtcSession.room;
const myUserId = room.client.getUserId();
const myDeviceId = room.client.getDeviceId();
const myMembershipIdentifier = `${myUserId}:${myDeviceId}`;
const myMembershipIdentifier = `${client.getUserId()}:${client.getDeviceId()}`;
const myMembershipEvent = useMemo(
() =>
memberships.find(
(m) => m.userId === myUserId && m.deviceId === myDeviceId,
)?.eventId,
[memberships, myUserId, myDeviceId],
const localMember = useBehavior(vm.localMember$);
const myMembershipEvent = useBehavior(
localMember?.matrixEventId$ ?? noMembershipEvent$,
);
const reactions = useBehavior(vm.reactions$);
@@ -99,8 +111,8 @@ export const ReactionsSenderProvider = ({
if (!myMembershipEvent) {
throw new Error("Cannot find own membership event");
}
const reaction = await room.client.sendEvent(
rtcSession.room.roomId,
const reaction = await client.sendEvent(
room.roomId,
EventType.Reaction,
{
"m.relates_to": {
@@ -116,20 +128,14 @@ export const ReactionsSenderProvider = ({
}
} else {
try {
await room.client.redactEvent(rtcSession.room.roomId, myReactionId);
await client.redactEvent(room.roomId, myReactionId);
logger.debug("Redacted raise hand event");
} catch (ex) {
logger.error("Failed to redact reaction event", myReactionId, ex);
throw ex;
}
}
}, [
myMembershipEvent,
myMembershipIdentifier,
myRaisedHand,
rtcSession,
room,
]);
}, [myMembershipEvent, myMembershipIdentifier, myRaisedHand, client, room]);
const sendReaction = useCallback(
async (reaction: ReactionOption) => {
@@ -140,20 +146,16 @@ export const ReactionsSenderProvider = ({
if (!myMembershipEvent) {
throw new Error("Cannot find own membership event");
}
await room.client.sendEvent(
rtcSession.room.roomId,
ElementCallReactionEventType,
{
"m.relates_to": {
rel_type: RelationType.Reference,
event_id: myMembershipEvent,
},
emoji: reaction.emoji,
name: reaction.name,
await client.sendEvent(room.roomId, ElementCallReactionEventType, {
"m.relates_to": {
rel_type: RelationType.Reference,
event_id: myMembershipEvent,
},
);
emoji: reaction.emoji,
name: reaction.name,
});
},
[myMembershipEvent, myReaction, room, myMembershipIdentifier, rtcSession],
[myMembershipEvent, myReaction, client, room, myMembershipIdentifier],
);
return (
+2 -3
View File
@@ -6,13 +6,12 @@ Please see LICENSE in the repository root for full details.
*/
import { type FC, type FormEventHandler, useCallback, useState } from "react";
import { type MatrixClient } from "matrix-js-sdk";
import { Trans, useTranslation } from "react-i18next";
import { Button, Heading, Text } from "@vector-im/compound-web";
import styles from "./CallEndedView.module.css";
import feedbackStyle from "../input/FeedbackInput.module.css";
import { useProfile } from "../profile/useProfile";
import { type ProfileClientParts, useProfile } from "../profile/useProfile";
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
import { FieldRow, InputField } from "../input/Input";
@@ -22,7 +21,7 @@ import { LeaveToHomeLink } from "../button/LeaveToHomeLink";
import { useLeaveToHome } from "../LeaveToHomeContext";
interface Props {
client: MatrixClient;
client: ProfileClientParts;
isPasswordlessUser: boolean;
hideHeader: boolean;
confineToRoom: boolean;
+46 -80
View File
@@ -19,16 +19,8 @@ import {
vitest,
} from "vitest";
import { render, waitFor, screen, act } from "@testing-library/react";
import {
type MatrixClient,
JoinRule,
type RoomState,
UnsupportedStickyEventsEndpointError,
} from "matrix-js-sdk";
import {
MatrixRTCSessionEvent,
type MatrixRTCSession,
} from "matrix-js-sdk/lib/matrixrtc";
import { type MatrixClient, JoinRule } from "matrix-js-sdk";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { BrowserRouter } from "react-router-dom";
import userEvent, {
PointerEventsCheckLevel,
@@ -53,7 +45,7 @@ import {
testScope,
} from "../utils/test";
import { CallView } from "./CallView";
import { GroupCallErrorBoundary } from "./GroupCallErrorBoundary";
import { type CallMatrixBackend } from "../CallMatrixBackend";
import {
type HostBridge,
HostBridgeProvider,
@@ -61,7 +53,10 @@ import {
nullHostBridge,
} from "../HostBridge";
import { type JoinCallData } from "../widget";
import { MatrixRTCTransportMissingError } from "../utils/errors";
import {
ConnectionLostError,
MatrixRTCTransportMissingError,
} from "../utils/errors";
import {
BackgroundEffectsProvider,
createAppBackgroundEffects,
@@ -146,7 +141,6 @@ function createCallView(
hostBridge: HostBridge,
joined = true,
options: {
withErrorBoundary?: boolean;
/** Wait for the host to say when to join, rather than joining at once. */
preload?: boolean;
} = {},
@@ -155,6 +149,7 @@ function createCallView(
getByText: ReturnType<typeof render>["getByText"];
} {
const client = {
...mockEmitter(),
getUser: () => null,
getUserId: () => localRtcMember.userId,
getDeviceId: () => localRtcMember.deviceId,
@@ -170,28 +165,14 @@ function createCallView(
client,
roomId,
getMember: (userId) => roomMembers.get(userId) ?? null,
getMembersWithMembership: () => [carol],
getMxcAvatarUrl: () => null,
getCanonicalAlias: () => null,
currentState: {
...mockEmitter(),
getJoinRule: () => JoinRule.Invite,
} as Partial<RoomState> as RoomState,
getJoinRule: () => JoinRule.Invite,
});
const rtcSession = new MockRTCSession(room, []).withMemberships(
constant([localRtcMember]),
);
rtcSession.joined = joined;
const callView = (
<CallView
client={client}
isPasswordlessUser={false}
confineToRoom={false}
preload={options.preload ?? false}
// Straight into the (mocked) call, past the lobby
skipLobby
rtcSession={rtcSession.asMockedSession()}
/>
);
const { getByText } = render(
<BrowserRouter>
<HostBridgeProvider value={hostBridge}>
@@ -200,13 +181,22 @@ function createCallView(
<BackgroundEffectsProvider
effects={createAppBackgroundEffects(testScope())}
>
{options.withErrorBoundary ? (
<GroupCallErrorBoundary recoveryActionHandler={vi.fn()}>
{callView}
</GroupCallErrorBoundary>
) : (
callView
)}
<CallView
backend={
{
...client,
...room,
clientEmitter: client,
roomEmitter: room,
} as unknown as CallMatrixBackend
}
isPasswordlessUser={false}
confineToRoom={false}
preload={options.preload ?? false}
// Straight into the (mocked) call, past the lobby
skipLobby
rtcSession={rtcSession.asMockedSession()}
/>
</BackgroundEffectsProvider>
</MediaDevicesContext>
</TooltipProvider>
@@ -371,52 +361,28 @@ test.skip("CallView shows errors that occur during joining", async () => {
screen.getByText("Call is not supported");
});
test("translates wrapped UnsupportedStickyEventsEndpointError to the StickyEventsRequiredError screen", async () => {
// Mirror the shape the SDK emits: the MembershipManager scheduler wraps
// the original UnsupportedStickyEventsEndpointError in a generic Error
// but preserves the original on `.cause`.
const stickyError = new UnsupportedStickyEventsEndpointError(
"Server does not support the sticky events",
"sendStickyEvent",
test("user can reconnect after losing the connection", async () => {
// What the call throws once the view model reports the connection lost
(ActiveCall as MockedFunction<typeof ActiveCall>).mockImplementation(
({ onLeft }) => {
const [error, setError] = useState<Error | null>(null);
if (error !== null) throw error;
return (
<div>
<button onClick={() => onLeft("user")}>Leave</button>
<button onClick={() => setError(new ConnectionLostError())}>
LoseConnection
</button>
</div>
);
},
);
const wrappedError = new Error(
"The MembershipManager shut down because of the end condition: " +
String(stickyError),
{ cause: stickyError },
);
const { rtcSession } = createCallView(nullHostBridge, true, {
withErrorBoundary: true,
});
await act(() =>
rtcSession.emit(MatrixRTCSessionEvent.MembershipManagerError, wrappedError),
);
await screen.findByText("Homeserver does not support Matrix 2.0 calls");
});
test("falls back to ConnectionLostError for unrecognised membership manager errors", async () => {
const { rtcSession } = createCallView(nullHostBridge, true, {
withErrorBoundary: true,
});
await act(() =>
rtcSession.emit(
MatrixRTCSessionEvent.MembershipManagerError,
new Error("something else broke"),
),
);
await screen.findByText("Connection lost");
});
test("user can reconnect after a membership manager error", async () => {
const user = userEvent.setup();
const { rtcSession } = createCallView(nullHostBridge, true);
await act(() =>
rtcSession.emit(MatrixRTCSessionEvent.MembershipManagerError, undefined),
);
createCallView(nullHostBridge, true);
await user.click(screen.getByRole("button", { name: "LoseConnection" }));
await screen.findByText("Connection lost");
// Never joined, so there was no call to leave
expect(playSound).not.toHaveBeenCalled();
// XXX: Wrapping the following click in act() shouldn't be necessary (the
// async state update should be processed automatically by the waitFor call),
// and yet here we are.
+182 -101
View File
@@ -13,21 +13,24 @@ import {
useMemo,
useState,
} from "react";
import {
type MatrixClient,
JoinRule,
type Room,
UnsupportedStickyEventsEndpointError,
} from "matrix-js-sdk";
import { type MatrixClient, JoinRule, type Room } from "matrix-js-sdk";
import {
Room as LivekitRoom,
isE2EESupported as isE2EESupportedBrowser,
} from "livekit-client";
import { logger } from "matrix-js-sdk/lib/logger";
import {
MatrixRTCSessionEvent,
type MatrixRTCSession,
type Statistics,
} from "matrix-js-sdk/lib/matrixrtc";
import { type Observable } from "rxjs";
import {
createRTCSlot,
type EncryptionSystem,
MembershipManagerError as RTCMembershipManagerError,
type RTCSlot,
withEmitter,
} from "@element-hq/matrixrtc-sdk";
import { type JoinCallData } from "../widget";
import { LobbyView } from "./LobbyView";
@@ -39,7 +42,6 @@ import { findDeviceByName } from "../utils/media";
import { ActiveCall } from "./InCallView";
import { type MuteStates } from "../state/MuteStates";
import { useMediaDevices } from "../MediaDevicesContext";
import { useMatrixRTCSessionMemberships } from "../useMatrixRTCSessionMemberships";
import {
saveKeyForRoom,
useRoomEncryptionSystem,
@@ -57,14 +59,11 @@ import {
} from "./CallEventAudioRenderer";
import { useLatest } from "../useLatest";
import {
ConnectionLostError,
E2EENotSupportedError,
ElementCallError,
StickyEventsRequiredError,
UnknownCallError,
} from "../utils/errors.ts";
import { GroupCallErrorBoundary } from "./GroupCallErrorBoundary.tsx";
import { useTypedEventEmitter } from "../useEvents";
import { muteAllAudio$ } from "../state/MuteAllAudioModel.ts";
import { useAppBarTitle } from "../AppBar.tsx";
import { useBehavior } from "../useBehavior.ts";
@@ -73,6 +72,9 @@ import { useHostBridge } from "../HostBridge.ts";
import { useMuteStates } from "../state/useMuteStates.ts";
import { useLeaveToHome } from "../LeaveToHomeContext.ts";
import { useLocalMedia } from "../useLocalMedia.ts";
import { ObservableScope } from "../state/ObservableScope.ts";
import { type CallNotificationWrapper } from "../state/CallViewModel/CallNotificationLifecycle.ts";
import { type CallMatrixBackend } from "../CallMatrixBackend.ts";
/**
* If there already are this many participants in the call, we automatically mute
@@ -80,17 +82,19 @@ import { useLocalMedia } from "../useLocalMedia.ts";
*/
export const MUTE_PARTICIPANT_COUNT = 8;
declare global {
interface Window {
rtcSession?: MatrixRTCSession;
}
}
interface Props {
/** The client to place the call with. */
client: MatrixClient;
/** The call to join. */
rtcSession: MatrixRTCSession;
/** The client and room to place the call with and in. */
backend: CallMatrixBackend;
/**
* The call to join, which the RTC slot is built on.
* Passing undefined -> the SDK will create a inner RTCSession (or in the future a rust equivalent)
* @deprecated: It should not get its rtcSession from here.
* The goal is that the RTC session is fully encapsulated inside the SDK (`createRTCSlot`)
* We keep this as a fallback for the SPA. In that mode we currently expect to manage Our
* own rtcSession with `useLoadGroupCall`. This is an open TODO. Until then we have this
* alternative.
*/
rtcSession?: MatrixRTCSession;
/**
* Whether the user is signed in as a guest, and so should be offered the
* chance to create an account when the call ends.
@@ -121,18 +125,58 @@ interface Props {
* whatever is hosting it — the standalone app's own shell, or an application
* embedding Element Call as a component. Both render this.
*/
export const CallView: FC<Props> = (props): ReactNode => {
export const CallView: FC<Props> = ({
backend,
rtcSession: externalRtcSession,
...props
}): ReactNode => {
// STOP GAP: what is below is still written against a client and a room.
// Both are refactored along with the backend.
const client = useMemo(
() => withEmitter(backend, backend.clientEmitter),
[backend],
);
const room = useMemo(
() => withEmitter(backend, backend.roomEmitter),
[backend],
);
// Whether the user is in the call is the call's own business, not its host's.
// Held here rather than below so that it survives the mute state being
// rebuilt.
const [joined, setJoined] = useState(false);
const muteStates = useMuteStates();
const e2eeSystem = useRoomEncryptionSystem(backend.roomId);
if (muteStates === null) return null;
// One slot for every join of this call: leaving and joining again, to
// reconnect or from the lobby, happens on the same one
const [slot, setSlot] = useState<ReturnType<typeof createRTCSlot> | null>(
null,
);
useEffect(() => {
const scope = new ObservableScope();
setSlot(
createRTCSlot(
scope,
backend,
{ encryptionSystem: e2eeSystem },
externalRtcSession,
),
);
return (): void => scope.end();
}, [backend, e2eeSystem, externalRtcSession]);
if (muteStates === null || slot === null) return null;
return (
<LoadedCallView
{...props}
client={client}
room={room}
sentCallNotification$={slot.sentCallNotification$}
statistics={slot.statistics}
slot={slot}
e2eeSystem={e2eeSystem}
joined={joined}
setJoined={setJoined}
muteStates={muteStates}
@@ -140,20 +184,98 @@ export const CallView: FC<Props> = (props): ReactNode => {
);
};
interface LoadedProps extends Props {
// Here we do not pass the rtcSession anymore. This is a huge step!!
// We only rely on our sdk abstraction (+ client and +room but only a
// smaller list of callbacks.)
interface LoadedProps extends Omit<Props, "rtcSession" | "backend"> {
// Narrower than `Props.client`: the `slot` already has what only it and its
// session need, `getRTCTransports`, `delegateDelayedLeave`, `baseUrl`,
// `getSyncState`, `ClientEvent.Sync`, and the session's sending
client: Pick<
MatrixClient,
| "getUserId"
| "getDeviceId"
| "getDomain"
| "getOpenIdToken"
| "getLivekitToken"
| "sendEvent"
| "redactEvent"
| "decryptEventIfNeeded"
| "getUser"
| "setDisplayName"
| "setAvatarUrl"
| "uploadContent"
| "doesServerSupportUnstableFeature"
| "getCrypto"
// `on`/`off`, to listen for `MatrixEventEvent.Decrypted` (reactions once
// decrypted)
| "on"
| "off"
>;
// Narrower than `Props.room`: the `slot` already follows
// `RoomStateEvent.Events` for its status, `RoomStateEvent.Members` for its
// own members, and the timeline its session reads the memberships from
room: Pick<
Room,
| "roomId"
| "name"
| "getMxcAvatarUrl"
| "getJoinRule"
| "getMembersWithMembership"
| "_unstable_getStickyEvents"
| "relations"
// `on`/`off`, to listen for:
// - `RoomEvent.Name` (room name)
// - `RoomStateEvent.Update` and `RoomEvent.CurrentStateUpdated` (avatar
// and join rule hooks)
// - `RoomStateEvent.Members` (call view model members)
// - `RoomEvent.Timeline` and `RoomStickyEventsEvent.Update` (call notifications)
// - `RoomEvent.Timeline`, `RoomEvent.Redaction` and
// `RoomEvent.LocalEchoUpdated` (reactions and raised hands)
| "on"
| "off"
>;
/**
* The call notifications the session sends with our join, so the call can
* show it ringing: the slot's `sentCallNotification$`.
*/
sentCallNotification$: Observable<CallNotificationWrapper>;
/** The session's media key statistics, reported when the call ends. */
statistics: Statistics;
slot: RTCSlot;
e2eeSystem: EncryptionSystem;
joined: boolean;
setJoined: (value: boolean) => void;
muteStates: MuteStates;
}
/** {@link CallView}, once it has the mute state everything below needs. */
/**
* Whether our membership is live in the slot: seen in the room, and not taken
* down by the membership manager stopping. Leaving the call only makes sense
* then; an error before the join, or one that ended the membership, leaves
* nothing to leave.
*/
function isInCall(slot: RTCSlot): boolean {
const participation = slot.participation$.value;
if (participation?.localMember$.value == null) return false;
const state = participation.state$.value;
return !(
state.kind === "failed" && state.error instanceof RTCMembershipManagerError
);
}
/** {@link CallView}, once it has the slot and mute state everything below needs. */
const LoadedCallView: FC<LoadedProps> = ({
client,
room,
isPasswordlessUser,
confineToRoom,
preload,
skipLobby,
rtcSession,
slot,
sentCallNotification$,
statistics,
e2eeSystem,
joined,
setJoined,
muteStates,
@@ -162,7 +284,7 @@ const LoadedCallView: FC<LoadedProps> = ({
const [externalError, setExternalError] = useState<ElementCallError | null>(
null,
);
const memberships = useMatrixRTCSessionMemberships(rtcSession);
const members = useBehavior(slot.members$);
const rootElement = useRootElement();
const hostBridge = useHostBridge();
// A host that can close us is a host that decides when we stop existing, so
@@ -181,7 +303,7 @@ const LoadedCallView: FC<LoadedProps> = ({
);
// This should use `useEffectEvent` (only available in experimental versions)
useEffect(() => {
if (memberships.length >= MUTE_PARTICIPANT_COUNT)
if (members.length >= MUTE_PARTICIPANT_COUNT)
muteStates.audio.setEnabled$.value?.(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
@@ -203,48 +325,10 @@ const LoadedCallView: FC<LoadedProps> = ({
};
}, [rootElement]);
useEffect(() => {
window.rtcSession = rtcSession;
return (): void => {
delete window.rtcSession;
};
}, [rtcSession]);
// TODO move this into the callViewModel LocalMembership.ts
// We might actually not need this at all. Since we get into fatalError on those errors already?
useTypedEventEmitter(
rtcSession,
MatrixRTCSessionEvent.MembershipManagerError,
(error) => {
// When matrix_rtc_mode=matrix_2_0 is in effect but the homeserver does
// not advertise MSC4354 (sticky events), the SDK throws an
// `UnsupportedStickyEventsEndpointError`. The MembershipManager
// scheduler wraps it and exposes the original via `.cause`.
if (
error instanceof Error &&
error.cause instanceof UnsupportedStickyEventsEndpointError
) {
setExternalError(new StickyEventsRequiredError());
} else {
setExternalError(new ConnectionLostError());
}
},
);
useEffect(() => {
// Sanity check the room object
if (client.getRoom(rtcSession.room.roomId) !== rtcSession.room)
logger.warn(
`We've ended up with multiple rooms for the same ID (${rtcSession.room.roomId}). This indicates a bug in the group call loading code, and may lead to incomplete room state.`,
);
}, [client, rtcSession.room]);
const room = rtcSession.room as Room;
const { displayName, avatarUrl } = useProfile(client);
const roomName = useRoomName(room);
const roomAvatar = useRoomAvatar(room);
const { returnToLobby, password: passwordFromUrl, header } = useUrlParams();
const e2eeSystem = useRoomEncryptionSystem(room.roomId);
// Save the password once we start the groupCallView
useEffect(() => {
@@ -260,7 +344,6 @@ const LoadedCallView: FC<LoadedProps> = ({
avatarUrl: avatarUrl!,
roomId: room.roomId,
roomName,
roomAlias: room.getCanonicalAlias(),
roomAvatar,
e2eeSystem,
};
@@ -268,8 +351,8 @@ const LoadedCallView: FC<LoadedProps> = ({
// Count each member only once, regardless of how many devices they use
const participantCount = useMemo(
() => new Set<string>(memberships.map((m) => m.userId!)).size,
[memberships],
() => new Set<string>(members.map((m) => m.userId)).size,
[members],
);
const mediaDevices = useMediaDevices();
@@ -277,27 +360,24 @@ const LoadedCallView: FC<LoadedProps> = ({
// Opened by the lobby, published by the call: one capture for both
const media = useLocalMedia();
const enterRTCSessionOrError = useCallback(
async (rtcSession: MatrixRTCSession): Promise<void> => {
try {
setJoined(true);
// TODO-MULTI-SFU what to do with error handling now that we don't use this function?
// @BillCarsonFr
} catch (e) {
if (e instanceof ElementCallError) {
setExternalError(e);
} else {
logger.error(`Unknown Error while entering RTC session`, e);
const error = new UnknownCallError(
e instanceof Error ? e : new Error("Unknown error", { cause: e }),
);
setExternalError(error);
}
const enterRTCSessionOrError = useCallback(async (): Promise<void> => {
try {
setJoined(true);
// TODO-MULTI-SFU what to do with error handling now that we don't use this function?
// @BillCarsonFr
} catch (e) {
if (e instanceof ElementCallError) {
setExternalError(e);
} else {
logger.error(`Unknown Error while entering RTC session`, e);
const error = new UnknownCallError(
e instanceof Error ? e : new Error("Unknown error", { cause: e }),
);
setExternalError(error);
}
return Promise.resolve();
},
[setJoined],
);
}
return Promise.resolve();
}, [setJoined]);
useEffect(() => {
const defaultDeviceSetup = async ({
@@ -360,7 +440,6 @@ const LoadedCallView: FC<LoadedProps> = ({
}
}, [
hostBridge,
rtcSession,
preload,
skipLobby,
mediaDevices,
@@ -407,9 +486,9 @@ const LoadedCallView: FC<LoadedProps> = ({
const sendInstantly = hostControlsLifetime;
PosthogAnalytics.instance.eventCallEnded.track(
room.roomId,
rtcSession.memberships.length,
slot.members$.value.length,
sendInstantly,
rtcSession,
statistics,
);
// Unfortunately the PostHog library provides no way to await the
// tracking of an event, but we don't really want it to hold up our
@@ -455,7 +534,8 @@ const LoadedCallView: FC<LoadedProps> = ({
hostBridge,
hostControlsLifetime,
room.roomId,
rtcSession,
slot,
statistics,
isPasswordlessUser,
confineToRoom,
returnToLobby,
@@ -469,7 +549,7 @@ const LoadedCallView: FC<LoadedProps> = ({
hostBridge.setAlwaysOnScreen(true).catch((e) => {
logger.error("Error calling setAlwaysOnScreen(true)", e);
});
}, [hostBridge, joined, rtcSession]);
}, [hostBridge, joined]);
const joinRule = useJoinRule(room);
@@ -530,7 +610,8 @@ const LoadedCallView: FC<LoadedProps> = ({
<ActiveCall
client={client}
matrixInfo={matrixInfo}
rtcSession={rtcSession as MatrixRTCSession}
slot={slot}
sentCallNotification$={sentCallNotification$}
matrixRoom={room}
onLeft={onLeft}
media={media}
@@ -553,7 +634,7 @@ const LoadedCallView: FC<LoadedProps> = ({
if (isPasswordlessUser || PosthogAnalytics.instance.isEnabled()) {
body = (
<CallEndedView
endedCallId={rtcSession.room.roomId}
endedCallId={room.roomId}
client={client}
isPasswordlessUser={isPasswordlessUser}
hideHeader={header === HeaderStyle.None}
@@ -570,7 +651,7 @@ const LoadedCallView: FC<LoadedProps> = ({
// Left, and the host decides what happens next:
body = returnToLobby ? lobbyView : null;
} else if (preload || skipLobby) {
// The RTC session is not joined to yet (`isJoined`), but enterRTCSessionOrError should have been called.
// Not in the call yet: waiting for the host to say when, or about to join
body = null;
} else {
body = lobbyView;
@@ -582,16 +663,16 @@ const LoadedCallView: FC<LoadedProps> = ({
setExternalError(null);
if (action == "reconnect") {
setLeft(false);
await enterRTCSessionOrError(rtcSession).catch((e) => {
await enterRTCSessionOrError().catch((e) => {
logger.error("Error re-entering RTC session", e);
});
}
}}
onError={(_error) => {
if (rtcSession.isJoined()) onLeft("error");
if (isInCall(slot)) onLeft("error");
// If there is an error we need to be dismissible again. This is done in
// `onLeft` as well; we need it here explicitly in case
// rtcSession.isJoined is false.
// `onLeft` as well; we need it here explicitly in case we were not in
// the call.
void hostBridge.setAlwaysOnScreen(false);
}}
>
+67 -66
View File
@@ -15,7 +15,7 @@ import {
vi,
} from "vitest";
import { act, render, type RenderResult } from "@testing-library/react";
import { BehaviorSubject } from "rxjs";
import { BehaviorSubject, NEVER } from "rxjs";
import { BrowserRouter } from "react-router-dom";
import { TooltipProvider } from "@vector-im/compound-web";
import userEvent from "@testing-library/user-event";
@@ -25,7 +25,6 @@ import {
mockMediaDevices,
mockMuteStates,
mockRtcMembership,
type MockRTCSession,
mockRTCSlot,
mockRTCMember,
testScope,
@@ -44,7 +43,7 @@ import { ReactionsSenderProvider } from "../reactions/useReactionsSender";
import { useRoomEncryptionSystem } from "../e2ee/sharedKeyManagement";
import { MemberAudioRenderer } from "../tracks/MemberAudioRenderer";
import type * as MatrixRTCSdk from "@element-hq/matrixrtc-sdk";
import { constant, type ObservableScope } from "@element-hq/matrixrtc-sdk";
import { constant, type RTCSlot } from "@element-hq/matrixrtc-sdk";
import { MediaDevicesContext } from "../MediaDevicesContext";
import { type MediaDevices as ECMediaDevices } from "../state/MediaDevices";
import { AppBar } from "../AppBar";
@@ -73,12 +72,6 @@ vi.mock("../tile/GridTile");
vi.mock("../tile/SpotlightTile");
vi.mock("../e2ee/sharedKeyManagement");
vi.mock("../tracks/MemberAudioRenderer");
// ActiveCall builds the slot itself; the view is what these tests are about
const createRTCSlotMock = vi.hoisted(() => vi.fn());
vi.mock("@element-hq/matrixrtc-sdk", async (importOriginal) => ({
...(await importOriginal<typeof MatrixRTCSdk>()),
createRTCSlot: createRTCSlotMock,
}));
vi.mock("react-use-measure", () => ({
default: (): [() => void, object] => [(): void => {}, {}],
}));
@@ -91,32 +84,33 @@ const matrixInfo = {
avatarUrl: "",
roomId: "",
roomName: "",
roomAlias: null,
roomAvatar: null,
e2eeSystem: { kind: E2eeType.NONE },
} satisfies MatrixInfo;
let useRoomEncryptionSystemMock: MockedFunction<typeof useRoomEncryptionSystem>;
// The view is what these tests are about, so the slot is a stand-in
function mockSlot(): RTCSlot {
return mockRTCSlot(testScope(), {
localMember$: constant(
mockRTCMember(true, {
membership: localRtcMember,
tracks$: constant([]),
}),
),
remoteMembers$: constant([
mockRTCMember(false, {
membership: aliceRtcMember,
tracks$: constant([]),
}),
]),
});
}
beforeEach(() => {
vi.clearAllMocks();
createRTCSlotMock.mockImplementation((scope: ObservableScope) =>
mockRTCSlot(scope, {
localMember$: constant(
mockRTCMember(true, {
membership: localRtcMember,
tracks$: constant([]),
}),
),
remoteMembers$: constant([
mockRTCMember(false, {
membership: aliceRtcMember,
tracks$: constant([]),
}),
]),
}),
);
// MemberAudioRenderer is tested separately.
(
MemberAudioRenderer as MockedFunction<typeof MemberAudioRenderer>
@@ -132,12 +126,11 @@ interface CreateInCallViewArgs {
withAppBar?: boolean;
}
function createInCallView(args: CreateInCallViewArgs = {}): RenderResult & {
rtcSession: MockRTCSession;
vm: CallViewModel;
} {
const mediaDevices = args.mediaDevices ?? mockMediaDevices({});
const muteState = mockMuteStates();
const { vm, footerVm, developerSettingsVm, rtcSession } =
const { vm, footerVm, developerSettingsVm, matrixRoom, client } =
getBasicCallViewModelEnvironment(
[local, alice],
undefined,
@@ -145,20 +138,15 @@ function createInCallView(args: CreateInCallViewArgs = {}): RenderResult & {
args.callViewModelOptions,
);
rtcSession.joined = true;
const room = rtcSession.room;
const client = room.client;
const inCallView = (
<InCallView
client={client}
rtcSession={rtcSession.asMockedSession()}
muteStates={muteState}
vm={vm}
footerVm={footerVm}
developerSettingsVm={developerSettingsVm}
matrixInfo={matrixInfo}
matrixRoom={room}
matrixRoom={matrixRoom}
onShareClick={null}
/>
);
@@ -168,10 +156,7 @@ function createInCallView(args: CreateInCallViewArgs = {}): RenderResult & {
const renderResult = render(
<BrowserRouter>
<MediaDevicesContext value={mediaDevices}>
<ReactionsSenderProvider
vm={vm}
rtcSession={rtcSession.asMockedSession()}
>
<ReactionsSenderProvider vm={vm} room={matrixRoom} client={client}>
<TooltipProvider>{content}</TooltipProvider>
</ReactionsSenderProvider>
</MediaDevicesContext>
@@ -179,7 +164,6 @@ function createInCallView(args: CreateInCallViewArgs = {}): RenderResult & {
);
return {
...renderResult,
rtcSession,
vm,
};
}
@@ -243,37 +227,53 @@ function fakeLocalMedia(): MatrixRTCSdk.LocalMedia {
};
}
function renderActiveCall(slot: RTCSlot): RenderResult {
const { matrixRoom } = getBasicRTCSession([local, alice]);
return render(
<BrowserRouter>
<MediaDevicesContext value={mockMediaDevices({})}>
<BackgroundEffectsProvider
effects={createAppBackgroundEffects(testScope())}
>
<TooltipProvider>
<ActiveCall
client={matrixRoom.client}
slot={slot}
sentCallNotification$={NEVER}
matrixRoom={matrixRoom}
muteStates={mockMuteStates()}
matrixInfo={matrixInfo}
onShareClick={null}
e2eeSystem={{ kind: E2eeType.NONE }}
media={fakeLocalMedia()}
onLeft={(): void => {}}
/>
</TooltipProvider>
</BackgroundEffectsProvider>
</MediaDevicesContext>
</BrowserRouter>,
);
}
describe("ActiveCall", () => {
it("creates the view models and renders the call", async () => {
const mediaDevices = mockMediaDevices({});
const { rtcSession, matrixRoom } = getBasicRTCSession([local, alice]);
const { findByTestId } = render(
<BrowserRouter>
<MediaDevicesContext value={mediaDevices}>
<BackgroundEffectsProvider
effects={createAppBackgroundEffects(testScope())}
>
<TooltipProvider>
<ActiveCall
client={matrixRoom.client}
rtcSession={rtcSession.asMockedSession()}
matrixRoom={matrixRoom}
muteStates={mockMuteStates()}
matrixInfo={matrixInfo}
onShareClick={null}
e2eeSystem={{ kind: E2eeType.NONE }}
media={fakeLocalMedia()}
onLeft={(): void => {}}
/>
</TooltipProvider>
</BackgroundEffectsProvider>
</MediaDevicesContext>
</BrowserRouter>,
);
const { findByTestId } = renderActiveCall(mockSlot());
// Rendering at all proves ActiveCall created all of its view models
expect(await findByTestId("incall_leave")).toBeVisible();
});
it("leaves the slot once gone, so that the next call can join it", async () => {
const slot = mockSlot();
const { findByTestId, unmount } = renderActiveCall(slot);
await findByTestId("incall_leave");
expect(slot.join).toHaveBeenCalled();
const participation = slot.participation$.value!;
expect(participation.leave).not.toHaveBeenCalled();
unmount();
expect(participation.leave).toHaveBeenCalled();
});
it("lays the call out for the size of its root element", async () => {
// jsdom has no layout and no ResizeObserver: the root reports whatever
// size we say, and the observer notifies whenever we tell it to
@@ -296,7 +296,7 @@ describe("ActiveCall", () => {
try {
const mediaDevices = mockMediaDevices({});
const { rtcSession, matrixRoom } = getBasicRTCSession([local, alice]);
const { matrixRoom } = getBasicRTCSession([local, alice]);
const { findByTestId, container } = render(
<BrowserRouter>
<RootElementProvider value={root}>
@@ -307,7 +307,8 @@ describe("ActiveCall", () => {
<TooltipProvider>
<ActiveCall
client={matrixRoom.client}
rtcSession={rtcSession.asMockedSession()}
slot={mockSlot()}
sentCallNotification$={NEVER}
matrixRoom={matrixRoom}
muteStates={mockMuteStates()}
matrixInfo={matrixInfo}
+98 -43
View File
@@ -18,7 +18,7 @@ import {
type ReactNode,
} from "react";
import useMeasure from "react-use-measure";
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
import { type Observable } from "rxjs";
import classNames from "classnames";
import { logger as rootLogger } from "matrix-js-sdk/lib/logger";
import { useTranslation } from "react-i18next";
@@ -31,7 +31,11 @@ import { useRootElement } from "../RootElementContext";
import { observeElementSize$ } from "../utils/elementSize";
import styles from "./InCallView.module.css";
import { GridTile } from "../tile/GridTile";
import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal";
import {
SettingsModal,
type SettingsClientParts,
defaultSettingsTab,
} from "../settings/SettingsModal";
import { useRageshakeRequestModal } from "../settings/submit-rageshake";
import { RageshakeRequestModal } from "./RageshakeRequestModal";
import { useWakeLock } from "../useWakeLock";
@@ -70,9 +74,8 @@ import { ReactionsAudioRenderer } from "./ReactionAudioRenderer";
import { ReactionsOverlay } from "./ReactionsOverlay";
import { CallEventAudioRenderer } from "./CallEventAudioRenderer";
import {
createRTCSlot,
type RTCParticipationOptions,
type RTCSlotOptions,
type RTCSlot,
constant,
} from "@element-hq/matrixrtc-sdk";
import {
@@ -94,7 +97,10 @@ import {
screenShareResolution,
} from "../settings/settings";
import { Config } from "../config/Config";
import { createSentCallNotification$ } from "../state/CallViewModel/CallNotificationLifecycle.ts";
import {
type CallNotificationWrapper,
createSentCallNotification$,
} from "../state/CallViewModel/CallNotificationLifecycle.ts";
import { ReactionsReader } from "../reactions/ReactionsReader";
import { MemberAudioRenderer } from "../tracks/MemberAudioRenderer.tsx";
import { muteAllAudio$ } from "../state/MuteAllAudioModel.ts";
@@ -132,6 +138,56 @@ export interface ActiveCallProps extends Omit<
InCallViewProps,
"vm" | "footerVm" | "developerSettingsVm"
> {
client: Pick<
MatrixClient,
// Our own identity: call view model, footer, settings
| "getUserId"
| "getDeviceId"
// Developer settings: the local transport and authenticating with it,
// `getOpenIdToken` for the JWT service flow, `getLivekitToken` for the
// client-server API flow (MSC4195)
| "getDomain"
| "getOpenIdToken"
| "getLivekitToken"
// Reactions and raised hands: sending, lowering, and decrypting
| "sendEvent"
| "redactEvent"
| "decryptEventIfNeeded"
// `on`/`off`, to listen for `MatrixEventEvent.Decrypted` (reactions once
// decrypted)
| "on"
| "off"
// Profile: display name and avatar, for the settings and the call ended view
| "getUser"
| "setDisplayName"
| "setAvatarUrl"
| "uploadContent"
// Developer settings
| "doesServerSupportUnstableFeature"
| "getCrypto"
>;
matrixRoom: Pick<
MatrixRoom,
// Call view model and reactions
| "roomId"
// Joined and invited members, for the call view model
| "getMembersWithMembership"
// Call notifications, for the call view model
| "_unstable_getStickyEvents"
// Raised hands already in the room, for the reactions reader
| "relations"
// `on`/`off`, to listen for:
// - `RoomStateEvent.Members` (call view model members)
// - `RoomEvent.Timeline` and `RoomStickyEventsEvent.Update` (call notifications)
// - `RoomEvent.Timeline`, `RoomEvent.Redaction` and
// `RoomEvent.LocalEchoUpdated` (reactions and raised hands)
| "on"
| "off"
>;
/** The slot to join; the call leaves it again when it ends. */
slot: RTCSlot;
/** The call notifications sent with our join, so the call can show it ringing. */
sentCallNotification$: Observable<CallNotificationWrapper>;
e2eeSystem: EncryptionSystem;
/** The tracks the lobby opened, for the join to publish. */
media: LocalMedia;
@@ -159,18 +215,17 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
useEffect(() => {
rootLogger.info("START CALL VIEW SCOPE");
const scope = new ObservableScope();
const reactionsReader = new ReactionsReader(scope, props.rtcSession);
const reactionsReader = new ReactionsReader(
scope,
props.slot.members$,
props.matrixRoom,
props.client,
);
const { autoLeaveWhenOthersLeft, waitForCallPickup, sendNotificationType } =
urlParams;
const capture = captureSettings();
const slot = createRTCSlot(
scope,
props.client,
props.matrixRoom,
rtcSlotOptions(props.e2eeSystem),
);
const rtcParticipation = slot.join({
const rtcParticipation = props.slot.join({
...rtcParticipationOptions(urlParams),
// Without a lobby nothing was captured and the join captures itself
publish:
@@ -186,13 +241,19 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
const vm = createCallViewModel$(
scope,
rtcParticipation,
props.matrixRoom,
mediaDevices,
props.muteStates,
{
rtcParticipation,
matrixRoom: props.matrixRoom,
client: props.client,
mediaDevices,
muteStates: props.muteStates,
encryptionSystem: props.e2eeSystem,
viewSize$: scope.behavior(observeElementSize$(rootElement)),
handsRaisedSubject$: reactionsReader.raisedHands$,
reactionsSubject$: reactionsReader.reactions$,
},
{
...callViewModelOptionsFromParams(urlParams),
encryptionSystem: props.e2eeSystem,
capture,
backgroundEffectsState$,
hostBridge,
@@ -200,22 +261,22 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
waitForCallPickup: waitForCallPickup && sendNotificationType === "ring",
sentCallNotification$: createSentCallNotification$(
scope,
props.rtcSession,
props.sentCallNotification$,
),
windowSize$: scope.behavior(observeElementSize$(rootElement)),
},
reactionsReader.raisedHands$,
reactionsReader.reactions$,
);
setVm(vm);
vm.leave$.pipe(scope.bind()).subscribe(props.onLeft);
return (): void => {
// The slot outlives the call, and joins again only once this has left
rtcParticipation.leave();
scope.end();
};
}, [
props.rtcSession,
props.slot,
props.sentCallNotification$,
props.matrixRoom,
props.muteStates,
props.e2eeSystem,
@@ -249,7 +310,6 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
scope.end();
};
}, [
props.rtcSession,
props.matrixRoom,
props.muteStates,
props.e2eeSystem,
@@ -266,7 +326,11 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
if (developerSettingsVm === null) return null;
return (
<ReactionsSenderProvider vm={vm} rtcSession={props.rtcSession}>
<ReactionsSenderProvider
vm={vm}
room={props.matrixRoom}
client={props.client}
>
<InCallView
{...props}
vm={vm}
@@ -278,13 +342,12 @@ export const ActiveCall: FC<ActiveCallProps> = (props) => {
};
export interface InCallViewProps {
client: MatrixClient;
client: SettingsClientParts;
vm: CallViewModel;
footerVm: ViewModel<FooterSnapshot>;
developerSettingsVm: ViewModel<DeveloperSettingsSnapshot>;
matrixInfo: MatrixInfo;
rtcSession: MatrixRTCSession;
matrixRoom: MatrixRoom;
matrixRoom: Pick<MatrixRoom, "roomId">;
muteStates: MuteStates;
onShareClick: (() => void) | null;
}
@@ -796,31 +859,23 @@ export function captureSettings(): CaptureSettings {
}
/**
* What the client needs from Element Call's configuration, settings and URL:
* What the join needs from Element Call's configuration, settings and URL:
* the SDK reads none of them itself. What to publish depends on the mute
* switches and the devices, so the caller adds that. Shared with the legacy
* SDK bundle so that a widget built from it behaves like the app.
*/
export function rtcSlotOptions(
encryptionSystem: EncryptionSystem,
): RTCSlotOptions {
return {
encryptionSystem,
// matrix_rtc_mode in config.json overrides the user's Developer Settings
// choice. We merely sample the current mode here, so the user would need
// to manually rejoin to switch to a different one.
matrixRTCMode:
(Config.get().matrix_rtc_mode as MatrixRTCMode | undefined) ??
matrixRTCModeSetting.value$.value,
};
}
export function rtcParticipationOptions(
urlParams: ReturnType<typeof useUrlParams>,
): Omit<RTCParticipationOptions, "publish"> {
const config = Config.get();
const session = config.matrix_rtc_session;
return {
// matrix_rtc_mode in config.json overrides the user's Developer Settings
// choice. We merely sample the current mode here, so the user would need
// to manually rejoin to switch to a different one.
matrixRTCMode:
(config.matrix_rtc_mode as MatrixRTCMode | undefined) ??
matrixRTCModeSetting.value$.value,
sendNotificationType: urlParams.sendNotificationType,
callIntent: urlParams.callIntent,
timings: {
+1 -1
View File
@@ -29,7 +29,7 @@ import { useRoomEncryptionSystem } from "../e2ee/sharedKeyManagement";
import { QrCode } from "../QrCode";
interface Props {
room: Room;
room: Pick<Room, "roomId" | "name">;
open: boolean;
onDismiss: () => void;
}
-1
View File
@@ -71,7 +71,6 @@ export const KnockLobbyView: FC<Props> = ({
userId: client.getUserId() ?? "",
displayName: profile.displayName,
avatarUrl: profile.avatarUrl,
roomAlias: null,
roomId: roomSummary.room_id,
roomName: roomSummary.name ?? "",
roomAvatar: roomSummary.avatar_url ?? null,
-1
View File
@@ -91,7 +91,6 @@ const matrixInfo = {
avatarUrl: "",
roomId: "!room:example.org",
roomName: "Test Room",
roomAlias: null,
roomAvatar: null,
e2eeSystem: { kind: E2eeType.NONE } satisfies EncryptionSystem,
};
+6 -3
View File
@@ -7,7 +7,6 @@ Please see LICENSE in the repository root for full details.
import { type FC, useCallback, useState, type JSX, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { type MatrixClient } from "matrix-js-sdk";
import { Button } from "@vector-im/compound-web";
import classNames from "classnames";
import { logger } from "matrix-js-sdk/lib/logger";
@@ -23,7 +22,11 @@ import { Header, LeftNav, RightNav, RoomHeaderInfo } from "../Header";
import { type MatrixInfo, VideoPreview } from "./VideoPreview";
import { type MuteStates } from "../state/MuteStates";
import { InviteButton } from "../button/InviteButton";
import { SettingsModal, defaultSettingsTab } from "../settings/SettingsModal";
import {
SettingsModal,
type SettingsClientParts,
defaultSettingsTab,
} from "../settings/SettingsModal";
import { useRootSizeMatches } from "../useRootSize";
import { E2eeType } from "../e2ee/e2eeType";
import { LeaveToHomeLink } from "../button/LeaveToHomeLink";
@@ -46,7 +49,7 @@ import { captureSettings } from "./InCallView";
const noVideoTrack = constant<LocalVideoMediaTrack | null>(null);
interface Props {
client: MatrixClient;
client: SettingsClientParts;
matrixInfo: MatrixInfo;
/** The media to open the devices on; the join takes it over. */
media: LocalMedia;
+29 -4
View File
@@ -6,7 +6,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type FC, useEffect, useState, type ReactNode, useRef } from "react";
import {
type FC,
useEffect,
useMemo,
useState,
type ReactNode,
useRef,
} from "react";
import { type MatrixError } from "matrix-js-sdk";
import { logger } from "matrix-js-sdk/lib/logger";
import { Trans, useTranslation } from "react-i18next";
@@ -27,6 +34,7 @@ import { Link } from "../button/Link";
import { ErrorView } from "../ErrorView";
import { usePageTitle } from "../usePageTitle";
import { useRoomName } from "./useRoomName";
import { createCallMatrixBackend } from "../CallMatrixBackend";
export const RoomPage: FC = (): ReactNode => {
const urlParams = useUrlParams();
@@ -51,9 +59,14 @@ export const RoomPage: FC = (): ReactNode => {
// The page title is the page's to set, not the call's: a host embedding the
// call has a title of its own. So it is set here, for whichever room we have
// got as far as knowing about.
const roomName = useRoomName(
groupCallState.kind === "loaded" ? groupCallState.rtcSession.room : null,
const loadedRoom =
groupCallState.kind === "loaded" ? groupCallState.room : null;
const backend = useMemo(
() =>
client && loadedRoom ? createCallMatrixBackend(client, loadedRoom) : null,
[client, loadedRoom],
);
const roomName = useRoomName(loadedRoom);
usePageTitle(
roomName ??
(groupCallState.kind === "canKnock" ||
@@ -90,6 +103,18 @@ export const RoomPage: FC = (): ReactNode => {
if (optInAnalytics === null && setOptInAnalytics) setOptInAnalytics(true);
}, [optInAnalytics, setOptInAnalytics]);
useEffect(() => {
// Sanity check the room object
if (
client &&
loadedRoom !== null &&
client.getRoom(loadedRoom.roomId) !== loadedRoom
)
logger.warn(
`We've ended up with multiple rooms for the same ID (${loadedRoom.roomId}). This indicates a bug in the group call loading code, and may lead to incomplete room state.`,
);
}, [client, loadedRoom]);
const wasInWaitForInviteState = useRef<boolean>(false);
useEffect(() => {
@@ -103,7 +128,7 @@ export const RoomPage: FC = (): ReactNode => {
case "loaded":
return (
<CallView
client={client!}
backend={backend!}
rtcSession={groupCallState.rtcSession}
isPasswordlessUser={passwordlessUser}
confineToRoom={confineToRoom}
-1
View File
@@ -19,7 +19,6 @@ describe("VideoPreview", () => {
roomId: "",
roomName: "",
e2eeSystem: { kind: E2eeType.NONE },
roomAlias: null,
roomAvatar: null,
};
-1
View File
@@ -25,7 +25,6 @@ export type MatrixInfo = {
avatarUrl: string;
roomId: string;
roomName: string;
roomAlias: string | null;
roomAvatar: string | null;
e2eeSystem: EncryptionSystem;
};
+4 -2
View File
@@ -10,9 +10,11 @@ import { useCallback } from "react";
import type { JoinRule, Room } from "matrix-js-sdk";
import { useRoomState } from "./useRoomState";
export function useJoinRule(room: Room): JoinRule {
export function useJoinRule(
room: Pick<Room, "getJoinRule" | "on" | "off">,
): JoinRule {
return useRoomState(
room,
useCallback((state) => state.getJoinRule(), []),
useCallback(() => room.getJoinRule(), [room]),
);
}
+8 -3
View File
@@ -38,6 +38,7 @@ import { useUrlParams } from "../UrlParams";
export type GroupCallLoaded = {
kind: "loaded";
room: Room;
rtcSession: MatrixRTCSession;
};
@@ -327,13 +328,15 @@ export const useLoadGroupCall = (
return room;
};
const fetchOrCreateGroupCall = async (): Promise<MatrixRTCSession> => {
const fetchOrCreateGroupCall = async (): Promise<
Pick<GroupCallLoaded, "room" | "rtcSession">
> => {
const room = await fetchOrCreateRoom();
activeRoom.current = room;
logger.debug(`Fetched / joined room ${roomIdOrAlias}`);
const rtcSession = client.matrixRTC.getRoomSession(room);
return rtcSession;
return { room, rtcSession };
};
const waitForClientSyncing = async (): Promise<void> => {
@@ -367,7 +370,9 @@ export const useLoadGroupCall = (
logger.log("Start loading group call");
waitForClientSyncing()
.then(fetchOrCreateGroupCall)
.then((rtcSession) => setState({ kind: "loaded", rtcSession }))
.then(({ room, rtcSession }) =>
setState({ kind: "loaded", room, rtcSession }),
)
.then(observeMyMembership)
.catch((error) => setState({ kind: "failed", error }));
}
+10 -1
View File
@@ -10,7 +10,16 @@ import { type Room } from "matrix-js-sdk";
import { useRoomState } from "./useRoomState";
export function useRoomAvatar(room: Room): string | null {
export function useRoomAvatar(
room: Pick<
Room,
// The avatar itself
| "getMxcAvatarUrl"
// `on`/`off` for its changes, for `useRoomState`
| "on"
| "off"
>,
): string | null {
return useRoomState(
room,
useCallback(() => room.getMxcAvatarUrl(), [room]),
+5 -3
View File
@@ -12,9 +12,11 @@ import { useCallback, useSyncExternalStore } from "react";
* The room's name, kept up to date. Null when there is no room yet, for a
* caller that only sometimes has one.
*/
export function useRoomName(room: Room): string;
export function useRoomName(room: Room | null): string | null;
export function useRoomName(room: Room | null): string | null {
type RoomNameParts = Pick<Room, "name" | "on" | "off">;
export function useRoomName(room: RoomNameParts): string;
export function useRoomName(room: RoomNameParts | null): string | null;
export function useRoomName(room: RoomNameParts | null): string | null {
const subscribe = useCallback(
(onChange: () => void) => {
if (room === null) return (): void => {};

Some files were not shown because too many files have changed in this diff Show More