Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert interface to abstract class.
Browse files Browse the repository at this point in the history
toger5 committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 395c1e4 commit 9b6bc3f
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
@@ -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");

@@ -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;
@@ -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();
}
@@ -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();
39 changes: 18 additions & 21 deletions src/matrixrtc/MembershipManager.ts
Original file line number Diff line number Diff line change
@@ -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 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;
}

/**
@@ -85,11 +84,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;
}

0 comments on commit 9b6bc3f

Please sign in to comment.