1
1
import { type MatrixClient } from "../client.ts" ;
2
- import { logger } from "../logger.ts" ;
2
+ import { logger as rootLogger } from "../logger.ts" ;
3
3
import { MatrixEvent } from "../models/event.ts" ;
4
4
import { Room } from "../models/room.ts" ;
5
5
import { EncryptionConfig } from "./MatrixRTCSession.ts" ;
@@ -9,9 +9,10 @@ import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
9
9
import { MatrixError , safeGetRetryAfterMs } from "../http-api/errors.ts" ;
10
10
import { CallMembership } from "./CallMembership.ts" ;
11
11
import { EventType } from "../@types/event.ts" ;
12
+ const logger = rootLogger . getChild ( "MatrixRTCSession" ) ;
12
13
13
14
/**
14
- * A type collecting call encryption statistics.
15
+ * A type collecting call encryption statistics for a session .
15
16
*/
16
17
export type Statistics = {
17
18
counters : {
@@ -23,16 +24,27 @@ export type Statistics = {
23
24
} ;
24
25
} ;
25
26
27
+ /**
28
+ * This interface is for testing and for making it possible to interchange the encryption manager.
29
+ * @internal
30
+ */
26
31
export interface IEncryptionManager {
27
32
join ( joinConfig : EncryptionConfig | undefined ) : void ;
28
33
leave ( ) : void ;
29
34
onMembershipsUpdate ( oldMemberships : CallMembership [ ] ) : Promise < void > ;
30
- onCallEncryption ( event : MatrixEvent ) : void ;
31
- requestSendCurrentKey ( ) : void ;
35
+ onCallEncryptionEventReceived ( event : MatrixEvent ) : void ;
32
36
getEncryptionKeys ( ) : Map < string , Array < { key : Uint8Array ; timestamp : number } > > ;
33
37
statistics : Statistics ;
34
38
}
35
39
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
+ */
36
48
export class EncryptionManager implements IEncryptionManager {
37
49
private manageMediaKeys = false ;
38
50
private keysEventUpdateTimeout ?: ReturnType < typeof setTimeout > ;
@@ -58,9 +70,6 @@ export class EncryptionManager implements IEncryptionManager {
58
70
59
71
private currentEncryptionKeyIndex = - 1 ;
60
72
61
- /**
62
- * The statistics for this session.
63
- */
64
73
public statistics : Statistics = {
65
74
counters : {
66
75
/**
@@ -205,7 +214,7 @@ export class EncryptionManager implements IEncryptionManager {
205
214
* Requests that we resend our current keys to the room. May send a keys event immediately
206
215
* or queue for alter if one has already been sent recently.
207
216
*/
208
- public requestSendCurrentKey ( ) : void {
217
+ private requestSendCurrentKey ( ) : void {
209
218
if ( ! this . manageMediaKeys ) return ;
210
219
211
220
if (
@@ -316,7 +325,7 @@ export class EncryptionManager implements IEncryptionManager {
316
325
*
317
326
* @param event the event to process
318
327
*/
319
- public onCallEncryption = ( event : MatrixEvent ) : void => {
328
+ public onCallEncryptionEventReceived = ( event : MatrixEvent ) : void => {
320
329
const userId = event . getSender ( ) ;
321
330
const content = event . getContent < EncryptionKeysEventContent > ( ) ;
322
331
0 commit comments