@@ -160,7 +160,7 @@ export type JoinSessionConfig = MembershipConfig & EncryptionConfig;
160
160
*/
161
161
export class MatrixRTCSession extends TypedEventEmitter < MatrixRTCSessionEvent , MatrixRTCSessionEventHandlerMap > {
162
162
private membershipManager ?: IMembershipManager ;
163
- private encryptionManager : IEncryptionManager ;
163
+ private encryptionManager ? : IEncryptionManager ;
164
164
// The session Id of the call, this is the call_id of the call Member event.
165
165
private _callId : string | undefined ;
166
166
@@ -317,18 +317,6 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
317
317
// TODO: double check if this is actually needed. Should be covered by refreshRoom in MatrixRTCSessionManager
318
318
roomState ?. on ( RoomStateEvent . Members , this . onRoomMemberUpdate ) ;
319
319
this . setExpiryTimer ( ) ;
320
-
321
- const transport = new RoomKeyTransport ( this . roomSubset , this . client , this . statistics ) ;
322
- this . encryptionManager = new EncryptionManager (
323
- this . client . getUserId ( ) ! ,
324
- this . client . getDeviceId ( ) ! ,
325
- ( ) => this . memberships ,
326
- transport ,
327
- this . statistics ,
328
- ( keyBin : Uint8Array < ArrayBufferLike > , encryptionKeyIndex : number , participantId : string ) => {
329
- this . emit ( MatrixRTCSessionEvent . EncryptionKeyChanged , keyBin , encryptionKeyIndex , participantId ) ;
330
- } ,
331
- ) ;
332
320
}
333
321
334
322
/*
@@ -381,6 +369,18 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
381
369
this . getOldestMembership ( ) ,
382
370
) ;
383
371
}
372
+ // Create Encryption manager
373
+ const transport = new RoomKeyTransport ( this . roomSubset , this . client , this . statistics ) ;
374
+ this . encryptionManager = new EncryptionManager (
375
+ this . client . getUserId ( ) ! ,
376
+ this . client . getDeviceId ( ) ! ,
377
+ ( ) => this . memberships ,
378
+ transport ,
379
+ this . statistics ,
380
+ ( keyBin : Uint8Array < ArrayBufferLike > , encryptionKeyIndex : number , participantId : string ) => {
381
+ this . emit ( MatrixRTCSessionEvent . EncryptionKeyChanged , keyBin , encryptionKeyIndex , participantId ) ;
382
+ } ,
383
+ ) ;
384
384
}
385
385
386
386
// Join!
@@ -412,7 +412,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
412
412
413
413
logger . info ( `Leaving call session in room ${ this . roomSubset . roomId } ` ) ;
414
414
415
- this . encryptionManager . leave ( ) ;
415
+ this . encryptionManager ! . leave ( ) ;
416
416
417
417
const leavePromise = this . membershipManager ! . leave ( timeout ) ;
418
418
this . emit ( MatrixRTCSessionEvent . JoinStateChanged , false ) ;
@@ -452,7 +452,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
452
452
* the keys.
453
453
*/
454
454
public reemitEncryptionKeys ( ) : void {
455
- this . encryptionManager . getEncryptionKeys ( ) . forEach ( ( keys , participantId ) => {
455
+ this . encryptionManager ? .getEncryptionKeys ( ) . forEach ( ( keys , participantId ) => {
456
456
keys . forEach ( ( key , index ) => {
457
457
this . emit ( MatrixRTCSessionEvent . EncryptionKeyChanged , key . key , index , participantId ) ;
458
458
} ) ;
@@ -467,7 +467,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
467
467
*/
468
468
public getEncryptionKeys ( ) : IterableIterator < [ string , Array < Uint8Array > ] > {
469
469
const keys =
470
- this . encryptionManager . getEncryptionKeys ( ) ??
470
+ this . encryptionManager ? .getEncryptionKeys ( ) ??
471
471
new Map < string , Array < { key : Uint8Array ; timestamp : number } > > ( ) ;
472
472
// the returned array doesn't contain the timestamps
473
473
return Array . from ( keys . entries ( ) )
@@ -540,7 +540,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
540
540
}
541
541
// This also needs to be done if `changed` = false
542
542
// A member might have updated their fingerprint (created_ts)
543
- void this . encryptionManager . onMembershipsUpdate ( oldMemberships ) ;
543
+ void this . encryptionManager ? .onMembershipsUpdate ( oldMemberships ) ;
544
544
545
545
this . setExpiryTimer ( ) ;
546
546
} ;
0 commit comments