|
1 | 1 | import { logger as rootLogger } from "../logger.ts";
|
2 |
| -import { Statistics, type EncryptionConfig } from "./MatrixRTCSession.ts"; |
| 2 | +import { type EncryptionConfig } from "./MatrixRTCSession.ts"; |
3 | 3 | import { secureRandomBase64Url } from "../randomstring.ts";
|
4 | 4 | import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts";
|
5 | 5 | import { safeGetRetryAfterMs } from "../http-api/errors.ts";
|
6 | 6 | import { type CallMembership } from "./CallMembership.ts";
|
7 |
| -import { KeyTransportEventListener, KeyTransportEvents, type IKeyTransport } from "./IKeyTransport.ts"; |
| 7 | +import { type KeyTransportEventListener, KeyTransportEvents, type IKeyTransport } from "./IKeyTransport.ts"; |
| 8 | +import { isMyMembership, type Statistics } from "./types.ts"; |
8 | 9 |
|
9 | 10 | const logger = rootLogger.getChild("MatrixRTCSession");
|
10 | 11 |
|
11 | 12 | /**
|
12 | 13 | * This interface is for testing and for making it possible to interchange the encryption manager.
|
13 | 14 | * @internal
|
14 | 15 | */
|
| 16 | +/** |
| 17 | + * Interface representing an encryption manager for handling encryption-related |
| 18 | + * operations in a real-time communication context. |
| 19 | + */ |
15 | 20 | export interface IEncryptionManager {
|
| 21 | + /** |
| 22 | + * Joins the encryption manager with the provided configuration. |
| 23 | + * |
| 24 | + * @param joinConfig - The configuration for joining encryption, or undefined |
| 25 | + * if no specific configuration is provided. |
| 26 | + */ |
16 | 27 | join(joinConfig: EncryptionConfig | undefined): void;
|
17 | 28 |
|
| 29 | + /** |
| 30 | + * Leaves the encryption manager, cleaning up any associated resources. |
| 31 | + */ |
18 | 32 | leave(): void;
|
19 | 33 |
|
| 34 | + /** |
| 35 | + * Called from the MatrixRTCSession when the memberships in this session updated. |
| 36 | + * |
| 37 | + * @param oldMemberships - The previous state of call memberships before the update. |
| 38 | + */ |
20 | 39 | onMembershipsUpdate(oldMemberships: CallMembership[]): void;
|
21 | 40 |
|
| 41 | + /** |
| 42 | + * Retrieves the encryption keys currently managed by the encryption manager. |
| 43 | + * |
| 44 | + * @returns A map where the keys are identifiers and the values are arrays of |
| 45 | + * objects containing encryption keys and their associated timestamps. |
| 46 | + */ |
22 | 47 | getEncryptionKeys(): Map<string, Array<{ key: Uint8Array; timestamp: number }>>;
|
23 | 48 | }
|
24 | 49 |
|
@@ -112,17 +137,16 @@ export class EncryptionManager implements IEncryptionManager {
|
112 | 137 | this.joined = false;
|
113 | 138 | }
|
114 | 139 |
|
115 |
| - // TODO deduplicate this method. It also is in MatrixRTCSession. |
116 |
| - private isMyMembership = (m: CallMembership): boolean => m.sender === this.userId && m.deviceId === this.deviceId; |
117 |
| - |
118 | 140 | public onMembershipsUpdate(oldMemberships: CallMembership[]): void {
|
119 | 141 | if (this.manageMediaKeys && this.joined) {
|
120 | 142 | const oldMembershipIds = new Set(
|
121 |
| - oldMemberships.filter((m) => !this.isMyMembership(m)).map(getParticipantIdFromMembership), |
| 143 | + oldMemberships |
| 144 | + .filter((m) => !isMyMembership(m, this.userId, this.deviceId)) |
| 145 | + .map(getParticipantIdFromMembership), |
122 | 146 | );
|
123 | 147 | const newMembershipIds = new Set(
|
124 | 148 | this.getMemberships()
|
125 |
| - .filter((m) => !this.isMyMembership(m)) |
| 149 | + .filter((m) => !isMyMembership(m, this.userId, this.deviceId)) |
126 | 150 | .map(getParticipantIdFromMembership),
|
127 | 151 | );
|
128 | 152 |
|
@@ -272,7 +296,7 @@ export class EncryptionManager implements IEncryptionManager {
|
272 | 296 | private storeLastMembershipFingerprints(): void {
|
273 | 297 | this.lastMembershipFingerprints = new Set(
|
274 | 298 | this.getMemberships()
|
275 |
| - .filter((m) => !this.isMyMembership(m)) |
| 299 | + .filter((m) => !isMyMembership(m, this.userId, this.deviceId)) |
276 | 300 | .map((m) => `${getParticipantIdFromMembership(m)}:${m.createdTs()}`),
|
277 | 301 | );
|
278 | 302 | }
|
|
0 commit comments