From eefe2195c9143843295721c75e56d86a85809366 Mon Sep 17 00:00:00 2001 From: Timo Date: Fri, 10 Jan 2025 11:32:35 +0100 Subject: [PATCH] convert interface to abstract class. --- src/matrixrtc/LocalMembershipManager.ts | 39 ++++++++++++------------- src/matrixrtc/MatrixRTCSession.ts | 7 +++-- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/matrixrtc/LocalMembershipManager.ts b/src/matrixrtc/LocalMembershipManager.ts index 0d0f0856e0..0b62f3e03d 100644 --- a/src/matrixrtc/LocalMembershipManager.ts +++ b/src/matrixrtc/LocalMembershipManager.ts @@ -11,26 +11,25 @@ import { Focus } from "./focus.ts"; import { isLivekitFocusActive } from "./LivekitFocus.ts"; import { MembershipConfig } from "./MatrixRTCSession.ts"; -export interface LocalMembershipManagerInterface { - constructor: ( +export abstract class LocalMembershipManagerInterface { + public constructor( joinConfig: MembershipConfig | undefined, - room: { - getLiveTimeline: () => void; - }, - client: { - sendState: () => void; - // eslint-disable-next-line @typescript-eslint/naming-convention - unstable_sendDelayedState: () => void; - // eslint-disable-next-line @typescript-eslint/naming-convention - unstable_sendDelayedEvent: () => void; - // eslint-disable-next-line @typescript-eslint/naming-convention - unstable_updateDelayedEvent: () => void; - }, - ) => MembershipManagerInterface; - isJoined(): boolean; - leave(timeout: number | undefined): Promise; - onMembershipsUpdate(): Promise; - getActiveFocus(): Focus | undefined; + room: Pick, + client: Pick< + MatrixClient, + | "getUserId" + | "getDeviceId" + | "sendStateEvent" + | "_unstable_sendDelayedEvent" + | "_unstable_sendDelayedStateEvent" + >, + getOldestMembership: () => CallMembership | undefined, + ) {} + public abstract isJoined(): boolean; + public abstract join(fociPreferred: Focus[], fociActive?: Focus): void; + public abstract leave(timeout: number | undefined): Promise; + public abstract onMembershipsUpdate(): Promise; + public abstract getActiveFocus(): Focus | undefined; } /** @@ -85,11 +84,9 @@ export class LocalMembershipManager { 8_000 ); } - private get membershipKeepAlivePeriod(): number { return this.joinConfig?.membershipKeepAlivePeriod ?? 5_000; } - private get callMemberEventRetryJitter(): number { return this.joinConfig?.callMemberEventRetryJitter ?? 2_000; } diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index 9538a3b8ad..5a1c5f738f 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 { LocalMembershipManager } from "./LocalMembershipManager.ts"; +import { LocalMembershipManager, LocalMembershipManagerInterface } from "./LocalMembershipManager.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?: LocalMembershipManager; + private membershipManager?: LocalMembershipManagerInterface; // The session Id of the call, this is the call_id of the call Member event. private _callId: string | undefined; @@ -283,6 +283,7 @@ export class MatrixRTCSession extends TypedEventEmitter