Skip to content

Commit

Permalink
convert interface to abstract class.
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Jan 10, 2025
1 parent ac97746 commit 5873e3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from "./MembershipManager.ts";
import { MembershipManager, MembershipManagerInterface } from "./MembershipManager.ts";

const logger = rootLogger.getChild("MatrixRTCSession");

Expand Down Expand Up @@ -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<MatrixRTCSessionEvent, MatrixRTCSessionEventHandlerMap> {
private membershipManager?: MembershipManager;
private membershipManager?: MembershipManagerInterface;

// The session Id of the call, this is the call_id of the call Member event.
private _callId: string | undefined;
Expand Down Expand Up @@ -283,6 +283,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
super();
this._callId = memberships[0]?.callId;
const roomState = this.room.getLiveTimeline().getState(EventTimeline.FORWARDS);
// TODO: double check if this is actually needed. Should be covered by refreshRoom in MatrixRTCSessionManager
roomState?.on(RoomStateEvent.Members, this.onMembershipsUpdate);
this.setExpiryTimer();
}
Expand Down Expand Up @@ -332,7 +333,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
this.getOldestMembership(),
);
}
this.membershipManager.join(fociPreferred, fociActive);
this.membershipManager!.join(fociPreferred, fociActive);
this.manageMediaKeys = joinConfig?.manageMediaKeys ?? this.manageMediaKeys;
if (joinConfig?.manageMediaKeys) {
this.makeNewSenderKey();
Expand Down
39 changes: 18 additions & 21 deletions src/matrixrtc/MembershipManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ import { Focus } from "./focus.ts";
import { isLivekitFocusActive } from "./LivekitFocus.ts";
import { MembershipConfig } from "./MatrixRTCSession.ts";

export interface MembershipManagerInterface {
constructor: (
export abstract class MembershipManagerInterface {
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<boolean>;
onMembershipsUpdate(): Promise<void>;
getActiveFocus(): Focus | undefined;
room: Pick<Room, "getLiveTimeline">,
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<boolean>;
public abstract onMembershipsUpdate(): Promise<void>;
public abstract getActiveFocus(): Focus | undefined;
}

/**
Expand Down Expand Up @@ -83,11 +82,9 @@ export class MembershipManager {
8_000
);
}

private get membershipKeepAlivePeriod(): number {
return this.joinConfig?.membershipKeepAlivePeriod ?? 5_000;
}

private get callMemberEventRetryJitter(): number {
return this.joinConfig?.callMemberEventRetryJitter ?? 2_000;
}
Expand Down

0 comments on commit 5873e3a

Please sign in to comment.