matrix-js-sdk 42.4.0 → 43.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/lib/@types/PushRules.d.ts +3 -1
- package/lib/@types/PushRules.d.ts.map +1 -1
- package/lib/@types/PushRules.js +2 -0
- package/lib/@types/PushRules.js.map +1 -1
- package/lib/@types/event.d.ts +1 -0
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -1
- package/lib/client.d.ts +88 -37
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +72 -47
- package/lib/client.js.map +1 -1
- package/lib/crypto-api/index.d.ts +3 -3
- package/lib/crypto-api/index.d.ts.map +1 -1
- package/lib/crypto-api/index.js.map +1 -1
- package/lib/embedded.d.ts +17 -1
- package/lib/embedded.d.ts.map +1 -1
- package/lib/embedded.js +46 -1
- package/lib/embedded.js.map +1 -1
- package/lib/errors.d.ts +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +2 -2
- package/lib/errors.js.map +1 -1
- package/lib/http-api/fetch.d.ts +7 -1
- package/lib/http-api/fetch.d.ts.map +1 -1
- package/lib/http-api/fetch.js +14 -5
- package/lib/http-api/fetch.js.map +1 -1
- package/lib/http-api/interface.d.ts +34 -8
- package/lib/http-api/interface.d.ts.map +1 -1
- package/lib/http-api/interface.js +10 -3
- package/lib/http-api/interface.js.map +1 -1
- package/lib/http-api/refresh.d.ts +30 -11
- package/lib/http-api/refresh.d.ts.map +1 -1
- package/lib/http-api/refresh.js +72 -5
- package/lib/http-api/refresh.js.map +1 -1
- package/lib/matrix.d.ts +1 -1
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js.map +1 -1
- package/lib/matrixrtc/CallMembership.d.ts.map +1 -1
- package/lib/matrixrtc/CallMembership.js +20 -6
- package/lib/matrixrtc/CallMembership.js.map +1 -1
- package/lib/matrixrtc/IMembershipManager.d.ts +5 -0
- package/lib/matrixrtc/IMembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/IMembershipManager.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +27 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +1 -1
- package/lib/matrixrtc/MatrixRTCSession.js +58 -36
- package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +1 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +1 -1
- package/lib/matrixrtc/MembershipManager.d.ts +76 -0
- package/lib/matrixrtc/MembershipManager.d.ts.map +1 -1
- package/lib/matrixrtc/MembershipManager.js +264 -47
- package/lib/matrixrtc/MembershipManager.js.map +1 -1
- package/lib/matrixrtc/index.d.ts +1 -1
- package/lib/matrixrtc/index.d.ts.map +1 -1
- package/lib/matrixrtc/index.js +1 -1
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/membershipData/common.d.ts +8 -0
- package/lib/matrixrtc/membershipData/common.d.ts.map +1 -1
- package/lib/matrixrtc/membershipData/common.js +10 -0
- package/lib/matrixrtc/membershipData/common.js.map +1 -1
- package/lib/matrixrtc/membershipData/index.d.ts +1 -1
- package/lib/matrixrtc/membershipData/index.d.ts.map +1 -1
- package/lib/matrixrtc/membershipData/index.js +1 -1
- package/lib/matrixrtc/membershipData/index.js.map +1 -1
- package/lib/matrixrtc/types.d.ts +104 -11
- package/lib/matrixrtc/types.d.ts.map +1 -1
- package/lib/matrixrtc/types.js +263 -19
- package/lib/matrixrtc/types.js.map +1 -1
- package/lib/matrixrtc/utils.d.ts +22 -1
- package/lib/matrixrtc/utils.d.ts.map +1 -1
- package/lib/matrixrtc/utils.js +38 -0
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/models/room-sticky-events.d.ts +7 -0
- package/lib/models/room-sticky-events.d.ts.map +1 -1
- package/lib/models/room-sticky-events.js +27 -0
- package/lib/models/room-sticky-events.js.map +1 -1
- package/lib/models/thread.d.ts.map +1 -1
- package/lib/models/thread.js +8 -0
- package/lib/models/thread.js.map +1 -1
- package/lib/oauth/authorize.js +1 -1
- package/lib/oauth/authorize.js.map +1 -1
- package/lib/oauth/index.d.ts +3 -5
- package/lib/oauth/index.d.ts.map +1 -1
- package/lib/oauth/index.js +7 -7
- package/lib/oauth/index.js.map +1 -1
- package/lib/oauth/tokenRefresher.d.ts +10 -4
- package/lib/oauth/tokenRefresher.d.ts.map +1 -1
- package/lib/oauth/tokenRefresher.js +34 -24
- package/lib/oauth/tokenRefresher.js.map +1 -1
- package/lib/receipt-accumulator.d.ts +10 -11
- package/lib/receipt-accumulator.d.ts.map +1 -1
- package/lib/receipt-accumulator.js +26 -25
- package/lib/receipt-accumulator.js.map +1 -1
- package/lib/room-summary-api.d.ts +71 -0
- package/lib/room-summary-api.d.ts.map +1 -0
- package/lib/room-summary-api.js +82 -0
- package/lib/room-summary-api.js.map +1 -0
- package/lib/rust-crypto/backup.d.ts +7 -0
- package/lib/rust-crypto/backup.d.ts.map +1 -1
- package/lib/rust-crypto/backup.js +41 -25
- package/lib/rust-crypto/backup.js.map +1 -1
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +6 -1
- package/lib/sync.js.map +1 -1
- package/package.json +6 -6
- package/src/@types/PushRules.ts +2 -0
- package/src/@types/event.ts +1 -1
- package/src/@types/matrix-sdk-crypto-wasm.d.ts +15 -12
- package/src/client.ts +105 -62
- package/src/crypto-api/index.ts +3 -3
- package/src/embedded.ts +61 -2
- package/src/errors.ts +2 -1
- package/src/http-api/fetch.ts +14 -5
- package/src/http-api/interface.ts +36 -8
- package/src/http-api/refresh.ts +101 -17
- package/src/matrix.ts +1 -1
- package/src/matrixrtc/CallMembership.ts +22 -4
- package/src/matrixrtc/IMembershipManager.ts +6 -0
- package/src/matrixrtc/MatrixRTCSession.ts +72 -49
- package/src/matrixrtc/MatrixRTCSessionManager.ts +1 -1
- package/src/matrixrtc/MembershipManager.ts +284 -61
- package/src/matrixrtc/index.ts +7 -1
- package/src/matrixrtc/membershipData/common.ts +12 -0
- package/src/matrixrtc/membershipData/index.ts +1 -1
- package/src/matrixrtc/types.ts +351 -23
- package/src/matrixrtc/utils.ts +54 -1
- package/src/models/room-sticky-events.ts +26 -1
- package/src/models/thread.ts +9 -0
- package/src/oauth/authorize.ts +1 -1
- package/src/oauth/index.ts +7 -8
- package/src/oauth/tokenRefresher.ts +15 -5
- package/src/receipt-accumulator.ts +30 -26
- package/src/room-summary-api.ts +114 -0
- package/src/rust-crypto/backup.ts +46 -33
- package/src/sync.ts +9 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MatrixRTCSession.js","names":[],"sources":["../../src/matrixrtc/MatrixRTCSession.ts"],"sourcesContent":["/*\nCopyright 2023 - 2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger, logger as rootLogger } from \"../logger.ts\";\nimport { TypedEventEmitter } from \"../models/typed-event-emitter.ts\";\nimport { EventTimeline } from \"../models/event-timeline.ts\";\nimport { type Room } from \"../models/room.ts\";\nimport { type MatrixClient } from \"../client.ts\";\nimport { EventType, RelationType } from \"../@types/event.ts\";\nimport { KnownMembership } from \"../@types/membership.ts\";\nimport { type ISendEventResponse } from \"../@types/requests.ts\";\nimport { CallMembership } from \"./CallMembership.ts\";\nimport { RoomStateEvent } from \"../models/room-state.ts\";\nimport { MembershipManager, StickyEventMembershipManager } from \"./MembershipManager.ts\";\nimport { type CallMembershipIdentityParts, type IEncryptionManager } from \"./EncryptionManager.ts\";\nimport { deepCompare, logDurationSync } from \"../utils.ts\";\nimport type {\n Statistics,\n RTCNotificationType,\n Status,\n IRTCNotificationContent,\n RTCCallIntent,\n Transport,\n SlotDescription,\n RtcSlotEventContent,\n RtcSlotEncryptionContent,\n} from \"./types.ts\";\nimport {\n MembershipManagerEvent,\n type MembershipManagerEventHandlerMap,\n type IMembershipManager,\n} from \"./IMembershipManager.ts\";\nimport { RTCEncryptionManager } from \"./RTCEncryptionManager.ts\";\nimport { ToDeviceKeyTransport } from \"./ToDeviceKeyTransport.ts\";\nimport { TypedReEmitter } from \"../ReEmitter.ts\";\nimport { type IContent, type MatrixEvent } from \"../models/event.ts\";\nimport { RoomStickyEventsEvent, type RoomStickyEventsMap } from \"../models/room-sticky-events.ts\";\nimport { computeSlotId } from \"./utils.ts\";\n\n/**\n * Events emitted by MatrixRTCSession\n */\nexport enum MatrixRTCSessionEvent {\n // A member joined, left, or updated a property of their membership.\n MembershipsChanged = \"memberships_changed\",\n // We joined or left the session: our own local idea of whether we are joined,\n // separate from MembershipsChanged, ie. independent of whether our member event\n // has successfully gone through.\n JoinStateChanged = \"join_state_changed\",\n // The key used to encrypt media has changed\n EncryptionKeyChanged = \"encryption_key_changed\",\n /** The membership manager had to shut down caused by an unrecoverable error */\n MembershipManagerError = \"membership_manager_error\",\n /** The RTCSession did send a call notification caused by joining the call as the first member */\n DidSendCallNotification = \"did_send_call_notification\",\n /** Whether the session is too large for the media key to be rotated has changed */\n KeyRotationSuppressedChanged = \"key_rotation_suppressed_changed\",\n}\n\nexport type MatrixRTCSessionEventHandlerMap = {\n [MatrixRTCSessionEvent.MembershipsChanged]: (\n oldMemberships: CallMembership[],\n newMemberships: CallMembership[],\n ) => void;\n [MatrixRTCSessionEvent.JoinStateChanged]: (isJoined: boolean) => void;\n [MatrixRTCSessionEvent.EncryptionKeyChanged]: (\n key: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => void;\n [MatrixRTCSessionEvent.MembershipManagerError]: (error: unknown) => void;\n [MatrixRTCSessionEvent.DidSendCallNotification]: (\n notificationContentNew: { event_id: string } & IRTCNotificationContent,\n ) => void;\n [MatrixRTCSessionEvent.KeyRotationSuppressedChanged]: (isKeyRotationSuppressed: boolean) => void;\n};\n\nexport interface SessionConfig {\n /**\n * What kind of notification to send when starting the session.\n * @default `undefined` (no notification)\n */\n notificationType?: RTCNotificationType;\n\n /**\n * Determines the kind of call this will be.\n */\n callIntent?: RTCCallIntent;\n\n /**\n * How long (in milliseconds) the callee's client should keep ringing/waiting for an\n * answer before the sender gives up and the call notification is considered timed out.\n */\n notificationLifetimeMs?: number;\n}\n\n// The names follow these principles:\n// - we use the technical term delay if the option is related to delayed events.\n// - we use delayedLeaveEvent if the option is related to the delayed leave event.\n// - we use membershipEvent if the option is related to the rtc member state event.\n// - we use the technical term expiry if the option is related to the expiry field of the membership state event.\n// - we use a `Ms` postfix if the option is a duration to avoid using words like:\n// `time`, `duration`, `delay`, `timeout`... that might be mistaken/confused with technical terms.\nexport interface MembershipConfig {\n /**\n * The timeout (in milliseconds) after we joined the call, that our membership should expire\n * unless we have explicitly updated it.\n *\n * This is what goes into the m.rtc.member event expiry field and is typically set to a number of hours.\n */\n membershipEventExpiryMs?: number;\n\n /**\n * The time in (in milliseconds) which the manager will prematurely send the updated state event before the membership `expires` time to make sure it\n * sends the updated state event early enough.\n *\n * A headroom of 1000ms and a `membershipExpiryTimeout` of 10000ms would result in the first membership event update after 9s and\n * a membership event that would be considered expired after 10s.\n *\n * This value does not have an effect on the value of `SessionMembershipData.expires`.\n */\n membershipEventExpiryHeadroomMs?: number;\n\n /**\n * The timeout (in milliseconds) with which the deleayed leave event on the server is configured.\n * After this time the server will set the event to the disconnected stat if it has not received a keep-alive from the client.\n */\n delayedLeaveEventDelayMs?: number;\n\n /**\n * The interval (in milliseconds) in which the client will send membership keep-alives to the server.\n */\n delayedLeaveEventRestartMs?: number;\n\n /**\n * The maximum number of retries that the manager will do for delayed event sending/updating and state event sending when a server rate limit has been hit.\n */\n maximumRateLimitRetryCount?: number;\n\n /**\n * The maximum number of retries that the manager will do for delayed event sending/updating and state event sending when a network error occurs.\n */\n maximumNetworkErrorRetryCount?: number;\n\n /**\n * The time (in milliseconds) after which we will retry a http request if it\n * failed to send due to a network error. (send membership event, send delayed event, restart delayed event...)\n */\n networkErrorRetryMs?: number;\n\n /**\n * The time (in milliseconds) after which a we consider a delayed event restart http request to have failed.\n * Setting this to a lower value will result in more frequent retries but also a higher chance of failiour.\n *\n * In the presence of network packet loss (hurting TCP connections), the custom delayedEventRestartLocalTimeoutMs\n * helps by keeping more delayed event reset candidates in flight,\n * improving the chances of a successful reset. (its is equivalent to the js-sdk `localTimeout` configuration,\n * but only applies to calls to the `_unstable_restartScheduledDelayedEvent` endpoint\n * or the `_unstable_updateDelayedEvent` endpoint with a body of `{action:\"restart\"}`.)\n */\n delayedLeaveEventRestartLocalTimeoutMs?: number;\n\n /**\n * Send membership using sticky events rather than state events.\n * This also make the client use the new m.rtc.member MSC4354 event format. (instead of m.call.member)\n *\n * **WARNING**: This is an unstable feature and not all clients will support it.\n */\n unstableSendStickyEvents?: boolean;\n}\n\nexport interface EncryptionConfig {\n /**\n * If true, generate and share a media key for this participant,\n * and emit MatrixRTCSessionEvent.EncryptionKeyChanged when\n * media keys for other participants become available.\n */\n manageMediaKeys?: boolean;\n /**\n * The minimum time (in milliseconds) between each attempt to send encryption key(s).\n * e.g. if this is set to 1000, then we will send at most one key event every second.\n * @deprecated - Not used by the new encryption manager.\n */\n updateEncryptionKeyThrottle?: number;\n\n /**\n * Sometimes it is necessary to rotate the encryption key after a membership update.\n * For performance reasons we might not want to rotate the key immediately but allow future memberships to use the same key.\n * If 5 people join in a row in less than 5 seconds, we don't want to rotate the key for each of them.\n * If 5 people leave in a row in less than 5 seconds, we don't want to rotate the key for each of them.\n * So we do share the key which was already used live for <5s to new joiners.\n * This does result in a potential leak up to the configured time of call media.\n * This has to be considered when choosing a value for this property.\n */\n keyRotationGracePeriodMs?: number;\n\n /**\n * The number of participants in the session at which the media key will no longer be rotated.\n *\n * Rotating a key requires sending it to every participant device, so in large sessions the cost of rotating\n * on every join/leave becomes prohibitive. At this limit the current key is kept and\n * distributed to new joiners. No new keys are generated for joiners/leavers.\n *\n * Defaults to undefined.\n */\n keyRotationParticipantLimit?: number;\n\n /**\n * The delay (in milliseconds) after a member leaves before we create and publish a new key, because people\n * tend to leave calls at the same time.\n * @deprecated - Not used by the new encryption manager.\n */\n makeKeyDelay?: number;\n /**\n * The delay (in milliseconds) between sending a new key and starting to encrypt with it. This\n * gives others a chance to receive the new key to minimize the chance they get media they can't decrypt.\n *\n * The higher this value is, the better it is for existing members as they will have a smoother experience.\n * But it impacts new joiners: They will always have to wait `useKeyDelay` before being able to decrypt the media\n * (as it will be encrypted with the new key after the delay only), even if the key has already arrived before the delay.\n */\n useKeyDelay?: number;\n}\nexport type JoinSessionConfig = SessionConfig & MembershipConfig & EncryptionConfig;\n\ninterface SessionMembershipsForSlotOpts {\n /**\n * Listen for incoming sticky member events. If disabled, this session will\n * ignore any incoming sticky events.\n */\n listenForStickyEvents: boolean;\n /**\n * Listen for incoming member state events (legacy). If disabled, this session will\n * ignore any incoming state events.\n */\n listenForMemberStateEvents: boolean;\n}\n\nconst DEFAULT_SESSION_MEMBERSHIPS_FOR_SLOT_OPTS: SessionMembershipsForSlotOpts = {\n listenForStickyEvents: true,\n listenForMemberStateEvents: true,\n};\n\n/**\n * A MatrixRTCSession manages the membership & properties of a MatrixRTC session.\n * This class doesn't deal with media at all, just membership & properties of a session.\n */\nexport class MatrixRTCSession extends TypedEventEmitter<\n MatrixRTCSessionEvent | MembershipManagerEvent,\n MatrixRTCSessionEventHandlerMap & MembershipManagerEventHandlerMap\n> {\n private membershipManager?: IMembershipManager;\n private encryptionManager?: IEncryptionManager;\n private joinConfig?: SessionConfig;\n private logger: Logger;\n\n private pendingNotificationToSend: undefined | RTCNotificationType;\n /**\n * This timeout is responsible to track any expiration. We need to know when we have to start\n * to ignore other call members. There is no callback for this. This timeout will always be configured to\n * emit when the next membership expires.\n */\n private expiryTimeout?: ReturnType<typeof setTimeout>;\n\n public memberships: CallMembership[] = [];\n\n /**\n * Resolves when the session has calculated the initial membership of the session.\n */\n public readonly initialMembershipCalculated: Promise<void>;\n /**\n * Does membership need to be recalculated? This is set to false upon\n * recalculation.\n */\n private membershipNeedsRecalculation = false;\n\n /**\n * The statistics for this session.\n */\n public statistics: Statistics = {\n counters: {\n roomEventEncryptionKeysSent: 0,\n roomEventEncryptionKeysReceived: 0,\n },\n totals: {\n roomEventEncryptionKeysReceivedTotalAge: 0,\n },\n };\n\n public get membershipStatus(): Status | undefined {\n return this.membershipManager?.status;\n }\n public get probablyLeft(): boolean | undefined {\n return this.membershipManager?.probablyLeft;\n }\n public get delayId(): string | undefined {\n return this.membershipManager?.delayId;\n }\n\n /**\n * Whether the key rotation is currently halted.\n * mirror of: EncryptionConfig.keyRotationParticipantLimit\n */\n public get isKeyRotationSuppressed(): boolean {\n return this.encryptionManager?.isKeyRotationSuppressed ?? false;\n }\n\n /**\n * The callId (sessionId) of the call.\n *\n * It can be undefined since the callId is only known once the first membership joins.\n * The callId is the property that, per definition, groups memberships into one call.\n * @deprecated use `slotId` instead.\n */\n public get callId(): string | undefined {\n return this.slotDescription?.id;\n }\n /**\n * The slotId of the call.\n * `{application}#{appSpecificId}`\n * It can be undefined since the slotId is only known once the first membership joins.\n * The slotId is the property that, per definition, groups memberships into one call.\n */\n public get slotId(): string | undefined {\n return computeSlotId(this.slotDescription);\n }\n\n /**\n * Reads the current slot state event's content for this session.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for this session.\n */\n public getRtcSlot(): RtcSlotEventContent | undefined {\n return getSlotEventContent(this.roomSubset, this.slotDescription);\n }\n\n /**\n * Whether this session's slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\n public isSlotClosed(): boolean | undefined {\n return isSlotClosed(this.roomSubset, this.slotDescription);\n }\n\n /**\n * Ensures this session's slot is open, sending a slot state event to open (or create) it if needed.\n *\n * The event's `application` is set from this session's slot description and its `encryption` from\n * `opts.encryption`, replacing whatever an existing slot event declares. Other content is preserved.\n * No-op if the slot is already open with matching `application` and `encryption`.\n *\n * @param opts.encryption - The encryption to declare on the slot, or `undefined` for none.\n * @throws if sending the state event fails.\n */\n public async ensureRtcSlotOpen(opts: { encryption?: RtcSlotEncryptionContent } = {}): Promise<void> {\n const application = { type: this.slotDescription.application };\n const existingContent = this.getRtcSlot();\n if (\n existingContent?.status === \"open\" &&\n deepCompare(existingContent.application, application) &&\n deepCompare(existingContent.encryption, opts.encryption)\n ) {\n return;\n }\n await this.sendRtcSlot({\n ...existingContent,\n status: \"open\",\n application,\n encryption: opts.encryption,\n });\n }\n\n /**\n * Ensures this session's slot is closed, sending a slot state event to close it if needed.\n * The other content of the existing slot event is preserved. No-op if no slot event exists.\n *\n * @throws if sending the state event fails.\n */\n public async ensureRtcSlotClosed(): Promise<void> {\n const existingContent = this.getRtcSlot();\n if (!existingContent || existingContent.status === \"closed\") return;\n await this.sendRtcSlot({ ...existingContent, status: \"closed\" });\n }\n\n private async sendRtcSlot(content: RtcSlotEventContent): Promise<void> {\n await this.client.sendStateEvent(\n this.roomSubset.roomId,\n EventType.RTCSlot,\n content,\n computeSlotId(this.slotDescription),\n );\n }\n\n /**\n * Returns all the call memberships for a room that match the provided `sessionDescription`,\n * oldest first.\n *\n * By default, this will return *both* sticky and member state events.\n */\n public static async sessionMembershipsForSlot(\n room: Pick<Room, \"getLiveTimeline\" | \"roomId\" | \"hasMembershipState\" | \"_unstable_getStickyEvents\">,\n slotDescription: SlotDescription,\n // default both true this implied we combine sticky and state events for the final call state\n // (prefer sticky events in case of a duplicate)\n options: SessionMembershipsForSlotOpts = DEFAULT_SESSION_MEMBERSHIPS_FOR_SLOT_OPTS,\n ): Promise<CallMembership[]> {\n const logger = rootLogger.getChild(\n `[MatrixRTCSession ${room.roomId} ${slotDescription.application}#${slotDescription.id}]`,\n );\n const callMemberEvents = collectMembersEvents(room, slotDescription, options, logger);\n\n const callMemberships = await computeBackendIdentityAndVerifyMemberEvents(\n room,\n callMemberEvents,\n slotDescription,\n logger,\n );\n\n callMemberships.sort((a, b) => a.createdTs() - b.createdTs());\n if (callMemberships.length > 1) {\n logger.debug(\n `Call memberships in room ${room.roomId}, in order: `,\n callMemberships.map((m) => [m.createdTs(), m.userId]),\n );\n }\n\n return callMemberships;\n }\n\n /**\n * Return the MatrixRTC session for the room.\n * This returned session can be used to find out if there are active sessions\n * for the requested room and `slotDescription`.\n */\n public static sessionForSlot(\n client: MatrixClient,\n room: Room,\n slotDescription: SlotDescription,\n opts?: SessionMembershipsForSlotOpts,\n ): MatrixRTCSession {\n return new MatrixRTCSession(client, room, slotDescription, opts);\n }\n\n /**\n * WARN: this can in theory only be a subset of the room with the properties required by\n * this class.\n * Outside of tests this most likely will be a full room, however.\n * @deprecated Relying on a full Room object being available here is an anti-pattern. You should be tracking\n * the room object in your own code and passing it in when needed.\n */\n public get room(): Room {\n return this.roomSubset as Room;\n }\n\n /**\n * This constructs a room session. When using MatrixRTC inside the js-sdk this is expected\n * to be used with the MatrixRTCSessionManager exclusively.\n *\n * In cases where you don't use the js-sdk but build on top of another Matrix stack this class can be used standalone\n * to manage a joined MatrixRTC session.\n *\n * @param client A subset of the {@link MatrixClient} that lets the session interact with the Matrix room.\n * @param roomSubset The room this session is attached to. A subset of a js-sdk Room that the session needs.\n * @param slotDescription The slot description is a virtual address where participants are allowed to meet.\n * This session will only manage memberships that match this slot description.Sessions are distinct if any of\n * those properties are distinct: `roomSubset.roomId`, `slotDescription.application`, `slotDescription.id`.\n * @param calculateMembershipsOpts - Options to configure how memberships are calculated for this session.\n */\n public constructor(\n private readonly client: Pick<\n MatrixClient,\n | \"getUserId\"\n | \"getDeviceId\"\n | \"sendEvent\"\n | \"sendStateEvent\"\n | \"_unstable_sendDelayedStateEvent\"\n | \"_unstable_updateDelayedEvent\"\n | \"_unstable_cancelScheduledDelayedEvent\"\n | \"_unstable_restartScheduledDelayedEvent\"\n | \"_unstable_sendScheduledDelayedEvent\"\n | \"_unstable_sendStickyEvent\"\n | \"_unstable_sendStickyDelayedEvent\"\n | \"cancelPendingEvent\"\n | \"encryptAndSendToDevice\"\n | \"off\"\n | \"on\"\n | \"decryptEventIfNeeded\"\n >,\n private roomSubset: Pick<\n Room,\n | \"getLiveTimeline\"\n | \"roomId\"\n | \"getVersion\"\n | \"hasMembershipState\"\n | \"on\"\n | \"off\"\n | \"_unstable_getStickyEvents\"\n >,\n\n public readonly slotDescription: SlotDescription,\n private readonly calculateMembershipsOpts?: SessionMembershipsForSlotOpts,\n ) {\n super();\n this.logger = rootLogger.getChild(\n `[MatrixRTCSession ${roomSubset.roomId} ${slotDescription.application}#${slotDescription.id}]`,\n );\n\n this.roomSubset.on(RoomStateEvent.Members, this.onRoomMemberUpdate);\n this.roomSubset.on(RoomStateEvent.Events, this.onRoomStateEvent);\n this.roomSubset.on(RoomStickyEventsEvent.Update, this.onStickyEventUpdate);\n\n this.initialMembershipCalculated = this.ensureRecalculateSessionMembers();\n this.setExpiryTimer();\n }\n /*\n * Returns true if we intend to be participating in the MatrixRTC session.\n * This is determined by checking if the relativeExpiry has been set.\n */\n public isJoined(): boolean {\n return this.membershipManager?.isJoined() ?? false;\n }\n\n /**\n * Performs cleanup & removes timers for client shutdown\n */\n public async stop(): Promise<void> {\n await this.membershipManager?.leave(1000);\n if (this.expiryTimeout) {\n clearTimeout(this.expiryTimeout);\n this.expiryTimeout = undefined;\n }\n\n this.roomSubset.off(RoomStateEvent.Members, this.onRoomMemberUpdate);\n this.roomSubset.off(RoomStateEvent.Events, this.onRoomStateEvent);\n this.roomSubset.off(RoomStickyEventsEvent.Update, this.onStickyEventUpdate);\n }\n\n private reEmitter = new TypedReEmitter<\n MatrixRTCSessionEvent | MembershipManagerEvent,\n MatrixRTCSessionEventHandlerMap & MembershipManagerEventHandlerMap\n >(this);\n\n /**\n * Announces this user and device as joined to the MatrixRTC session,\n * and continues to update the membership event to keep it valid until\n * leaveRoomSession() is called\n * This will not subscribe to updates: remember to call subscribe() separately if\n * desired.\n * This method will return immediately and the session will be joined in the background.\n * @param ownMembershipIdentity the identity of the user and device joining the session.\n * This will be put into the content.member.\n * @param fociPreferred the list of preferred foci to use in the joined RTC membership event.\n * If multiSfuFocus is set, this is only needed if this client wants to publish to multiple transports simultaneously.\n * @param multiSfuFocus the active focus to use in the joined RTC membership event. Setting this implies the\n * membership manager will operate in a multi-SFU connection mode. If `undefined`, an `oldest_membership`\n * transport selection will be used instead.\n * @param joinConfig - Additional configuration for the joined session.\n */\n public joinRTCSession(\n ownMembershipIdentity: CallMembershipIdentityParts,\n fociPreferred: Transport[],\n multiSfuFocus?: Transport,\n joinConfig?: JoinSessionConfig,\n ): void {\n if (this.isJoined()) {\n this.logger.info(`Already joined to session in room ${this.roomSubset.roomId}: ignoring join call`);\n return;\n } else {\n // Create MembershipManager and pass the RTCSession logger (with room id info)\n this.membershipManager = joinConfig?.unstableSendStickyEvents\n ? new StickyEventMembershipManager(\n joinConfig,\n this.roomSubset,\n this.client,\n this.slotDescription,\n ownMembershipIdentity.memberId,\n this.logger,\n )\n : new MembershipManager(joinConfig, this.roomSubset, this.client, this.slotDescription, this.logger);\n\n this.reEmitter.reEmit(this.membershipManager, [\n MembershipManagerEvent.ProbablyLeft,\n MembershipManagerEvent.StatusChanged,\n MembershipManagerEvent.DelayIdChanged,\n ]);\n // Create Encryption manager\n const [room, client, statistics] = [this.roomSubset, this.client, this.statistics];\n const transport = new ToDeviceKeyTransport(ownMembershipIdentity, room.roomId, client, statistics);\n this.encryptionManager = new RTCEncryptionManager(\n ownMembershipIdentity,\n () => this.memberships,\n transport,\n (\n keyBin: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => {\n this.emit(\n MatrixRTCSessionEvent.EncryptionKeyChanged,\n keyBin,\n encryptionKeyIndex,\n membership,\n rtcBackendIdentity,\n );\n },\n this.logger,\n );\n }\n\n this.joinConfig = joinConfig;\n this.pendingNotificationToSend = this.joinConfig?.notificationType;\n\n // Join!\n this.membershipManager.join(fociPreferred, multiSfuFocus, (e) => {\n this.logger.error(\"MembershipManager encountered an unrecoverable error: \", e);\n this.emit(MatrixRTCSessionEvent.MembershipManagerError, e);\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, this.isJoined());\n });\n this.encryptionManager.join(joinConfig);\n\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, true);\n }\n\n /**\n *\n * @param fociPreferred\n * @param multiSfuFocus\n * @param joinConfig\n * @deprecated use the joinRTCSession method instead\n */\n public joinRoomSession(\n fociPreferred: Transport[],\n multiSfuFocus?: Transport,\n joinConfig?: JoinSessionConfig,\n ): void {\n const [userId, deviceId] = [this.client.getUserId()!, this.client.getDeviceId()!];\n // TODO this wants to become a UUID\n const memberId = `${userId}:${deviceId}`;\n this.joinRTCSession({ userId, deviceId, memberId }, fociPreferred, multiSfuFocus, joinConfig);\n }\n\n /**\n * Announces this user and device as having left the MatrixRTC session\n * and stops scheduled updates.\n * This will not unsubscribe from updates: remember to call unsubscribe() separately if\n * desired.\n * The membership update required to leave the session will retry if it fails.\n * Without network connection the promise will never resolve.\n * A timeout can be provided so that there is a guarantee for the promise to resolve.\n * @returns Whether the membership update was attempted and did not time out.\n */\n public async leaveRoomSession(timeout: number | undefined = undefined): Promise<boolean> {\n if (!this.isJoined()) {\n this.logger.info(`Not joined to session in room ${this.roomSubset.roomId}: ignoring leave call`);\n return false;\n }\n\n this.logger.info(`Leaving call session in room ${this.roomSubset.roomId}`);\n\n this.encryptionManager!.leave();\n\n const leavePromise = this.membershipManager!.leave(timeout);\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, false);\n\n return await leavePromise;\n }\n /**\n * This returns the focus in use by the oldest membership.\n * Do not use since this might be just the focus for the oldest membership. others might use a different focus.\n * @deprecated use `member.getTransport(session.getOldestMembership())` instead for the specific member you want to get the focus for.\n */\n public getFocusInUse(): Transport | undefined {\n const oldestMembership = this.getOldestMembership();\n return oldestMembership?.getTransport(oldestMembership);\n }\n\n public getOldestMembership(): CallMembership | undefined {\n return this.memberships[0];\n }\n\n /**\n * Get the call intent for the current call, based on what members are advertising. If one or more\n * members disagree on the current call intent, or nobody specifies one then `undefined` is returned.\n *\n * If all members that specify a call intent agree, that value is returned.\n * @returns A call intent, or `undefined` if no consensus or not given.\n */\n public getConsensusCallIntent(): RTCCallIntent | undefined {\n const getFirstCallIntent = this.memberships.find((m) => !!m.callIntent)?.callIntent;\n if (!getFirstCallIntent) {\n return undefined;\n }\n if (this.memberships.every((m) => !m.callIntent || m.callIntent === getFirstCallIntent)) {\n return getFirstCallIntent;\n }\n return undefined;\n }\n\n public async updateCallIntent(callIntent: RTCCallIntent): Promise<void> {\n const myMembership = this.membershipManager?.ownMembership;\n if (!myMembership) {\n throw Error(\"Not connected yet\");\n }\n await this.membershipManager?.updateCallIntent(callIntent);\n }\n\n /**\n * Re-emit an EncryptionKeyChanged event for each tracked encryption key. This can be used to export\n * the keys.\n */\n public reemitEncryptionKeys(): void {\n this.encryptionManager?.getEncryptionKeys().forEach((keyRing, key) => {\n keyRing.forEach((keyInfo) => {\n this.emit(\n MatrixRTCSessionEvent.EncryptionKeyChanged,\n keyInfo.key,\n keyInfo.keyIndex,\n keyInfo.membership,\n keyInfo.rtcBackendIdentity,\n );\n });\n });\n }\n\n /**\n * Sets a timer for the soonest membership expiry\n */\n private setExpiryTimer(): void {\n if (this.expiryTimeout) {\n clearTimeout(this.expiryTimeout);\n this.expiryTimeout = undefined;\n }\n\n let soonestExpiry;\n for (const membership of this.memberships) {\n const thisExpiry = membership.getMsUntilExpiry();\n // If getMsUntilExpiry is undefined we have a MSC4143 (MatrixRTC) compliant event - it never expires\n // but will be reliably resent on disconnect.\n if (thisExpiry !== undefined && (soonestExpiry === undefined || thisExpiry < soonestExpiry)) {\n soonestExpiry = thisExpiry;\n }\n }\n\n if (soonestExpiry != undefined) {\n this.expiryTimeout = setTimeout(() => void this.ensureRecalculateSessionMembers(), soonestExpiry);\n }\n }\n\n /**\n * Sends notification events to indiciate the call has started.\n * Note: This does not return a promise, instead scheduling the notification events to be sent.\n * @param parentEventId Event id linking to your RTC call membership event.\n * @param notificationType The type of notification to send\n * @param callIntent The type of call this is (e.g. \"audio\").\n */\n private sendCallNotify(\n parentEventId: string,\n notificationType: RTCNotificationType,\n callIntent?: RTCCallIntent,\n ): void {\n const lifetime = this.joinConfig?.notificationLifetimeMs ?? 90_000;\n const sendNotificationEvent = async (): Promise<{\n response: ISendEventResponse;\n content: IRTCNotificationContent;\n }> => {\n const content: IRTCNotificationContent = {\n \"m.mentions\": { user_ids: [], room: true },\n \"notification_type\": notificationType,\n \"m.relates_to\": {\n event_id: parentEventId,\n rel_type: RelationType.Reference,\n },\n \"sender_ts\": Date.now(),\n \"lifetime\": lifetime,\n };\n if (callIntent) {\n content[\"m.call.intent\"] = callIntent;\n }\n const response = await this.client.sendEvent(this.roomSubset.roomId, EventType.RTCNotification, content);\n return { response, content };\n };\n\n void sendNotificationEvent()\n .then((notification) => {\n // Join event_id and origin event content\n const newResult = { ...notification.response, ...notification.content };\n this.emit(MatrixRTCSessionEvent.DidSendCallNotification, newResult);\n })\n .catch(([errorLegacy, errorNew]) =>\n this.logger.error(\"Failed to send call notification\", errorLegacy, errorNew),\n );\n }\n\n /**\n * Call this when the Matrix room members have changed.\n */\n private readonly onRoomMemberUpdate = (): void => {\n void this.ensureRecalculateSessionMembers();\n };\n\n /**\n * Call this when a room state event has been updated.\n */\n private readonly onRoomStateEvent = (event: MatrixEvent): void => {\n if (event.getType() !== EventType.RTCSlot) return;\n if (event.getStateKey() !== computeSlotId(this.slotDescription)) return;\n void this.ensureRecalculateSessionMembers();\n };\n\n /**\n * Call this when a sticky event update has occured.\n */\n private readonly onStickyEventUpdate: RoomStickyEventsMap[RoomStickyEventsEvent.Update] = (\n added,\n updated,\n removed,\n ): void => {\n if (\n [...added, ...removed, ...updated.flatMap((v) => [v.current, v.previous])].some(\n (e) => e.getType() === EventType.RTCMembership,\n )\n ) {\n void this.ensureRecalculateSessionMembers();\n }\n };\n\n /**\n * Call this when something changed that may impacts the current MatrixRTC members in this session.\n */\n // We allow this name schema since this function should only be used for testing purposes.\n public _onRTCSessionMemberUpdate = async (): Promise<void> => {\n await this.recalculateSessionMembers();\n };\n\n // helper variables to make sure we do not have parallel running recalculations.\n private recalculateSessionMembersPromise: Promise<void> = Promise.resolve();\n\n /**\n * Ensures that membership is recalculated when the state of the session may have changed.\n * Also ensures that only one recalculation is made at a time.\n * @returns A promise resolving when the state has been recalculated.\n */\n private ensureRecalculateSessionMembers(): Promise<void> {\n if (this.membershipNeedsRecalculation) {\n // We have already requested recalcuation, don't attempt a new one.\n return this.recalculateSessionMembersPromise;\n }\n this.membershipNeedsRecalculation = true;\n // Chain the recalculation.\n this.recalculateSessionMembersPromise = this.recalculateSessionMembersPromise.then(\n () => this.recalculateSessionMembers(),\n () => this.recalculateSessionMembers(),\n );\n return this.recalculateSessionMembersPromise;\n }\n\n /**\n * Call this when anything that could impact rtc memberships has changed: Room Members or RTC members.\n *\n * Examines the latest call memberships and handles any encryption key sending or rotation that is needed.\n *\n * This function should be called when the room members or call memberships might have changed.\n */\n private readonly recalculateSessionMembers = async (): Promise<void> => {\n // Clear the flag.\n this.membershipNeedsRecalculation = false;\n const oldMemberships = this.memberships;\n // Needs to be computed before `this.memberships` is updated below, since it is derived from it.\n const wasKeyRotationSuppressed = this.isKeyRotationSuppressed;\n\n this.memberships = await MatrixRTCSession.sessionMembershipsForSlot(\n this.room,\n this.slotDescription,\n this.calculateMembershipsOpts,\n );\n\n const changed =\n oldMemberships.length != this.memberships.length ||\n oldMemberships.some((m, i) => !CallMembership.equal(m, this.memberships[i]));\n\n if (changed) {\n this.logger.info(\n `Memberships for call in room ${this.roomSubset.roomId} have changed: emitting (${this.memberships.length} members)`,\n );\n logDurationSync(this.logger, \"emit MatrixRTCSessionEvent.MembershipsChanged\", () => {\n this.emit(MatrixRTCSessionEvent.MembershipsChanged, oldMemberships, this.memberships);\n });\n\n void this.membershipManager?.onRTCSessionMemberUpdate(this.memberships);\n // The `ownMembership` will be set when calling `onRTCSessionMemberUpdate`.\n const ownMembership = this.membershipManager?.ownMembership;\n if (this.pendingNotificationToSend && ownMembership && oldMemberships.length === 0) {\n // If we're the first member in the call, we're responsible for\n // sending the notification event\n if (ownMembership.eventId && this.joinConfig?.notificationType) {\n this.sendCallNotify(\n ownMembership.eventId,\n this.joinConfig.notificationType,\n ownMembership.callIntent,\n );\n } else {\n this.logger.warn(\"Own membership eventId is undefined, cannot send call notification\");\n }\n }\n // If anyone else joins the session it is no longer our responsibility to send the notification.\n // (If we were the joiner we already did sent the notification in the block above.)\n if (this.memberships.length > 0) this.pendingNotificationToSend = undefined;\n } else {\n this.logger.debug(`No membership changes detected for room ${this.roomSubset.roomId}`);\n }\n // This also needs to be done if `changed` = false\n // A member might have updated their fingerprint (created_ts)\n this.encryptionManager?.onMembershipsUpdate(oldMemberships);\n if (this.isKeyRotationSuppressed !== wasKeyRotationSuppressed) {\n this.logger.info(\n `Key rotation is now ${this.isKeyRotationSuppressed ? \"suppressed\" : \"active again\"} (${this.memberships.length} members)`,\n );\n this.emit(MatrixRTCSessionEvent.KeyRotationSuppressedChanged, this.isKeyRotationSuppressed);\n }\n\n this.setExpiryTimer();\n };\n}\n\n/// Private helpers\nasync function computeBackendIdentityAndVerifyMemberEvents(\n room: Pick<Room, \"hasMembershipState\">,\n callMemberEvents: MatrixEvent[],\n slotDescription: SlotDescription,\n logger: Logger,\n): Promise<CallMembership[]> {\n const callMemberships: CallMembership[] = [];\n\n for (const memberEvent of callMemberEvents) {\n const content = memberEvent.getContent();\n\n // Quick filter to avoid unneeded processing of invalid events or left events.\n if (!quickFilterNonRelevantContents(content, logger)) {\n continue;\n }\n\n try {\n const membership = await CallMembership.parseFromEvent(memberEvent);\n\n if (isValidMembership(membership, room, slotDescription, logger)) {\n callMemberships.push(membership);\n }\n } catch (e) {\n logger.warn(\"Couldn't construct call membership: \", e);\n }\n }\n\n return callMemberships;\n}\n\nfunction quickFilterNonRelevantContents(content: IContent, logger: Logger): boolean {\n // Ignore sticky keys for the count\n const eventKeysCount = Object.keys(content).filter((k) => k !== \"msc4354_sticky_key\").length;\n // Don't even bother about empty events (saves us from costly type/\"key in\" checks in bigger rooms)\n if (eventKeysCount === 0) return false;\n\n // We first decide if it's a MSC4143 event (per device state key)\n if (eventKeysCount > 1 && \"application\" in content) {\n // We have a MSC4143 event membership event with a proper joined content\n return true;\n } else if (eventKeysCount === 1 && \"memberships\" in content) {\n // Events used to have this format in the past, but are now deprecated.\n // Given that state events ~cannot be deleted, there can be some remaining events in the room, just ignore them.\n return false;\n } else {\n // Invalid or left content\n return false;\n }\n}\n\nfunction isValidMembership(\n membership: CallMembership,\n room: Pick<Room, \"hasMembershipState\">,\n slotDescription: SlotDescription,\n logger: Logger,\n): boolean {\n if (membership.slotDescription.id !== slotDescription.id) {\n logger.info(\n `Ignoring membership of user ${membership.userId} for a different slot. Theirs: ${JSON.stringify(membership.slotDescription)}, Expected: ${JSON.stringify(slotDescription)}`,\n );\n return false;\n }\n\n if (membership.isExpired()) {\n logger.info(`Ignoring expired device membership ${membership.userId}/${membership.deviceId}`);\n return false;\n }\n\n if (!room.hasMembershipState(membership.userId ?? \"\", KnownMembership.Join)) {\n logger.info(`Ignoring membership of user ${membership.userId} who is not in the room.`);\n return false;\n }\n\n return true;\n}\n\n/**\n * Reads the slot state event's content for the given slot description.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for the given description.\n */\nfunction getSlotEventContent(\n room: Pick<Room, \"getLiveTimeline\">,\n slotDescription: SlotDescription,\n): RtcSlotEventContent | undefined {\n const slotId = computeSlotId(slotDescription);\n const slotEvent = room\n .getLiveTimeline()\n .getState(EventTimeline.FORWARDS)\n ?.getStateEvents(EventType.RTCSlot, slotId);\n if (!slotEvent) return undefined;\n\n return slotEvent.getContent<RtcSlotEventContent>();\n}\n\n/**\n * Whether the given slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\nfunction isSlotClosed(room: Pick<Room, \"getLiveTimeline\">, slotDescription: SlotDescription): boolean | undefined {\n const content = getSlotEventContent(room, slotDescription) as Partial<RtcSlotEventContent> | undefined;\n if (content === undefined) return undefined;\n\n return (\n content.status !== \"open\" ||\n typeof content.application !== \"object\" ||\n content.application?.type !== slotDescription.application\n );\n}\n\n/**\n * Collects the raw member events from room state and sticky store.\n */\nfunction collectMembersEvents(\n room: Pick<Room, \"getLiveTimeline\" | \"roomId\" | \"_unstable_getStickyEvents\">,\n slotDescription: SlotDescription,\n options: SessionMembershipsForSlotOpts,\n logger: Logger,\n): MatrixEvent[] {\n const { listenForStickyEvents, listenForMemberStateEvents } = options;\n let callMemberEvents: MatrixEvent[] = [];\n if (listenForStickyEvents && !isSlotClosed(room, slotDescription)) {\n // prefill with sticky events\n callMemberEvents = [...room._unstable_getStickyEvents()].filter((e) => e.getType() === EventType.RTCMembership);\n }\n if (listenForMemberStateEvents) {\n const roomState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);\n if (!roomState) {\n logger.warn(\"Couldn't get state for room \" + room.roomId + \"using empty membership array\");\n return [];\n }\n const callMemberStateEvents = roomState.getStateEvents(EventType.GroupCallMemberPrefix);\n callMemberEvents = callMemberEvents.concat(\n callMemberStateEvents.filter(\n (callMemberStateEvent) =>\n !callMemberEvents.some(\n // only care about state events which have keys which we have not yet seen in the sticky events.\n // TODO: I believe this can discard a joined state event if there is a matching left sticky event.\n (stickyEvent) =>\n stickyEvent.getContent().msc4354_sticky_key === callMemberStateEvent.getStateKey(),\n ),\n ),\n );\n }\n return callMemberEvents;\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AgB,CAAC,MAAM,CACtC,qBAAqB,CAAC,MAAM,CACvB,oBAAoB,IACjB,CAAC,gBAAgB,CAAC,IAAI;IAClB;IACA;IACC,WAAW,IACR,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,kBAAkB,KAAK,oBAAoB,CAAC,WAAW,CAAC,CACzF,CACR,CACJ,CAAC;EACL;EACA,OAAO,gBAAgB;AAC3B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MatrixRTCSession.js","names":[],"sources":["../../src/matrixrtc/MatrixRTCSession.ts"],"sourcesContent":["/*\nCopyright 2023 - 2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger, logger as rootLogger } from \"../logger.ts\";\nimport { TypedEventEmitter } from \"../models/typed-event-emitter.ts\";\nimport { EventTimeline } from \"../models/event-timeline.ts\";\nimport { type Room } from \"../models/room.ts\";\nimport { type MatrixClient } from \"../client.ts\";\nimport { EventType, RelationType } from \"../@types/event.ts\";\nimport { KnownMembership } from \"../@types/membership.ts\";\nimport { type ISendEventResponse } from \"../@types/requests.ts\";\nimport { CallMembership } from \"./CallMembership.ts\";\nimport { RoomStateEvent } from \"../models/room-state.ts\";\nimport { MembershipManager, StickyEventMembershipManager } from \"./MembershipManager.ts\";\nimport { type CallMembershipIdentityParts, type IEncryptionManager } from \"./EncryptionManager.ts\";\nimport { deepCompare, logDurationSync } from \"../utils.ts\";\nimport type {\n Statistics,\n RTCNotificationType,\n Status,\n IRTCNotificationContent,\n RTCCallIntent,\n Transport,\n SlotDescription,\n RtcSlotEventContent,\n RtcSlotEncryptionContent,\n} from \"./types.ts\";\nimport { RTC_NOTIFICATION_MAX_SENDER_TS_AHEAD_MS } from \"./types.ts\";\nimport { isLeftMembershipContent } from \"./membershipData/index.ts\";\nimport { UnsupportedStickyEventsEndpointError } from \"../errors.ts\";\nimport {\n MembershipManagerEvent,\n type MembershipManagerEventHandlerMap,\n type IMembershipManager,\n} from \"./IMembershipManager.ts\";\nimport { RTCEncryptionManager } from \"./RTCEncryptionManager.ts\";\nimport { ToDeviceKeyTransport } from \"./ToDeviceKeyTransport.ts\";\nimport { TypedReEmitter } from \"../ReEmitter.ts\";\nimport { type IContent, type MatrixEvent } from \"../models/event.ts\";\nimport { RoomStickyEventsEvent, type RoomStickyEventsMap } from \"../models/room-sticky-events.ts\";\nimport { computeSlotId, getSlotEventContent, isSlotClosed, isSlotOpen } from \"./utils.ts\";\n\n/**\n * Events emitted by MatrixRTCSession\n */\nexport enum MatrixRTCSessionEvent {\n // A member joined, left, or updated a property of their membership.\n MembershipsChanged = \"memberships_changed\",\n // We joined or left the session: our own local idea of whether we are joined,\n // separate from MembershipsChanged, ie. independent of whether our member event\n // has successfully gone through.\n JoinStateChanged = \"join_state_changed\",\n // The key used to encrypt media has changed\n EncryptionKeyChanged = \"encryption_key_changed\",\n /** The membership manager had to shut down caused by an unrecoverable error */\n MembershipManagerError = \"membership_manager_error\",\n /** The RTCSession did send a call notification caused by joining the call as the first member */\n DidSendCallNotification = \"did_send_call_notification\",\n /** Whether the session is too large for the media key to be rotated has changed */\n KeyRotationSuppressedChanged = \"key_rotation_suppressed_changed\",\n}\n\nexport type MatrixRTCSessionEventHandlerMap = {\n [MatrixRTCSessionEvent.MembershipsChanged]: (\n oldMemberships: CallMembership[],\n newMemberships: CallMembership[],\n ) => void;\n [MatrixRTCSessionEvent.JoinStateChanged]: (isJoined: boolean) => void;\n [MatrixRTCSessionEvent.EncryptionKeyChanged]: (\n key: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => void;\n [MatrixRTCSessionEvent.MembershipManagerError]: (error: unknown) => void;\n [MatrixRTCSessionEvent.DidSendCallNotification]: (\n notificationContentNew: { event_id: string } & IRTCNotificationContent,\n ) => void;\n [MatrixRTCSessionEvent.KeyRotationSuppressedChanged]: (isKeyRotationSuppressed: boolean) => void;\n};\n\nexport interface SessionConfig {\n /**\n * What kind of notification to send when starting the session.\n * @default `undefined` (no notification)\n */\n notificationType?: RTCNotificationType;\n\n /**\n * Determines the kind of call this will be.\n */\n callIntent?: RTCCallIntent;\n\n /**\n * Application-specific data to publish in our membership alongside the\n * application `type` and `m.call.intent`: in the `application` object of\n * an `m.rtc.member` event, or at the top level of a legacy `m.call.member`\n * one. Keys should be namespaced. Read back through\n * {@link CallMembership.applicationData}.\n */\n applicationData?: Record<string, unknown>;\n\n /**\n * How long (in milliseconds) the callee's client should keep ringing/waiting for an\n * answer before the sender gives up and the call notification is considered timed out.\n */\n notificationLifetimeMs?: number;\n}\n\n// The names follow these principles:\n// - we use the technical term delay if the option is related to delayed events.\n// - we use delayedLeaveEvent if the option is related to the delayed leave event.\n// - we use membershipEvent if the option is related to the rtc member state event.\n// - we use the technical term expiry if the option is related to the expiry field of the membership state event.\n// - we use a `Ms` postfix if the option is a duration to avoid using words like:\n// `time`, `duration`, `delay`, `timeout`... that might be mistaken/confused with technical terms.\nexport interface MembershipConfig {\n /**\n * The timeout (in milliseconds) after we joined the call, that our membership should expire\n * unless we have explicitly updated it.\n *\n * This is what goes into the m.rtc.member event expiry field and is typically set to a number of hours.\n */\n membershipEventExpiryMs?: number;\n\n /**\n * The time in (in milliseconds) which the manager will prematurely send the updated state event before the membership `expires` time to make sure it\n * sends the updated state event early enough.\n *\n * A headroom of 1000ms and a `membershipExpiryTimeout` of 10000ms would result in the first membership event update after 9s and\n * a membership event that would be considered expired after 10s.\n *\n * This value does not have an effect on the value of `SessionMembershipData.expires`.\n */\n membershipEventExpiryHeadroomMs?: number;\n\n /**\n * The timeout (in milliseconds) with which the deleayed leave event on the server is configured.\n * After this time the server will set the event to the disconnected stat if it has not received a keep-alive from the client.\n */\n delayedLeaveEventDelayMs?: number;\n\n /**\n * The interval (in milliseconds) in which the client will send membership keep-alives to the server.\n */\n delayedLeaveEventRestartMs?: number;\n\n /**\n * The maximum number of retries that the manager will do for delayed event sending/updating and state event sending when a server rate limit has been hit.\n */\n maximumRateLimitRetryCount?: number;\n\n /**\n * The maximum number of retries that the manager will do for delayed event sending/updating and state event sending when a network error occurs.\n */\n maximumNetworkErrorRetryCount?: number;\n\n /**\n * The time (in milliseconds) after which we will retry a http request if it\n * failed to send due to a network error. (send membership event, send delayed event, restart delayed event...)\n */\n networkErrorRetryMs?: number;\n\n /**\n * The time (in milliseconds) after which a we consider a delayed event restart http request to have failed.\n * Setting this to a lower value will result in more frequent retries but also a higher chance of failiour.\n *\n * In the presence of network packet loss (hurting TCP connections), the custom delayedEventRestartLocalTimeoutMs\n * helps by keeping more delayed event reset candidates in flight,\n * improving the chances of a successful reset. (its is equivalent to the js-sdk `localTimeout` configuration,\n * but only applies to calls to the `_unstable_restartScheduledDelayedEvent` endpoint\n * or the `_unstable_updateDelayedEvent` endpoint with a body of `{action:\"restart\"}`.)\n */\n delayedLeaveEventRestartLocalTimeoutMs?: number;\n\n /**\n * Send membership using sticky events rather than state events.\n * This also make the client use the new m.rtc.member MSC4354 event format. (instead of m.call.member)\n *\n * **WARNING**: This is an unstable feature and not all clients will support it.\n */\n unstableSendStickyEvents?: boolean;\n}\n\nexport interface EncryptionConfig {\n /**\n * If true, generate and share a media key for this participant,\n * and emit MatrixRTCSessionEvent.EncryptionKeyChanged when\n * media keys for other participants become available.\n */\n manageMediaKeys?: boolean;\n /**\n * The minimum time (in milliseconds) between each attempt to send encryption key(s).\n * e.g. if this is set to 1000, then we will send at most one key event every second.\n * @deprecated - Not used by the new encryption manager.\n */\n updateEncryptionKeyThrottle?: number;\n\n /**\n * Sometimes it is necessary to rotate the encryption key after a membership update.\n * For performance reasons we might not want to rotate the key immediately but allow future memberships to use the same key.\n * If 5 people join in a row in less than 5 seconds, we don't want to rotate the key for each of them.\n * If 5 people leave in a row in less than 5 seconds, we don't want to rotate the key for each of them.\n * So we do share the key which was already used live for <5s to new joiners.\n * This does result in a potential leak up to the configured time of call media.\n * This has to be considered when choosing a value for this property.\n */\n keyRotationGracePeriodMs?: number;\n\n /**\n * The number of participants in the session at which the media key will no longer be rotated.\n *\n * Rotating a key requires sending it to every participant device, so in large sessions the cost of rotating\n * on every join/leave becomes prohibitive. At this limit the current key is kept and\n * distributed to new joiners. No new keys are generated for joiners/leavers.\n *\n * Defaults to undefined.\n */\n keyRotationParticipantLimit?: number;\n\n /**\n * The delay (in milliseconds) after a member leaves before we create and publish a new key, because people\n * tend to leave calls at the same time.\n * @deprecated - Not used by the new encryption manager.\n */\n makeKeyDelay?: number;\n /**\n * The delay (in milliseconds) between sending a new key and starting to encrypt with it. This\n * gives others a chance to receive the new key to minimize the chance they get media they can't decrypt.\n *\n * The higher this value is, the better it is for existing members as they will have a smoother experience.\n * But it impacts new joiners: They will always have to wait `useKeyDelay` before being able to decrypt the media\n * (as it will be encrypted with the new key after the delay only), even if the key has already arrived before the delay.\n */\n useKeyDelay?: number;\n}\nexport type JoinSessionConfig = SessionConfig & MembershipConfig & EncryptionConfig;\n\ninterface SessionMembershipsForSlotOpts {\n /**\n * Listen for incoming sticky member events. If disabled, this session will\n * ignore any incoming sticky events.\n */\n listenForStickyEvents: boolean;\n /**\n * Listen for incoming member state events (legacy). If disabled, this session will\n * ignore any incoming state events.\n */\n listenForMemberStateEvents: boolean;\n}\n\nconst DEFAULT_SESSION_MEMBERSHIPS_FOR_SLOT_OPTS: SessionMembershipsForSlotOpts = {\n listenForStickyEvents: true,\n listenForMemberStateEvents: true,\n};\n\n/**\n * A MatrixRTCSession manages the membership & properties of a MatrixRTC session.\n * This class doesn't deal with media at all, just membership & properties of a session.\n */\nexport class MatrixRTCSession extends TypedEventEmitter<\n MatrixRTCSessionEvent | MembershipManagerEvent,\n MatrixRTCSessionEventHandlerMap & MembershipManagerEventHandlerMap\n> {\n private membershipManager?: IMembershipManager;\n private encryptionManager?: IEncryptionManager;\n private joinConfig?: SessionConfig;\n private logger: Logger;\n\n private pendingNotificationToSend: undefined | RTCNotificationType;\n /**\n * This timeout is responsible to track any expiration. We need to know when we have to start\n * to ignore other call members. There is no callback for this. This timeout will always be configured to\n * emit when the next membership expires.\n */\n private expiryTimeout?: ReturnType<typeof setTimeout>;\n\n public memberships: CallMembership[] = [];\n\n /**\n * Resolves when the session has calculated the initial membership of the session.\n */\n public readonly initialMembershipCalculated: Promise<void>;\n /**\n * Does membership need to be recalculated? This is set to false upon\n * recalculation.\n */\n private membershipNeedsRecalculation = false;\n\n /**\n * The statistics for this session.\n */\n public statistics: Statistics = {\n counters: {\n roomEventEncryptionKeysSent: 0,\n roomEventEncryptionKeysReceived: 0,\n },\n totals: {\n roomEventEncryptionKeysReceivedTotalAge: 0,\n },\n };\n\n public get membershipStatus(): Status | undefined {\n return this.membershipManager?.status;\n }\n public get probablyLeft(): boolean | undefined {\n return this.membershipManager?.probablyLeft;\n }\n public get delayId(): string | undefined {\n return this.membershipManager?.delayId;\n }\n\n /**\n * Whether the key rotation is currently halted.\n * mirror of: EncryptionConfig.keyRotationParticipantLimit\n */\n public get isKeyRotationSuppressed(): boolean {\n return this.encryptionManager?.isKeyRotationSuppressed ?? false;\n }\n\n /**\n * The callId (sessionId) of the call.\n *\n * It can be undefined since the callId is only known once the first membership joins.\n * The callId is the property that, per definition, groups memberships into one call.\n * @deprecated use `slotId` instead.\n */\n public get callId(): string | undefined {\n return this.slotDescription?.id;\n }\n /**\n * The slotId of the call.\n * `{application}#{appSpecificId}`\n * It can be undefined since the slotId is only known once the first membership joins.\n * The slotId is the property that, per definition, groups memberships into one call.\n */\n public get slotId(): string | undefined {\n return computeSlotId(this.slotDescription);\n }\n\n /**\n * Reads the current slot state event's content for this session.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for this session.\n */\n public getRtcSlot(): RtcSlotEventContent | undefined {\n return getSlotEventContent(this.roomSubset, this.slotDescription);\n }\n\n /**\n * Whether this session's slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\n public isSlotClosed(): boolean | undefined {\n return isSlotClosed(this.roomSubset, this.slotDescription);\n }\n\n /**\n * Whether this session's slot is open.\n *\n * @returns `true` if the slot is open, `false` if the slot is closed or `undefined`\n * if no slot exists.\n */\n public isSlotOpen(): boolean | undefined {\n return isSlotOpen(this.roomSubset, this.slotDescription);\n }\n\n /**\n * Ensures this session's slot is open, sending a slot state event to open (or create) it if needed.\n *\n * The event's `application` is set from this session's slot description and its `encryption` from\n * `opts.encryption`, replacing whatever an existing slot event declares. Other content is preserved.\n * No-op if the slot is already open with matching `application` and `encryption`.\n *\n * @param opts.encryption - The encryption to declare on the slot, or `undefined` for none.\n * @throws if sending the state event fails.\n */\n public async ensureRtcSlotOpen(opts: { encryption?: RtcSlotEncryptionContent } = {}): Promise<void> {\n const application = { type: this.slotDescription.application };\n const existingContent = this.getRtcSlot();\n if (\n existingContent?.status === \"open\" &&\n deepCompare(existingContent.application, application) &&\n deepCompare(existingContent.encryption, opts.encryption)\n ) {\n return;\n }\n await this.sendRtcSlot({\n ...existingContent,\n status: \"open\",\n application,\n encryption: opts.encryption,\n });\n }\n\n /**\n * Ensures this session's slot is closed, sending a slot state event to close it if needed.\n * The other content of the existing slot event is preserved. No-op if no slot event exists.\n *\n * @throws if sending the state event fails.\n */\n public async ensureRtcSlotClosed(): Promise<void> {\n const existingContent = this.getRtcSlot();\n if (!existingContent || existingContent.status === \"closed\") return;\n await this.sendRtcSlot({ ...existingContent, status: \"closed\" });\n }\n\n private async sendRtcSlot(content: RtcSlotEventContent): Promise<void> {\n await this.client.sendStateEvent(\n this.roomSubset.roomId,\n EventType.RTCSlot,\n content,\n computeSlotId(this.slotDescription),\n );\n }\n\n /**\n * Returns all the call memberships for a room that match the provided `sessionDescription`,\n * oldest first.\n *\n * By default, this will return *both* sticky and member state events.\n */\n public static async sessionMembershipsForSlot(\n room: Pick<Room, \"getLiveTimeline\" | \"roomId\" | \"hasMembershipState\" | \"_unstable_getStickyEvents\">,\n slotDescription: SlotDescription,\n // default both true this implied we combine sticky and state events for the final call state\n // (prefer sticky events in case of a duplicate)\n options: SessionMembershipsForSlotOpts = DEFAULT_SESSION_MEMBERSHIPS_FOR_SLOT_OPTS,\n ): Promise<CallMembership[]> {\n const logger = rootLogger.getChild(\n `[MatrixRTCSession ${room.roomId} ${slotDescription.application}#${slotDescription.id}]`,\n );\n const callMemberEvents = collectMembersEvents(room, slotDescription, options, logger);\n\n const callMemberships = await computeBackendIdentityAndVerifyMemberEvents(\n room,\n callMemberEvents,\n slotDescription,\n logger,\n );\n\n callMemberships.sort((a, b) => a.createdTs() - b.createdTs());\n if (callMemberships.length > 1) {\n logger.debug(\n `Call memberships in room ${room.roomId}, in order: `,\n callMemberships.map((m) => [m.createdTs(), m.userId]),\n );\n }\n\n return callMemberships;\n }\n\n /**\n * Return the MatrixRTC session for the room.\n * This returned session can be used to find out if there are active sessions\n * for the requested room and `slotDescription`.\n */\n public static sessionForSlot(\n client: MatrixClient,\n room: Room,\n slotDescription: SlotDescription,\n opts?: SessionMembershipsForSlotOpts,\n ): MatrixRTCSession {\n return new MatrixRTCSession(client, room, slotDescription, opts);\n }\n\n /**\n * WARN: this can in theory only be a subset of the room with the properties required by\n * this class.\n * Outside of tests this most likely will be a full room, however.\n * @deprecated Relying on a full Room object being available here is an anti-pattern. You should be tracking\n * the room object in your own code and passing it in when needed.\n */\n public get room(): Room {\n return this.roomSubset as Room;\n }\n\n /**\n * This constructs a room session. When using MatrixRTC inside the js-sdk this is expected\n * to be used with the MatrixRTCSessionManager exclusively.\n *\n * In cases where you don't use the js-sdk but build on top of another Matrix stack this class can be used standalone\n * to manage a joined MatrixRTC session.\n *\n * @param client A subset of the {@link MatrixClient} that lets the session interact with the Matrix room.\n * @param roomSubset The room this session is attached to. A subset of a js-sdk Room that the session needs.\n * @param slotDescription The slot description is a virtual address where participants are allowed to meet.\n * This session will only manage memberships that match this slot description.Sessions are distinct if any of\n * those properties are distinct: `roomSubset.roomId`, `slotDescription.application`, `slotDescription.id`.\n * @param calculateMembershipsOpts - Options to configure how memberships are calculated for this session.\n */\n public constructor(\n private readonly client: Pick<\n MatrixClient,\n | \"getUserId\"\n | \"getDeviceId\"\n | \"sendEvent\"\n | \"sendStateEvent\"\n | \"_unstable_sendDelayedStateEvent\"\n | \"_unstable_updateDelayedEvent\"\n | \"_unstable_cancelScheduledDelayedEvent\"\n | \"_unstable_restartScheduledDelayedEvent\"\n | \"_unstable_sendScheduledDelayedEvent\"\n | \"_unstable_sendStickyEvent\"\n | \"_unstable_sendStickyDelayedEvent\"\n | \"cancelPendingEvent\"\n | \"encryptAndSendToDevice\"\n | \"off\"\n | \"on\"\n | \"decryptEventIfNeeded\"\n >,\n private roomSubset: Pick<\n Room,\n | \"getLiveTimeline\"\n | \"roomId\"\n | \"getVersion\"\n | \"hasMembershipState\"\n | \"on\"\n | \"off\"\n | \"_unstable_getStickyEvents\"\n >,\n\n public readonly slotDescription: SlotDescription,\n private readonly calculateMembershipsOpts?: SessionMembershipsForSlotOpts,\n ) {\n super();\n this.logger = rootLogger.getChild(\n `[MatrixRTCSession ${roomSubset.roomId} ${slotDescription.application}#${slotDescription.id}]`,\n );\n\n this.roomSubset.on(RoomStateEvent.Members, this.onRoomMemberUpdate);\n this.roomSubset.on(RoomStateEvent.Events, this.onRoomStateEvent);\n this.roomSubset.on(RoomStickyEventsEvent.Update, this.onStickyEventUpdate);\n\n this.initialMembershipCalculated = this.ensureRecalculateSessionMembers();\n this.setExpiryTimer();\n }\n /*\n * Returns true if we intend to be participating in the MatrixRTC session.\n * This is determined by checking if the relativeExpiry has been set.\n */\n public isJoined(): boolean {\n return this.membershipManager?.isJoined() ?? false;\n }\n\n /**\n * Performs cleanup & removes timers for client shutdown\n */\n public async stop(): Promise<void> {\n await this.membershipManager?.leave(1000);\n if (this.expiryTimeout) {\n clearTimeout(this.expiryTimeout);\n this.expiryTimeout = undefined;\n }\n\n this.roomSubset.off(RoomStateEvent.Members, this.onRoomMemberUpdate);\n this.roomSubset.off(RoomStateEvent.Events, this.onRoomStateEvent);\n this.roomSubset.off(RoomStickyEventsEvent.Update, this.onStickyEventUpdate);\n }\n\n private reEmitter = new TypedReEmitter<\n MatrixRTCSessionEvent | MembershipManagerEvent,\n MatrixRTCSessionEventHandlerMap & MembershipManagerEventHandlerMap\n >(this);\n\n /**\n * Announces this user and device as joined to the MatrixRTC session,\n * and continues to update the membership event to keep it valid until\n * leaveRoomSession() is called\n * This will not subscribe to updates: remember to call subscribe() separately if\n * desired.\n * This method will return immediately and the session will be joined in the background.\n * @param ownMembershipIdentity the identity of the user and device joining the session.\n * This will be put into the content.member.\n * @param fociPreferred the list of preferred foci to use in the joined RTC membership event.\n * If multiSfuFocus is set, this is only needed if this client wants to publish to multiple transports simultaneously.\n * @param multiSfuFocus the active focus to use in the joined RTC membership event. Setting this implies the\n * membership manager will operate in a multi-SFU connection mode. If `undefined`, an `oldest_membership`\n * transport selection will be used instead.\n * @param joinConfig - Additional configuration for the joined session.\n */\n public joinRTCSession(\n ownMembershipIdentity: CallMembershipIdentityParts,\n fociPreferred: Transport[],\n multiSfuFocus?: Transport,\n joinConfig?: JoinSessionConfig,\n ): void {\n if (this.isJoined()) {\n this.logger.info(`Already joined to session in room ${this.roomSubset.roomId}: ignoring join call`);\n return;\n } else {\n // Create MembershipManager and pass the RTCSession logger (with room id info)\n this.membershipManager = joinConfig?.unstableSendStickyEvents\n ? new StickyEventMembershipManager(\n joinConfig,\n this.roomSubset,\n this.client,\n this.slotDescription,\n ownMembershipIdentity.memberId,\n this.logger,\n )\n : new MembershipManager(joinConfig, this.roomSubset, this.client, this.slotDescription, this.logger);\n\n this.reEmitter.reEmit(this.membershipManager, [\n MembershipManagerEvent.ProbablyLeft,\n MembershipManagerEvent.StatusChanged,\n MembershipManagerEvent.DelayIdChanged,\n ]);\n // Create Encryption manager\n const [room, client, statistics] = [this.roomSubset, this.client, this.statistics];\n const transport = new ToDeviceKeyTransport(ownMembershipIdentity, room.roomId, client, statistics);\n this.encryptionManager = new RTCEncryptionManager(\n ownMembershipIdentity,\n () => this.memberships,\n transport,\n (\n keyBin: Uint8Array<ArrayBuffer>,\n encryptionKeyIndex: number,\n membership: CallMembershipIdentityParts,\n rtcBackendIdentity: string,\n ) => {\n this.emit(\n MatrixRTCSessionEvent.EncryptionKeyChanged,\n keyBin,\n encryptionKeyIndex,\n membership,\n rtcBackendIdentity,\n );\n },\n this.logger,\n );\n }\n\n this.joinConfig = joinConfig;\n this.pendingNotificationToSend = this.joinConfig?.notificationType;\n\n // Join!\n this.membershipManager.join(fociPreferred, multiSfuFocus, (e) => {\n this.logger.error(\"MembershipManager encountered an unrecoverable error: \", e);\n this.emit(MatrixRTCSessionEvent.MembershipManagerError, e);\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, this.isJoined());\n });\n this.encryptionManager.join(joinConfig);\n\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, true);\n }\n\n /**\n *\n * @param fociPreferred\n * @param multiSfuFocus\n * @param joinConfig\n * @deprecated use the joinRTCSession method instead\n */\n public joinRoomSession(\n fociPreferred: Transport[],\n multiSfuFocus?: Transport,\n joinConfig?: JoinSessionConfig,\n ): void {\n const [userId, deviceId] = [this.client.getUserId()!, this.client.getDeviceId()!];\n // TODO this wants to become a UUID\n const memberId = `${userId}:${deviceId}`;\n this.joinRTCSession({ userId, deviceId, memberId }, fociPreferred, multiSfuFocus, joinConfig);\n }\n\n /**\n * Announces this user and device as having left the MatrixRTC session\n * and stops scheduled updates.\n * This will not unsubscribe from updates: remember to call unsubscribe() separately if\n * desired.\n * The membership update required to leave the session will retry if it fails.\n * Without network connection the promise will never resolve.\n * A timeout can be provided so that there is a guarantee for the promise to resolve.\n * @returns Whether the membership update was attempted and did not time out.\n */\n public async leaveRoomSession(timeout: number | undefined = undefined): Promise<boolean> {\n if (!this.isJoined()) {\n this.logger.info(`Not joined to session in room ${this.roomSubset.roomId}: ignoring leave call`);\n return false;\n }\n\n this.logger.info(`Leaving call session in room ${this.roomSubset.roomId}`);\n\n this.encryptionManager!.leave();\n\n const leavePromise = this.membershipManager!.leave(timeout);\n this.emit(MatrixRTCSessionEvent.JoinStateChanged, false);\n\n return await leavePromise;\n }\n /**\n * This returns the focus in use by the oldest membership.\n * Do not use since this might be just the focus for the oldest membership. others might use a different focus.\n * @deprecated use `member.getTransport(session.getOldestMembership())` instead for the specific member you want to get the focus for.\n */\n public getFocusInUse(): Transport | undefined {\n const oldestMembership = this.getOldestMembership();\n return oldestMembership?.getTransport(oldestMembership);\n }\n\n public getOldestMembership(): CallMembership | undefined {\n return this.memberships[0];\n }\n\n /**\n * Get the call intent for the current call, based on what members are advertising. If one or more\n * members disagree on the current call intent, or nobody specifies one then `undefined` is returned.\n *\n * If all members that specify a call intent agree, that value is returned.\n * @returns A call intent, or `undefined` if no consensus or not given.\n */\n public getConsensusCallIntent(): RTCCallIntent | undefined {\n const getFirstCallIntent = this.memberships.find((m) => !!m.callIntent)?.callIntent;\n if (!getFirstCallIntent) {\n return undefined;\n }\n if (this.memberships.every((m) => !m.callIntent || m.callIntent === getFirstCallIntent)) {\n return getFirstCallIntent;\n }\n return undefined;\n }\n\n public async updateCallIntent(callIntent: RTCCallIntent): Promise<void> {\n const myMembership = this.membershipManager?.ownMembership;\n if (!myMembership) {\n throw Error(\"Not connected yet\");\n }\n await this.membershipManager?.updateCallIntent(callIntent);\n }\n\n /**\n * Replace the application-specific data in our membership (see\n * {@link SessionConfig.applicationData}), re-sending it if it changed.\n */\n public async updateApplicationData(applicationData: Record<string, unknown>): Promise<void> {\n const myMembership = this.membershipManager?.ownMembership;\n if (!myMembership) {\n throw Error(\"Not connected yet\");\n }\n await this.membershipManager?.updateApplicationData(applicationData);\n }\n\n /**\n * Re-emit an EncryptionKeyChanged event for each tracked encryption key. This can be used to export\n * the keys.\n */\n public reemitEncryptionKeys(): void {\n this.encryptionManager?.getEncryptionKeys().forEach((keyRing, key) => {\n keyRing.forEach((keyInfo) => {\n this.emit(\n MatrixRTCSessionEvent.EncryptionKeyChanged,\n keyInfo.key,\n keyInfo.keyIndex,\n keyInfo.membership,\n keyInfo.rtcBackendIdentity,\n );\n });\n });\n }\n\n /**\n * Sets a timer for the soonest membership expiry\n */\n private setExpiryTimer(): void {\n if (this.expiryTimeout) {\n clearTimeout(this.expiryTimeout);\n this.expiryTimeout = undefined;\n }\n\n let soonestExpiry;\n for (const membership of this.memberships) {\n const thisExpiry = membership.getMsUntilExpiry();\n // If getMsUntilExpiry is undefined we have a MSC4143 (MatrixRTC) compliant event - it never expires\n // but will be reliably resent on disconnect.\n if (thisExpiry !== undefined && (soonestExpiry === undefined || thisExpiry < soonestExpiry)) {\n soonestExpiry = thisExpiry;\n }\n }\n\n if (soonestExpiry != undefined) {\n this.expiryTimeout = setTimeout(() => void this.ensureRecalculateSessionMembers(), soonestExpiry);\n }\n }\n\n /**\n * Sends notification events to indiciate the call has started.\n * Note: This does not return a promise, instead scheduling the notification events to be sent.\n * @param parentEventId Event id linking to your RTC call membership event.\n * @param notificationType The type of notification to send\n * @param callIntent The type of call this is (e.g. \"audio\").\n */\n private sendCallNotify(\n parentEventId: string,\n notificationType: RTCNotificationType,\n callIntent?: RTCCallIntent,\n ): void {\n const lifetime = this.joinConfig?.notificationLifetimeMs ?? 90_000;\n const slotId = computeSlotId(this.slotDescription);\n const sendNotificationEvent = async (): Promise<{\n response: ISendEventResponse;\n content: IRTCNotificationContent;\n }> => {\n const content: IRTCNotificationContent = {\n \"slot_id\": slotId,\n \"m.mentions\": { user_ids: [], room: true },\n \"notification_type\": notificationType,\n \"m.relates_to\": {\n event_id: parentEventId,\n rel_type: RelationType.Reference,\n },\n \"sender_ts\": Date.now(),\n \"lifetime\": lifetime,\n \"msc4354_sticky_key\": slotId,\n };\n if (callIntent) {\n content[\"m.call.intent\"] = callIntent;\n }\n return { response: await this.sendNotificationEvent(content), content };\n };\n\n void sendNotificationEvent()\n .then((notification) => {\n // Join event_id and origin event content\n const newResult = { ...notification.response, ...notification.content };\n this.emit(MatrixRTCSessionEvent.DidSendCallNotification, newResult);\n })\n .catch((error) => this.logger.error(\"Failed to send call notification\", error));\n }\n\n /**\n * Sends a notification event, as a sticky event (MSC4354) where the server supports it.\n */\n private async sendNotificationEvent(content: IRTCNotificationContent): Promise<ISendEventResponse> {\n const roomId = this.roomSubset.roomId;\n try {\n // Stay sticky slightly longer than the lifetime, since the server measures the sticky duration\n // from `origin_server_ts` while receivers measure the lifetime from `sender_ts`.\n const stickyDurationMs = content.lifetime + RTC_NOTIFICATION_MAX_SENDER_TS_AHEAD_MS;\n return await this.client._unstable_sendStickyEvent(\n roomId,\n stickyDurationMs,\n null,\n EventType.RTCNotification,\n content,\n );\n } catch (error) {\n if (!(error instanceof UnsupportedStickyEventsEndpointError)) throw error;\n this.logger.debug(\"Server does not support sticky events, sending notification as a regular event\");\n return await this.client.sendEvent(roomId, EventType.RTCNotification, content);\n }\n }\n\n /**\n * Call this when the Matrix room members have changed.\n */\n private readonly onRoomMemberUpdate = (): void => {\n void this.ensureRecalculateSessionMembers();\n };\n\n /**\n * Call this when a room state event has been updated.\n */\n private readonly onRoomStateEvent = (event: MatrixEvent): void => {\n if (event.getType() !== EventType.RTCSlot) return;\n if (event.getStateKey() !== computeSlotId(this.slotDescription)) return;\n void this.ensureRecalculateSessionMembers();\n };\n\n /**\n * Call this when a sticky event update has occured.\n */\n private readonly onStickyEventUpdate: RoomStickyEventsMap[RoomStickyEventsEvent.Update] = (\n added,\n updated,\n removed,\n ): void => {\n if (\n [...added, ...removed, ...updated.flatMap((v) => [v.current, v.previous])].some(\n (e) => e.getType() === EventType.RTCMembership,\n )\n ) {\n void this.ensureRecalculateSessionMembers();\n }\n };\n\n /**\n * Call this when something changed that may impacts the current MatrixRTC members in this session.\n *\n * @deprecated use {@link ensureRecalculateSessionMembers} instead.\n */\n public _onRTCSessionMemberUpdate = async (): Promise<void> => {\n await this.ensureRecalculateSessionMembers();\n };\n\n // Recalculations are chained onto this promise, so they never run in parallel.\n private recalculateSessionMembersPromise: Promise<void> = Promise.resolve();\n\n /**\n * Ensures that membership is recalculated when the state of the session may have changed.\n * Also ensures that only one recalculation is made at a time.\n * @returns A promise resolving when the state has been recalculated.\n */\n public ensureRecalculateSessionMembers(): Promise<void> {\n if (this.membershipNeedsRecalculation) {\n // We have already requested recalcuation, don't attempt a new one.\n return this.recalculateSessionMembersPromise;\n }\n this.membershipNeedsRecalculation = true;\n // Chain the recalculation.\n this.recalculateSessionMembersPromise = this.recalculateSessionMembersPromise.then(\n () => this.recalculateSessionMembers(),\n () => this.recalculateSessionMembers(),\n );\n return this.recalculateSessionMembersPromise;\n }\n\n /**\n * Call this when anything that could impact rtc memberships has changed: Room Members or RTC members.\n *\n * Examines the latest call memberships and handles any encryption key sending or rotation that is needed.\n *\n * This function should be called when the room members or call memberships might have changed.\n */\n private readonly recalculateSessionMembers = async (): Promise<void> => {\n // Clear the flag.\n this.membershipNeedsRecalculation = false;\n const oldMemberships = this.memberships;\n // Needs to be computed before `this.memberships` is updated below, since it is derived from it.\n const wasKeyRotationSuppressed = this.isKeyRotationSuppressed;\n\n this.memberships = await MatrixRTCSession.sessionMembershipsForSlot(\n this.room,\n this.slotDescription,\n this.calculateMembershipsOpts,\n );\n\n const changed =\n oldMemberships.length != this.memberships.length ||\n oldMemberships.some((m, i) => !CallMembership.equal(m, this.memberships[i]));\n\n if (changed) {\n this.logger.info(\n `Memberships for call in room ${this.roomSubset.roomId} have changed: emitting (${this.memberships.length} members)`,\n );\n logDurationSync(this.logger, \"emit MatrixRTCSessionEvent.MembershipsChanged\", () => {\n this.emit(MatrixRTCSessionEvent.MembershipsChanged, oldMemberships, this.memberships);\n });\n\n void this.membershipManager?.onRTCSessionMemberUpdate(this.memberships);\n // The `ownMembership` will be set when calling `onRTCSessionMemberUpdate`.\n const ownMembership = this.membershipManager?.ownMembership;\n if (this.pendingNotificationToSend && ownMembership && oldMemberships.length === 0) {\n // If we're the first member in the call, we're responsible for\n // sending the notification event\n if (ownMembership.eventId && this.joinConfig?.notificationType) {\n this.sendCallNotify(\n ownMembership.eventId,\n this.joinConfig.notificationType,\n ownMembership.callIntent,\n );\n } else {\n this.logger.warn(\"Own membership eventId is undefined, cannot send call notification\");\n }\n }\n // If anyone else joins the session it is no longer our responsibility to send the notification.\n // (If we were the joiner we already did sent the notification in the block above.)\n if (this.memberships.length > 0) this.pendingNotificationToSend = undefined;\n } else {\n this.logger.debug(`No membership changes detected for room ${this.roomSubset.roomId}`);\n }\n // This also needs to be done if `changed` = false\n // A member might have updated their fingerprint (created_ts)\n this.encryptionManager?.onMembershipsUpdate(oldMemberships);\n if (this.isKeyRotationSuppressed !== wasKeyRotationSuppressed) {\n this.logger.info(\n `Key rotation is now ${this.isKeyRotationSuppressed ? \"suppressed\" : \"active again\"} (${this.memberships.length} members)`,\n );\n this.emit(MatrixRTCSessionEvent.KeyRotationSuppressedChanged, this.isKeyRotationSuppressed);\n }\n\n this.setExpiryTimer();\n };\n}\n\n/// Private helpers\nasync function computeBackendIdentityAndVerifyMemberEvents(\n room: Pick<Room, \"hasMembershipState\">,\n callMemberEvents: MatrixEvent[],\n slotDescription: SlotDescription,\n logger: Logger,\n): Promise<CallMembership[]> {\n const callMemberships: CallMembership[] = [];\n\n for (const memberEvent of callMemberEvents) {\n const content = memberEvent.getContent();\n\n // Quick filter to avoid unneeded processing of invalid events or left events.\n if (!quickFilterNonRelevantContents(content)) {\n continue;\n }\n\n try {\n const membership = await CallMembership.parseFromEvent(memberEvent);\n\n if (isValidMembership(membership, room, slotDescription, logger)) {\n callMemberships.push(membership);\n }\n } catch (e) {\n logger.warn(\"Couldn't construct call membership: \", e);\n }\n }\n\n return callMemberships;\n}\n\nfunction quickFilterNonRelevantContents(content: IContent): boolean {\n // Don't even bother about left memberships (saves us from costly type/\"key in\" checks in bigger rooms)\n if (isLeftMembershipContent(content)) return false;\n\n // Ignore sticky keys for the count\n const eventKeysCount = Object.keys(content).filter((k) => k !== \"msc4354_sticky_key\").length;\n\n // We first decide if it's a MSC4143 event (per device state key)\n if (eventKeysCount > 1 && \"application\" in content) {\n // We have a MSC4143 event membership event with a proper joined content\n return true;\n } else if (eventKeysCount === 1 && \"memberships\" in content) {\n // Events used to have this format in the past, but are now deprecated.\n // Given that state events ~cannot be deleted, there can be some remaining events in the room, just ignore them.\n return false;\n } else {\n // Invalid or left content\n return false;\n }\n}\n\nfunction isValidMembership(\n membership: CallMembership,\n room: Pick<Room, \"hasMembershipState\">,\n slotDescription: SlotDescription,\n logger: Logger,\n): boolean {\n if (membership.slotDescription.id !== slotDescription.id) {\n logger.info(\n `Ignoring membership of user ${membership.userId} for a different slot. Theirs: ${JSON.stringify(membership.slotDescription)}, Expected: ${JSON.stringify(slotDescription)}`,\n );\n return false;\n }\n\n if (membership.isExpired()) {\n logger.info(`Ignoring expired device membership ${membership.userId}/${membership.deviceId}`);\n return false;\n }\n\n if (!room.hasMembershipState(membership.userId ?? \"\", KnownMembership.Join)) {\n logger.info(`Ignoring membership of user ${membership.userId} who is not in the room.`);\n return false;\n }\n\n return true;\n}\n\n/**\n * Collects the raw member events from room state and sticky store.\n */\nfunction collectMembersEvents(\n room: Pick<Room, \"getLiveTimeline\" | \"roomId\" | \"_unstable_getStickyEvents\">,\n slotDescription: SlotDescription,\n options: SessionMembershipsForSlotOpts,\n logger: Logger,\n): MatrixEvent[] {\n const { listenForStickyEvents, listenForMemberStateEvents } = options;\n let callMemberEvents: MatrixEvent[] = [];\n if (listenForStickyEvents && !isSlotClosed(room, slotDescription)) {\n // prefill with sticky events\n callMemberEvents = [...room._unstable_getStickyEvents()].filter((e) => e.getType() === EventType.RTCMembership);\n }\n if (listenForMemberStateEvents) {\n const roomState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);\n if (!roomState) {\n logger.warn(\"Couldn't get state for room \" + room.roomId + \"using empty membership array\");\n return [];\n }\n const callMemberStateEvents = roomState.getStateEvents(EventType.GroupCallMemberPrefix);\n callMemberEvents = callMemberEvents.concat(\n callMemberStateEvents.filter(\n (callMemberStateEvent) =>\n !callMemberEvents.some(\n // only care about state events which have keys which we have not yet seen in the sticky events.\n // TODO: I believe this can discard a joined state event if there is a matching left sticky event.\n (stickyEvent) =>\n stickyEvent.getContent().msc4354_sticky_key === callMemberStateEvent.getStateKey(),\n ),\n ),\n );\n }\n return callMemberEvents;\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAsB,MAAM,IAAI,UAAU,QAAQ,cAAc;AAChE,SAAS,iBAAiB,QAAQ,kCAAkC;AACpE,SAAS,aAAa,QAAQ,6BAA6B;AAG3D,SAAS,SAAS,EAAE,YAAY,QAAQ,oBAAoB;AAC5D,SAAS,eAAe,QAAQ,yBAAyB;AAEzD,SAAS,cAAc,QAAQ,qBAAqB;AACpD,SAAS,cAAc,QAAQ,yBAAyB;AACxD,SAAS,iBAAiB,EAAE,4BAA4B,QAAQ,wBAAwB;AAExF,SAAS,WAAW,EAAE,eAAe,QAAQ,aAAa;AAY1D,SAAS,uCAAuC,QAAQ,YAAY;AACpE,SAAS,uBAAuB,QAAQ,2BAA2B;AACnE,SAAS,oCAAoC,QAAQ,cAAc;AACnE,SACI,sBAAsB,QAGnB,yBAAyB;AAChC,SAAS,oBAAoB,QAAQ,2BAA2B;AAChE,SAAS,oBAAoB,QAAQ,2BAA2B;AAChE,SAAS,cAAc,QAAQ,iBAAiB;AAEhD,SAAS,qBAAqB,QAAkC,iCAAiC;AACjG,SAAS,aAAa,EAAE,mBAAmB,EAAE,YAAY,EAAE,UAAU,QAAQ,YAAY;;AAEzF;AACA;AACA;AACA,WAAY,qBAAqB,0BAArB,qBAAqB;EAC7B;EADQ,qBAAqB;EAG7B;EACA;EACA;EALQ,qBAAqB;E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ACA;AACA;AACA,SAAS,oBAAoB,CACzB,IAA4E,EAC5E,eAAgC,EAChC,OAAsC,EACtC,MAAc,EACD;EACb,MAAM;IAAE,qBAAqB;IAAE;EAA2B,CAAC,GAAG,OAAO;EACrE,IAAI,gBAA+B,GAAG,EAAE;EACxC,IAAI,qBAAqB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE;IAC/D;IACA,gBAAgB,GAAG,CAAC,GAAG,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC,IAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,SAAS,CAAC,aAAa,CAAC;EACnH;EACA,IAAI,0BAA0B,EAAE;IAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;IACzE,IAAI,CAAC,SAAS,EAAE;MACZ,MAAM,CAAC,IAAI,CAAC,8BAA8B,GAAG,IAAI,CAAC,MAAM,GAAG,8BAA8B,CAAC;MAC1F,OAAO,EAAE;IACb;IACA,MAAM,qBAAqB,GAAG,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,qBAAqB,CAAC;IACvF,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CACtC,qBAAqB,CAAC,MAAM,CACvB,oBAAoB,IACjB,CAAC,gBAAgB,CAAC,IAAI;IAClB;IACA;IACC,WAAW,IACR,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,kBAAkB,KAAK,oBAAoB,CAAC,WAAW,CAAC,CACzF,CACR,CACJ,CAAC;EACL;EACA,OAAO,gBAAgB;AAC3B","ignoreList":[]}
|
|
@@ -147,7 +147,7 @@ export class MatrixRTCSessionManager extends TypedEventEmitter {
|
|
|
147
147
|
// Alternatively we would need to setup some event emission when the RTC session ended.
|
|
148
148
|
// TODO we want to add the emission en session end. This makes the responsibility of the session manager more clear.
|
|
149
149
|
|
|
150
|
-
await session.
|
|
150
|
+
await session.ensureRecalculateSessionMembers().catch(error => {
|
|
151
151
|
this.logger.error(`Error updating RTC session members for ${room.roomId}: ${error}`);
|
|
152
152
|
});
|
|
153
153
|
const nowActive = session.memberships.length > 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MatrixRTCSessionManager.js","names":[],"sources":["../../src/matrixrtc/MatrixRTCSessionManager.ts"],"sourcesContent":["/*\nCopyright 2023-2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger } from \"../logger.ts\";\nimport { type MatrixClient, ClientEvent } from \"../client.ts\";\nimport { TypedEventEmitter } from \"../models/typed-event-emitter.ts\";\nimport { type Room } from \"../models/room.ts\";\nimport { RoomStateEvent } from \"../models/room-state.ts\";\nimport { type MatrixEvent } from \"../models/event.ts\";\nimport { MatrixRTCSession } from \"./MatrixRTCSession.ts\";\nimport { EventType } from \"../@types/event.ts\";\nimport { type RtcSlotEventContent, type SlotDescription } from \"./types.ts\";\nimport { computeSlotId } from \"./utils.ts\";\n\nexport enum MatrixRTCSessionManagerEvents {\n // A member has joined the MatrixRTC session, creating an active session in a room where there wasn't previously\n SessionStarted = \"session_started\",\n // All participants have left a given MatrixRTC session.\n SessionEnded = \"session_ended\",\n}\n\ntype EventHandlerMap = {\n [MatrixRTCSessionManagerEvents.SessionStarted]: (roomId: string, session: MatrixRTCSession) => void;\n [MatrixRTCSessionManagerEvents.SessionEnded]: (roomId: string, session: MatrixRTCSession) => void;\n};\n\n/**\n * Holds all active MatrixRTC session objects and creates new ones as events arrive.\n * One `MatrixRTCSessionManager` is required for each MatrixRTC sessionDescription (application, session id) that the client wants to support.\n * If no application type is specified in the constructor, the default is \"m.call\".\n *\n * This interface is UNSTABLE and may change without warning.\n */\nexport class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionManagerEvents, EventHandlerMap> {\n // All the room-scoped sessions we know about. This will include any where the app\n // has queried for the MatrixRTC sessions in a room, whether it's ever had any members\n // or not). We keep a (lazily created) session object for every room to ensure that there\n // is only ever one single room session object for any given room for the lifetime of the\n // client: that way there can never be any code holding onto a stale object that is no\n // longer the correct session object for the room.\n private roomSessions = new Map<string, MatrixRTCSession>();\n\n private readonly logger: Logger;\n\n public constructor(\n rootLogger: Logger,\n private client: MatrixClient,\n private readonly slotDescription: SlotDescription = { application: \"m.call\", id: \"ROOM\" }, // Default to the Matrix Call application\n ) {\n super();\n this.logger = rootLogger.getChild(`[MatrixRTCSessionManager ${computeSlotId(slotDescription)}]`);\n }\n\n public start(): void {\n // We shouldn't need to null-check here, but matrix-client.spec.ts mocks getRooms\n // returning nothing, and breaks tests if you change it to return an empty array :'(\n for (const room of this.client.getRooms() ?? []) {\n const session = MatrixRTCSession.sessionForSlot(this.client, room, this.slotDescription);\n if (session.memberships.length > 0) {\n this.roomSessions.set(room.roomId, session);\n }\n }\n\n this.client.on(ClientEvent.Room, this.onRoom);\n this.client.on(ClientEvent.Event, this.onEvent);\n this.client.on(RoomStateEvent.Events, this.onRoomState);\n }\n\n public stop(): void {\n for (const sess of this.roomSessions.values()) {\n void sess.stop();\n }\n this.roomSessions.clear();\n\n this.client.off(ClientEvent.Room, this.onRoom);\n this.client.off(ClientEvent.Event, this.onEvent);\n this.client.off(RoomStateEvent.Events, this.onRoomState);\n }\n\n /**\n * Gets the main MatrixRTC session for a room, or undefined if there is\n * no current session\n */\n public getActiveRoomSession(room: Room): MatrixRTCSession | undefined {\n return this.roomSessions.get(room.roomId)!;\n }\n\n /**\n * Reads the current slot state event's content for the given room's session.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for the session.\n */\n public getRtcSlot(room: Room): RtcSlotEventContent | undefined {\n return this.getRoomSession(room).getRtcSlot();\n }\n\n /**\n * Whether the given room's slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\n public isSlotClosed(room: Room): boolean | undefined {\n return this.getRoomSession(room).isSlotClosed();\n }\n\n /**\n * Gets the main MatrixRTC session for a room, returning an empty session\n * if no members are currently participating\n */\n public getRoomSession(room: Room): MatrixRTCSession {\n if (!this.roomSessions.has(room.roomId)) {\n this.roomSessions.set(\n room.roomId,\n MatrixRTCSession.sessionForSlot(this.client, room, this.slotDescription),\n );\n }\n\n return this.roomSessions.get(room.roomId)!;\n }\n\n private onRoom = (room: Room): void => {\n void this.refreshRoom(room);\n };\n\n private readonly onEvent = (event: MatrixEvent): void => {\n if (!event.unstableStickyExpiresAt) return; // Not sticky, not interested.\n\n if (event.getType() !== EventType.RTCMembership) return;\n\n const room = this.client.getRoom(event.getRoomId());\n if (!room) return;\n\n void this.refreshRoom(room);\n };\n\n private readonly onRoomState = (event: MatrixEvent): void => {\n if (event.getType() !== EventType.GroupCallMemberPrefix && event.getType() !== EventType.RTCSlot) {\n return;\n }\n const room = this.client.getRoom(event.getRoomId());\n if (!room) {\n this.logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);\n return;\n }\n\n void this.refreshRoom(room);\n };\n\n private async refreshRoom(room: Room): Promise<void> {\n const isNewSession = !this.roomSessions.has(room.roomId);\n const session = this.getRoomSession(room);\n\n const wasActiveAndKnown = session.memberships.length > 0 && !isNewSession;\n // This needs to be here and the event listener cannot be setup in the MatrixRTCSession,\n // because we need the update to happen between:\n // wasActiveAndKnown = session.memberships.length > 0 and\n // nowActive = session.memberships.length\n // Alternatively we would need to setup some event emission when the RTC session ended.\n // TODO we want to add the emission en session end. This makes the responsibility of the session manager more clear.\n\n await session._onRTCSessionMemberUpdate().catch((error) => {\n this.logger.error(`Error updating RTC session members for ${room.roomId}: ${error}`);\n });\n\n const nowActive = session.memberships.length > 0;\n\n if (wasActiveAndKnown && !nowActive) {\n this.logger.trace(`Session ended for ${room.roomId} (${session.memberships.length} members)`);\n this.emit(MatrixRTCSessionManagerEvents.SessionEnded, room.roomId, this.roomSessions.get(room.roomId)!);\n } else if (!wasActiveAndKnown && nowActive) {\n this.logger.trace(`Session started for ${room.roomId} (${session.memberships.length} members)`);\n this.emit(MatrixRTCSessionManagerEvents.SessionStarted, room.roomId, this.roomSessions.get(room.roomId)!);\n }\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAA4B,WAAW,QAAQ,cAAc;AAC7D,SAAS,iBAAiB,QAAQ,kCAAkC;AAEpE,SAAS,cAAc,QAAQ,yBAAyB;AAExD,SAAS,gBAAgB,QAAQ,uBAAuB;AACxD,SAAS,SAAS,QAAQ,oBAAoB;AAE9C,SAAS,aAAa,QAAQ,YAAY;AAE1C,WAAY,6BAA6B,0BAA7B,6BAA6B;EACrC;EADQ,6BAA6B;EAGrC;EAHQ,6BAA6B;EAAA,OAA7B,6BAA6B;AAAA;AAYzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAM,uBAAuB,SAAS,iBAAiB,CAAiD;EAWpG,WAAW,CACd,UAAkB,EACV,MAAoB,EACX,eAAgC,GAAG;IAAE,WAAW,EAAE,QAAQ;IAAE,EAAE,EAAE;EAAO,CAAC,CAAE;EAAA,EAC7F;IACE,KAAK,CAAC,CAAC;IAfX;IACA;IACA;IACA;IACA;IACA;IAAA,sCACuB,IAAI,GAAG,CAA2B,CAAC;IAAA;IAAA,gCAiFxC,IAAU,IAAW;MACnC,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC;IAAA,iCAE2B,KAAkB,IAAW;MACrD,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,OAAO,CAAC;;MAE5C,IAAI,KAAK,CAAC,OAAO,CAAC,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AiB,IAAI,SAAS,EAAE;MACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,WAAW,CAAC;MAC/F,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC;IAC7G;EACJ;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MatrixRTCSessionManager.js","names":[],"sources":["../../src/matrixrtc/MatrixRTCSessionManager.ts"],"sourcesContent":["/*\nCopyright 2023-2026 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type Logger } from \"../logger.ts\";\nimport { type MatrixClient, ClientEvent } from \"../client.ts\";\nimport { TypedEventEmitter } from \"../models/typed-event-emitter.ts\";\nimport { type Room } from \"../models/room.ts\";\nimport { RoomStateEvent } from \"../models/room-state.ts\";\nimport { type MatrixEvent } from \"../models/event.ts\";\nimport { MatrixRTCSession } from \"./MatrixRTCSession.ts\";\nimport { EventType } from \"../@types/event.ts\";\nimport { type RtcSlotEventContent, type SlotDescription } from \"./types.ts\";\nimport { computeSlotId } from \"./utils.ts\";\n\nexport enum MatrixRTCSessionManagerEvents {\n // A member has joined the MatrixRTC session, creating an active session in a room where there wasn't previously\n SessionStarted = \"session_started\",\n // All participants have left a given MatrixRTC session.\n SessionEnded = \"session_ended\",\n}\n\ntype EventHandlerMap = {\n [MatrixRTCSessionManagerEvents.SessionStarted]: (roomId: string, session: MatrixRTCSession) => void;\n [MatrixRTCSessionManagerEvents.SessionEnded]: (roomId: string, session: MatrixRTCSession) => void;\n};\n\n/**\n * Holds all active MatrixRTC session objects and creates new ones as events arrive.\n * One `MatrixRTCSessionManager` is required for each MatrixRTC sessionDescription (application, session id) that the client wants to support.\n * If no application type is specified in the constructor, the default is \"m.call\".\n *\n * This interface is UNSTABLE and may change without warning.\n */\nexport class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionManagerEvents, EventHandlerMap> {\n // All the room-scoped sessions we know about. This will include any where the app\n // has queried for the MatrixRTC sessions in a room, whether it's ever had any members\n // or not). We keep a (lazily created) session object for every room to ensure that there\n // is only ever one single room session object for any given room for the lifetime of the\n // client: that way there can never be any code holding onto a stale object that is no\n // longer the correct session object for the room.\n private roomSessions = new Map<string, MatrixRTCSession>();\n\n private readonly logger: Logger;\n\n public constructor(\n rootLogger: Logger,\n private client: MatrixClient,\n private readonly slotDescription: SlotDescription = { application: \"m.call\", id: \"ROOM\" }, // Default to the Matrix Call application\n ) {\n super();\n this.logger = rootLogger.getChild(`[MatrixRTCSessionManager ${computeSlotId(slotDescription)}]`);\n }\n\n public start(): void {\n // We shouldn't need to null-check here, but matrix-client.spec.ts mocks getRooms\n // returning nothing, and breaks tests if you change it to return an empty array :'(\n for (const room of this.client.getRooms() ?? []) {\n const session = MatrixRTCSession.sessionForSlot(this.client, room, this.slotDescription);\n if (session.memberships.length > 0) {\n this.roomSessions.set(room.roomId, session);\n }\n }\n\n this.client.on(ClientEvent.Room, this.onRoom);\n this.client.on(ClientEvent.Event, this.onEvent);\n this.client.on(RoomStateEvent.Events, this.onRoomState);\n }\n\n public stop(): void {\n for (const sess of this.roomSessions.values()) {\n void sess.stop();\n }\n this.roomSessions.clear();\n\n this.client.off(ClientEvent.Room, this.onRoom);\n this.client.off(ClientEvent.Event, this.onEvent);\n this.client.off(RoomStateEvent.Events, this.onRoomState);\n }\n\n /**\n * Gets the main MatrixRTC session for a room, or undefined if there is\n * no current session\n */\n public getActiveRoomSession(room: Room): MatrixRTCSession | undefined {\n return this.roomSessions.get(room.roomId)!;\n }\n\n /**\n * Reads the current slot state event's content for the given room's session.\n *\n * @returns The slot event's content, or `undefined` if no slot event exists for the session.\n */\n public getRtcSlot(room: Room): RtcSlotEventContent | undefined {\n return this.getRoomSession(room).getRtcSlot();\n }\n\n /**\n * Whether the given room's slot is closed.\n *\n * @returns `true` if the slot is closed, `false` if the slot is open or `undefined`\n * if no slot exists.\n */\n public isSlotClosed(room: Room): boolean | undefined {\n return this.getRoomSession(room).isSlotClosed();\n }\n\n /**\n * Gets the main MatrixRTC session for a room, returning an empty session\n * if no members are currently participating\n */\n public getRoomSession(room: Room): MatrixRTCSession {\n if (!this.roomSessions.has(room.roomId)) {\n this.roomSessions.set(\n room.roomId,\n MatrixRTCSession.sessionForSlot(this.client, room, this.slotDescription),\n );\n }\n\n return this.roomSessions.get(room.roomId)!;\n }\n\n private onRoom = (room: Room): void => {\n void this.refreshRoom(room);\n };\n\n private readonly onEvent = (event: MatrixEvent): void => {\n if (!event.unstableStickyExpiresAt) return; // Not sticky, not interested.\n\n if (event.getType() !== EventType.RTCMembership) return;\n\n const room = this.client.getRoom(event.getRoomId());\n if (!room) return;\n\n void this.refreshRoom(room);\n };\n\n private readonly onRoomState = (event: MatrixEvent): void => {\n if (event.getType() !== EventType.GroupCallMemberPrefix && event.getType() !== EventType.RTCSlot) {\n return;\n }\n const room = this.client.getRoom(event.getRoomId());\n if (!room) {\n this.logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);\n return;\n }\n\n void this.refreshRoom(room);\n };\n\n private async refreshRoom(room: Room): Promise<void> {\n const isNewSession = !this.roomSessions.has(room.roomId);\n const session = this.getRoomSession(room);\n\n const wasActiveAndKnown = session.memberships.length > 0 && !isNewSession;\n // This needs to be here and the event listener cannot be setup in the MatrixRTCSession,\n // because we need the update to happen between:\n // wasActiveAndKnown = session.memberships.length > 0 and\n // nowActive = session.memberships.length\n // Alternatively we would need to setup some event emission when the RTC session ended.\n // TODO we want to add the emission en session end. This makes the responsibility of the session manager more clear.\n\n await session.ensureRecalculateSessionMembers().catch((error) => {\n this.logger.error(`Error updating RTC session members for ${room.roomId}: ${error}`);\n });\n\n const nowActive = session.memberships.length > 0;\n\n if (wasActiveAndKnown && !nowActive) {\n this.logger.trace(`Session ended for ${room.roomId} (${session.memberships.length} members)`);\n this.emit(MatrixRTCSessionManagerEvents.SessionEnded, room.roomId, this.roomSessions.get(room.roomId)!);\n } else if (!wasActiveAndKnown && nowActive) {\n this.logger.trace(`Session started for ${room.roomId} (${session.memberships.length} members)`);\n this.emit(MatrixRTCSessionManagerEvents.SessionStarted, room.roomId, this.roomSessions.get(room.roomId)!);\n }\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAA4B,WAAW,QAAQ,cAAc;AAC7D,SAAS,iBAAiB,QAAQ,kCAAkC;AAEpE,SAAS,cAAc,QAAQ,yBAAyB;AAExD,SAAS,gBAAgB,QAAQ,uBAAuB;AACxD,SAAS,SAAS,QAAQ,oBAAoB;AAE9C,SAAS,aAAa,QAAQ,YAAY;AAE1C,WAAY,6BAA6B,0BAA7B,6BAA6B;EACrC;EADQ,6BAA6B;EAGrC;EAHQ,6BAA6B;EAAA,OAA7B,6BAA6B;AAAA;AAYzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAM,uBAAuB,SAAS,iBAAiB,CAAiD;EAWpG,WAAW,CACd,UAAkB,EACV,MAAoB,EACX,eAAgC,GAAG;IAAE,WAAW,EAAE,QAAQ;IAAE,EAAE,EAAE;EAAO,CAAC,CAAE;EAAA,EAC7F;IACE,KAAK,CAAC,CAAC;IAfX;IACA;IACA;IACA;IACA;IACA;IAAA,sCACuB,IAAI,GAAG,CAA2B,CAAC;IAAA;IAAA,gCAiFxC,IAAU,IAAW;MACnC,KAAK,IAAI,CAAC,W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I,CAAC,6BAA6B,CAAC,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC;IAC3G,CAAC,MAAM,IAAI,CAAC,iBAAiB,IAAI,SAAS,EAAE;MACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,WAAW,CAAC;MAC/F,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAE,CAAC;IAC7G;EACJ;AACJ","ignoreList":[]}
|
|
@@ -43,6 +43,9 @@ export interface MembershipManagerState {
|
|
|
43
43
|
networkErrorRetries: Map<MembershipActionType, number>;
|
|
44
44
|
/** The time at which we expect the server to send the delayed leave event. */
|
|
45
45
|
expectedServerDelayLeaveTs?: number;
|
|
46
|
+
/** The time at which the membership we last sent stops being valid for other clients.
|
|
47
|
+
* Recorded when sending, see `membershipExpiryTsOf`. */
|
|
48
|
+
membershipExpiryTs: number;
|
|
46
49
|
/** This is used to track if the client expects the scheduled delayed leave event to have
|
|
47
50
|
* been sent because restarting failed during the available time.
|
|
48
51
|
* Once we resend the delayed event or successfully restarted it will get unset. */
|
|
@@ -70,6 +73,7 @@ export declare class MembershipManager extends TypedEventEmitter<MembershipManag
|
|
|
70
73
|
private activated;
|
|
71
74
|
private readonly logger;
|
|
72
75
|
protected callIntent: RTCCallIntent | undefined;
|
|
76
|
+
protected applicationData: Record<string, unknown> | undefined;
|
|
73
77
|
isActivated(): boolean;
|
|
74
78
|
isJoined(): boolean;
|
|
75
79
|
/**
|
|
@@ -95,6 +99,7 @@ export declare class MembershipManager extends TypedEventEmitter<MembershipManag
|
|
|
95
99
|
private leavePromiseResolvers?;
|
|
96
100
|
onRTCSessionMemberUpdate(memberships: CallMembership[]): Promise<void>;
|
|
97
101
|
updateCallIntent(callIntent: RTCCallIntent): Promise<void>;
|
|
102
|
+
updateApplicationData(applicationData: Record<string, unknown>): Promise<void>;
|
|
98
103
|
/**
|
|
99
104
|
* @throws if the client does not return user or device id.
|
|
100
105
|
* @param joinConfig
|
|
@@ -130,10 +135,79 @@ export declare class MembershipManager extends TypedEventEmitter<MembershipManag
|
|
|
130
135
|
private cancelKnownDelayIdBeforeSendDelayedEvent;
|
|
131
136
|
private setAndEmitProbablyLeft;
|
|
132
137
|
private setAndEmitDelayId;
|
|
138
|
+
/**
|
|
139
|
+
* Attempts to restart the delayed leave event and keeps everything that depends on it in sync.
|
|
140
|
+
*
|
|
141
|
+
* @param delayId the id of the delayed leave event to restart
|
|
142
|
+
* @returns the outcome of the attempt.
|
|
143
|
+
*/
|
|
144
|
+
private tryRestartDelayedEvent;
|
|
133
145
|
private restartDelayedEvent;
|
|
134
146
|
private sendScheduledDelayedLeaveEventOrFallbackToSendLeaveEvent;
|
|
135
147
|
protected clientSendMembership: (myMembership: RtcMembershipData | SessionMembershipData | EmptyObject) => Promise<ISendEventResponse>;
|
|
136
148
|
private sendJoinEvent;
|
|
149
|
+
/**
|
|
150
|
+
* The timestamp at which a membership we send stops being valid for other clients.
|
|
151
|
+
*
|
|
152
|
+
* State events are valid until `created_ts + expires`. `makeMyMembership` inherits `created_ts` from our previous
|
|
153
|
+
* membership when we have one, otherwise the event's own timestamp counts.
|
|
154
|
+
* @param sent the membership as we sent it
|
|
155
|
+
*/
|
|
156
|
+
protected membershipExpiryTsOf(sent: SessionMembershipData | RtcMembershipData): number;
|
|
157
|
+
/**
|
|
158
|
+
* Gives up on our current membership and starts a fresh join.
|
|
159
|
+
*
|
|
160
|
+
* We forget our own membership so that the next state event does not inherit its `created_ts`. That would keep
|
|
161
|
+
* the identity of the membership we are giving up while `expires` starts over from a single iteration, which can
|
|
162
|
+
* put the absolute expiry in the past.
|
|
163
|
+
* @param reason why we are not keeping the current membership. Only used for logging.
|
|
164
|
+
*/
|
|
165
|
+
private rejoinFromScratch;
|
|
166
|
+
/**
|
|
167
|
+
* Schedules another attempt at the expiry update. Once our membership has expired we stop trying to keep it alive
|
|
168
|
+
* and rejoin instead, so that we never end up silently expired.
|
|
169
|
+
* @param delayMs how long to wait before trying again. Clamped so that we always get a last attempt at the moment
|
|
170
|
+
* the membership expires, and never schedule one beyond it.
|
|
171
|
+
* @param reason why we cannot update the expiry right now. Only used for logging.
|
|
172
|
+
* @param resendDelayedEvent whether to schedule a replacement delayed leave event first, with the retry running
|
|
173
|
+
* right after it.
|
|
174
|
+
*/
|
|
175
|
+
private deferExpiryUpdate;
|
|
176
|
+
/**
|
|
177
|
+
* Makes sure a delayed leave event is scheduled that will outlive the membership update we are about to send.
|
|
178
|
+
*
|
|
179
|
+
* Re-sending our membership is only safe while our delayed leave event is still scheduled: if the server has
|
|
180
|
+
* already sent it (e.g. because the device was asleep and no restarts reached the server), the membership we
|
|
181
|
+
* would send would come back to life without any delayed leave event to clean it up, and stay until `expires`
|
|
182
|
+
* runs out. So we restart the delayed event first. A success guarantees it will outlive the membership update;
|
|
183
|
+
* a 404 tells us it is gone, and we have to work out why.
|
|
184
|
+
* @returns `undefined` if the membership can be sent, otherwise the action to take instead.
|
|
185
|
+
*/
|
|
186
|
+
private ensureDelayedLeaveEventProtectsMembership;
|
|
187
|
+
/**
|
|
188
|
+
* Without a delay id, a `SendDelayedEvent` action may be queued that has not succeeded yet. Then we wait for it
|
|
189
|
+
* rather than put the membership back on the server with nothing to clean it up. The retry gets the same
|
|
190
|
+
* timestamp, and actions with the same timestamp run in insertion order, so it runs right after that attempt:
|
|
191
|
+
* straight away if the delayed event is there, or to wait for the next attempt if it rescheduled.
|
|
192
|
+
*
|
|
193
|
+
* Without such an action queued we are not using delayed events at all, because the homeserver does not support
|
|
194
|
+
* them. Then there is also no delayed leave event that could have removed our membership, and nothing to protect
|
|
195
|
+
* it from.
|
|
196
|
+
* @returns `undefined` if the membership can be sent, otherwise the deferred expiry update.
|
|
197
|
+
*/
|
|
198
|
+
private waitForPendingDelayedLeaveEvent;
|
|
199
|
+
/**
|
|
200
|
+
* The server does not know our delayed leave event anymore. Whether it sent it or lost it decides whether we
|
|
201
|
+
* still have a membership to extend.
|
|
202
|
+
*/
|
|
203
|
+
private recoverFromGoneDelayedLeaveEvent;
|
|
204
|
+
/**
|
|
205
|
+
* Restarting our delayed leave event failed with something other than a 404.
|
|
206
|
+
* @param error what the restart failed with
|
|
207
|
+
* @returns `undefined` if the membership can be sent regardless, otherwise the action to take instead.
|
|
208
|
+
* @throws the error if it is not one we retry on.
|
|
209
|
+
*/
|
|
210
|
+
private recoverFromFailedDelayedLeaveEventRestart;
|
|
137
211
|
private updateExpiryOnJoinedEvent;
|
|
138
212
|
private sendFallbackLeaveEvent;
|
|
139
213
|
/**
|
|
@@ -202,6 +276,8 @@ export declare class StickyEventMembershipManager extends MembershipManager {
|
|
|
202
276
|
protected clientSendMembership: (myMembership: RtcMembershipData | SessionMembershipData | EmptyObject) => Promise<ISendEventResponse>;
|
|
203
277
|
private static nameMap;
|
|
204
278
|
protected actionUpdateFromErrors(e: unknown, t: MembershipActionType, m: string): ActionUpdate | undefined;
|
|
279
|
+
/** A sticky event vanishes `MEMBERSHIP_STICKY_DURATION_MS` after it was sent, whatever its content says. */
|
|
280
|
+
protected membershipExpiryTsOf(): number;
|
|
205
281
|
/**
|
|
206
282
|
*
|
|
207
283
|
* @returns Only returns `RtcMembershipData`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MembershipManager.d.ts","sourceRoot":"","sources":["../../src/matrixrtc/MembershipManager.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;A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