From 00d4e72419246b40e7cc2d133226adbebde999c5 Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 10 Jan 2025 17:23:27 +0100 Subject: [PATCH] renaming public api --- src/matrixrtc/MatrixRTCSession.ts | 28 +++++++++++++++--------- src/matrixrtc/MatrixRTCSessionManager.ts | 2 +- src/matrixrtc/MembershipManager.ts | 11 ++++++---- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index 3c311ccf4a..1c2e35b8c4 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -29,7 +29,7 @@ import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts"; import { KnownMembership } from "../@types/membership.ts"; import { MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts"; import { MatrixEvent } from "../models/event.ts"; -import { MembershipManager, MembershipManagerInterface } from "./MembershipManager.ts"; +import { LegacyMembershipManager, IMembershipManager } from "./MembershipManager.ts"; const logger = rootLogger.getChild("MatrixRTCSession"); @@ -132,7 +132,7 @@ export type JoinSessionConfig = MembershipConfig & EncryptionConfig; * This class doesn't deal with media at all, just membership & properties of a session. */ export class MatrixRTCSession extends TypedEventEmitter { - private membershipManager?: MembershipManagerInterface; + private membershipManager?: IMembershipManager; // The session Id of the call, this is the call_id of the call Member event. private _callId: string | undefined; @@ -284,7 +284,7 @@ export class MatrixRTCSession extends TypedEventEmitter + this.membershipManager = new LegacyMembershipManager(joinConfig, this.room, this.client, () => this.getOldestMembership(), ); } @@ -652,7 +652,7 @@ export class MatrixRTCSession extends TypedEventEmitter { - this.onMembershipsUpdate(); + this.recalculateSessionMembers(); + }; + public onRoomMemberUpdate = (): void => { + this.recalculateSessionMembers(); + }; + public onRTCSessionMemberUpdate = (): void => { + this.recalculateSessionMembers(); }; /** + * Call this when anything that could impact rtc memberships has changed: Room Members or RTC members. + * * Examines the latest call memberships and handles any encryption key sending or rotation that is needed. * * This function should be called when the room members or call memberships might have changed. */ - public onMembershipsUpdate = (): void => { + private recalculateSessionMembers = (): void => { const oldMemberships = this.memberships; this.memberships = MatrixRTCSession.callMembershipsForRoom(this.room); @@ -781,7 +789,7 @@ export class MatrixRTCSession extends TypedEventEmitter 0 && !isNewSession; - sess.onMembershipsUpdate(); + sess.onRTCSessionMemberUpdate(); const nowActive = sess.memberships.length > 0; diff --git a/src/matrixrtc/MembershipManager.ts b/src/matrixrtc/MembershipManager.ts index 561677205e..e195917156 100644 --- a/src/matrixrtc/MembershipManager.ts +++ b/src/matrixrtc/MembershipManager.ts @@ -17,11 +17,14 @@ import { MembershipConfig } from "./MatrixRTCSession.ts"; * * @internal */ -export interface MembershipManagerInterface { +export interface IMembershipManager { isJoined(): boolean; join(fociPreferred: Focus[], fociActive?: Focus): void; leave(timeout: number | undefined): Promise; - onMembershipsUpdate(memberships: CallMembership[]): Promise; + /** + * call this if the MatrixRTC session members have changed + */ + onRTCSessionMemberUpdate(memberships: CallMembership[]): Promise; getActiveFocus(): Focus | undefined; } @@ -41,7 +44,7 @@ export interface MembershipManagerInterface { * * @internal */ -export class MembershipManager implements MembershipManagerInterface { +export class LegacyMembershipManager implements IMembershipManager { private relativeExpiry: number | undefined; private memberEventTimeout?: ReturnType; @@ -135,7 +138,7 @@ export class MembershipManager implements MembershipManagerInterface { } } - public async onMembershipsUpdate(memberships: CallMembership[]): Promise { + public async onRTCSessionMemberUpdate(memberships: CallMembership[]): Promise { const isMyMembership = (m: CallMembership): boolean => m.sender === this.client.getUserId() && m.deviceId === this.client.getDeviceId();