Skip to content

Commit 532ecee

Browse files
committed
review
1 parent 1dddd19 commit 532ecee

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/matrixrtc/EncryptionManager.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type MatrixClient } from "../client.ts";
2-
import { logger } from "../logger.ts";
2+
import { logger as rootLogger } from "../logger.ts";
33
import { MatrixEvent } from "../models/event.ts";
44
import { Room } from "../models/room.ts";
55
import { EncryptionConfig } from "./MatrixRTCSession.ts";
@@ -9,9 +9,10 @@ import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
99
import { MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts";
1010
import { CallMembership } from "./CallMembership.ts";
1111
import { EventType } from "../@types/event.ts";
12+
const logger = rootLogger.getChild("MatrixRTCSession");
1213

1314
/**
14-
* A type collecting call encryption statistics.
15+
* A type collecting call encryption statistics for a session.
1516
*/
1617
export type Statistics = {
1718
counters: {
@@ -23,16 +24,27 @@ export type Statistics = {
2324
};
2425
};
2526

27+
/**
28+
* This interface is for testing and for making it possible to interchange the encryption manager.
29+
* @internal
30+
*/
2631
export interface IEncryptionManager {
2732
join(joinConfig: EncryptionConfig | undefined): void;
2833
leave(): void;
2934
onMembershipsUpdate(oldMemberships: CallMembership[]): Promise<void>;
30-
onCallEncryption(event: MatrixEvent): void;
31-
requestSendCurrentKey(): void;
35+
onCallEncryptionEventReceived(event: MatrixEvent): void;
3236
getEncryptionKeys(): Map<string, Array<{ key: Uint8Array; timestamp: number }>>;
3337
statistics: Statistics;
3438
}
3539

40+
/**
41+
* This class implements the IEncryptionManager interface,
42+
* and takes care of managing the encryption keys of all rtc members:
43+
* - generate new keys for the local user and send them to other participants
44+
* - track all keys of all other members and update livekit.
45+
*
46+
* @internal
47+
*/
3648
export class EncryptionManager implements IEncryptionManager {
3749
private manageMediaKeys = false;
3850
private keysEventUpdateTimeout?: ReturnType<typeof setTimeout>;
@@ -58,9 +70,6 @@ export class EncryptionManager implements IEncryptionManager {
5870

5971
private currentEncryptionKeyIndex = -1;
6072

61-
/**
62-
* The statistics for this session.
63-
*/
6473
public statistics: Statistics = {
6574
counters: {
6675
/**
@@ -205,7 +214,7 @@ export class EncryptionManager implements IEncryptionManager {
205214
* Requests that we resend our current keys to the room. May send a keys event immediately
206215
* or queue for alter if one has already been sent recently.
207216
*/
208-
public requestSendCurrentKey(): void {
217+
private requestSendCurrentKey(): void {
209218
if (!this.manageMediaKeys) return;
210219

211220
if (
@@ -316,7 +325,7 @@ export class EncryptionManager implements IEncryptionManager {
316325
*
317326
* @param event the event to process
318327
*/
319-
public onCallEncryption = (event: MatrixEvent): void => {
328+
public onCallEncryptionEventReceived = (event: MatrixEvent): void => {
320329
const userId = event.getSender();
321330
const content = event.getContent<EncryptionKeysEventContent>();
322331

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
412412
* @param event the event to process
413413
*/
414414
public onCallEncryption = (event: MatrixEvent): void => {
415-
this.encryptionManager.onCallEncryption(event);
415+
this.encryptionManager.onCallEncryptionEventReceived(event);
416416
};
417417

418418
/**

0 commit comments

Comments
 (0)