diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index de00b2e666..ed5c98f5c4 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -20,18 +20,16 @@ import { EventTimeline } from "../models/event-timeline.ts"; import { Room } from "../models/room.ts"; import { MatrixClient } from "../client.ts"; import { EventType } from "../@types/event.ts"; -import { UpdateDelayedEventAction } from "../@types/requests.ts"; -import { CallMembership, DEFAULT_EXPIRE_DURATION, SessionMembershipData } from "./CallMembership.ts"; +import { CallMembership } from "./CallMembership.ts"; import { RoomStateEvent } from "../models/room-state.ts"; import { Focus } from "./focus.ts"; import { secureRandomBase64Url } from "../randomstring.ts"; import { EncryptionKeysEventContent } from "./types.ts"; import { decodeBase64, encodeUnpaddedBase64 } from "../base64.ts"; import { KnownMembership } from "../@types/membership.ts"; -import { HTTPError, MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts"; +import { MatrixError, safeGetRetryAfterMs } from "../http-api/errors.ts"; import { MatrixEvent } from "../models/event.ts"; -import { isLivekitFocusActive } from "./LivekitFocus.ts"; -import { sleep } from "../utils.ts"; +import { MyMembershipManager } from "./MatrixRTCMyMembershipManager.ts"; const logger = rootLogger.getChild("MatrixRTCSession"); @@ -294,22 +292,19 @@ export class MatrixRTCSession extends TypedEventEmitter { - await this.leaveRoomSession(1000); + await this.myMembershipManager?.leaveRoomSession(1000); if (this.expiryTimeout) { clearTimeout(this.expiryTimeout); this.expiryTimeout = undefined; } - if (this.memberEventTimeout) { - clearTimeout(this.memberEventTimeout); - this.memberEventTimeout = undefined; - } + this.myMembershipManager?.stop(); const roomState = this.room.getLiveTimeline().getState(EventTimeline.FORWARDS); roomState?.off(RoomStateEvent.Members, this.onMembershipUpdate); } @@ -332,22 +327,19 @@ export class MatrixRTCSession extends TypedEventEmitter + this.getOldestMembership(), + ); } - - this.ownFocusActive = fociActive; - this.ownFociPreferred = fociPreferred; this.joinConfig = joinConfig; - this.relativeExpiry = this.membershipExpiryTimeout; this.manageMediaKeys = joinConfig?.manageMediaKeys ?? this.manageMediaKeys; - - logger.info(`Joining call session in room ${this.room.roomId} with manageMediaKeys=${this.manageMediaKeys}`); + this.myMembershipManager.setJoined(fociPreferred, fociActive); if (joinConfig?.manageMediaKeys) { this.makeNewSenderKey(); this.requestSendCurrentKey(); } - // We don't wait for this, mostly because it may fail and schedule a retry, so this - // function returning doesn't really mean anything at all. - this.triggerCallMembershipEventUpdate(); + this.myMembershipManager.joinRoomSession(); this.emit(MatrixRTCSessionEvent.JoinStateChanged, true); } @@ -389,35 +381,14 @@ export class MatrixRTCSession extends TypedEventEmitter