-
Notifications
You must be signed in to change notification settings - Fork 190
Connection stability and E2EE key exchange improvements #3761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alisonjenkins
wants to merge
6
commits into
element-hq:livekit
Choose a base branch
from
alisonjenkins:alisonjenkins/connection-stability-e2ee
base: livekit
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−10
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c19304
Skip local participant in MatrixAudioRenderer track filter
alisonjenkins 0142560
Debounce homeserver connection signals to prevent spurious reconnects
alisonjenkins 4675a54
Debounce reconnecting$ and deduplicate local connection updates
alisonjenkins cb3b185
Add E2EE key exchange timing diagnostics to MatrixKeyProvider
alisonjenkins 9575593
Expose useKeyDelay and keyRotationGracePeriodMs config options
alisonjenkins 2a5a3ee
Pre-warm Olm sessions during lobby to speed up E2EE key exchange
alisonjenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| Copyright 2026 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE in the repository root for full details. | ||
| */ | ||
|
|
||
| import { useEffect } from "react"; | ||
| import { type MatrixClient, type Room } from "matrix-js-sdk"; | ||
| import { type CallMembership } from "matrix-js-sdk/lib/matrixrtc"; | ||
| import { logger as rootLogger } from "matrix-js-sdk/lib/logger"; | ||
|
|
||
| const logger = rootLogger.getChild("[OlmPrewarm]"); | ||
|
|
||
| /** | ||
| * Pre-warms Olm sessions with current call participants while the user is in | ||
| * the lobby. This avoids a `/keys/claim` round-trip when actually joining the | ||
| * call and distributing E2EE media encryption keys. | ||
| * | ||
| * Internally calls `CryptoApi.prepareToEncrypt(room)` which triggers | ||
| * `KeyClaimManager.ensureSessionsForUsers()` for all room members, establishing | ||
| * Olm sessions with any devices we haven't communicated with before. | ||
| * | ||
| * @param client - The Matrix client. | ||
| * @param room - The room the call is in. | ||
| * @param memberships - Current call memberships (used to trigger re-warming | ||
| * when new participants join while the user is still in the lobby). | ||
| * @param enabled - Pass `false` to disable (e.g. when the user has already | ||
| * joined the call or E2EE is not in use). | ||
| */ | ||
| export function usePrewarmOlmSessions( | ||
| client: MatrixClient, | ||
| room: Room, | ||
| memberships: CallMembership[], | ||
| enabled: boolean, | ||
| ): void { | ||
| useEffect(() => { | ||
| if (!enabled) return; | ||
| if (memberships.length === 0) return; | ||
|
|
||
| const crypto = client.getCrypto(); | ||
| if (!crypto) { | ||
| logger.debug("No crypto available, skipping Olm session pre-warming"); | ||
| return; | ||
| } | ||
|
|
||
| logger.info( | ||
| `Pre-warming Olm sessions for room ${room.roomId} (${memberships.length} call members)`, | ||
| ); | ||
| crypto.prepareToEncrypt(room); | ||
| }, [client, room, memberships, enabled]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,10 +76,9 @@ export function LivekitRoomAudioRenderer({ | |
| .filter((ref) => ref.publication.kind === Track.Kind.Audio) | ||
| // Only keep tracks from participants that are in the validIdentities list | ||
| .filter((ref) => { | ||
| if (ref.participant.isLocal) return false; | ||
| const isValid = validIdentities.includes(ref.participant.identity); | ||
| if (!isValid) { | ||
| // TODO make sure to also skip the warn logging for the local identity | ||
| // Log that there is an invalid identity, that means that someone is publishing audio that is not expected to be in the call. | ||
| prefixedLogger.warn( | ||
|
Comment on lines
80
to
83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove this? |
||
| `Audio track ${ref.participant.identity} from ${url} has no matching matrix call member`, | ||
| `current members: ${validIdentities.join()}`, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log is wrong. Or at least misleading. we are preparing for all room members. not just the N call members with this right?