11import { type MatrixClient } from "../client.ts" ;
2- import { logger } from "../logger.ts" ;
2+ import { logger as rootLogger } from "../logger.ts" ;
33import { MatrixEvent } from "../models/event.ts" ;
44import { Room } from "../models/room.ts" ;
55import { EncryptionConfig } from "./MatrixRTCSession.ts" ;
@@ -9,9 +9,10 @@ import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
99import { MatrixError , safeGetRetryAfterMs } from "../http-api/errors.ts" ;
1010import { CallMembership } from "./CallMembership.ts" ;
1111import { 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 */
1617export 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+ */
2631export 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+ */
3648export 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
0 commit comments