one e2ee worker per session

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo K
2025-09-15 17:49:07 +02:00
parent e08f16f889
commit c8098734cd
2 changed files with 29 additions and 25 deletions

View File

@@ -1,3 +1,4 @@
// TODO not used anymore - remove
/*
Copyright 2023, 2024 New Vector Ltd.

View File

@@ -8,7 +8,7 @@ Please see LICENSE in the repository root for full details.
import { observeParticipantEvents } from "@livekit/components-core";
import {
ConnectionState,
type E2EEOptions,
type BaseKeyProvider,
ExternalE2EEKeyProvider,
type Room as LivekitRoom,
type LocalParticipant,
@@ -433,7 +433,7 @@ function getRoomMemberFromRtcMember(
export class CallViewModel extends ViewModel {
private readonly livekitAlias = getLivekitAlias(this.matrixRTCSession);
private readonly livekitE2EERoomOptions = getE2eeOptions(
private readonly livekitE2EEKeyProvider = getE2eeKeyProvider(
this.options.encryptionSystem,
this.matrixRTCSession,
);
@@ -450,10 +450,25 @@ export class CallViewModel extends ViewModel {
this.membershipsAndFocusMap$,
this.mediaDevices,
this.muteStates,
this.livekitE2EERoomOptions,
this.livekitE2EEKeyProvider
? {
keyProvider: this.livekitE2EEKeyProvider,
worker: new E2EEWorker(),
}
: undefined,
),
);
private readonly memberships$ = this.scope.behavior(
fromEvent(
this.matrixRTCSession,
MatrixRTCSessionEvent.MembershipsChanged,
).pipe(
startWith(null),
map(() => this.matrixRTCSession.memberships),
),
);
private readonly membershipsAndFocusMap$ = this.scope.behavior(
this.memberships$.pipe(
map((memberships) =>
@@ -496,7 +511,12 @@ export class CallViewModel extends ViewModel {
this.matrixRTCSession.room.client,
this.scope,
this.membershipsAndFocusMap$,
this.livekitE2EERoomOptions,
this.livekitE2EEKeyProvider
? {
keyProvider: this.livekitE2EEKeyProvider,
worker: new E2EEWorker(),
}
: undefined,
);
} else {
logger.log(
@@ -623,16 +643,6 @@ export class CallViewModel extends ViewModel {
// in a split-brained state.
private readonly pretendToBeDisconnected$ = this.reconnecting$;
private readonly memberships$ = this.scope.behavior(
fromEvent(
this.matrixRTCSession,
MatrixRTCSessionEvent.MembershipsChanged,
).pipe(
startWith(null),
pauseWhen(this.pretendToBeDisconnected$),
map(() => this.matrixRTCSession.memberships),
),
);
private readonly participants$ = this.scope.behavior<
{
@@ -1875,28 +1885,21 @@ export class CallViewModel extends ViewModel {
// TODO-MULTI-SFU // Setup and update the keyProvider which was create by `createRoom` was a thing before. Now we never update if the E2EEsystem changes
// do we need this?
function getE2eeOptions(
function getE2eeKeyProvider(
e2eeSystem: EncryptionSystem,
rtcSession: MatrixRTCSession,
): E2EEOptions | undefined {
return undefined;
): BaseKeyProvider | undefined {
if (e2eeSystem.kind === E2eeType.NONE) return undefined;
if (e2eeSystem.kind === E2eeType.PER_PARTICIPANT) {
const keyProvider = new MatrixKeyProvider();
keyProvider.setRTCSession(rtcSession);
return {
keyProvider,
worker: new E2EEWorker(),
};
return keyProvider;
} else if (e2eeSystem.kind === E2eeType.SHARED_KEY && e2eeSystem.secret) {
const keyProvider = new ExternalE2EEKeyProvider();
keyProvider
.setKey(e2eeSystem.secret)
.catch((e) => logger.error("Failed to set shared key for E2EE", e));
return {
keyProvider,
worker: new E2EEWorker(),
};
return keyProvider;
}
}