import { ChannelManager } from './channel-manager.js'; import { DiscontinuityListener } from './discontinuity.js'; import { RoomEventType } from './events.js'; import { Logger } from './logger.js'; import { InternalRoomLifecycle } from './room-status.js'; import { StatusSubscription } from './subscription.js'; import * as Ably from '@ably/pubsub-core'; /** * Events that can be emitted by the RoomLifecycleManager */ export interface RoomLifeCycleEvents { [RoomEventType.Discontinuity]: Ably.ErrorInfo; } /** * Manages the lifecycle of a room's underlying channel, handling attach, detach and release operations * while maintaining the room's status. */ export declare class RoomLifecycleManager { private readonly _channelManager; private readonly _roomLifecycle; private readonly _logger; private readonly _eventEmitter; private _hasAttachedOnce; private _isExplicitlyDetached; private readonly _mutex; private readonly _unsubscribeChannelStateListener; private readonly _offDiscontinuityAttached; private readonly _offDiscontinuityUpdate; constructor(channelManager: ChannelManager, roomLifecycle: InternalRoomLifecycle, logger: Logger); /** * Registers a handler for discontinuity events. * @param handler The function to be called when a discontinuity is detected * @returns An object with an off() method to deregister the handler */ onDiscontinuity(handler: DiscontinuityListener): StatusSubscription; /** * Attaches to the channel and updates room status accordingly. * If the room is released/releasing, this operation fails. * If already attached, this is a no-op. */ attach(): Promise; /** * Detaches from the channel and updates room status accordingly. * If the room is released/releasing, this operation fails. * If already detached, this is a no-op. */ detach(): Promise; /** * Releases the room by detaching the channel and releasing it from the channel manager. * If the channel is in a failed state, skips the detach operation. * Will retry detach until successful unless in failed state. */ release(): Promise; /** * Maps an Ably channel state to a room status * @param channelState The Ably channel state to map. * @returns The corresponding room status. */ private _mapChannelStateToRoomStatus; private _checkRoomNotReleasing; /** * Returns the current room status * @param status The room status to check against. * @returns true if the room status matches, false otherwise. */ private _roomStatusIs; private _channelStateListener; private _discontinuityOnAttachedListener; private _discontinuityOnUpdateListener; private _channelDetachLoop; private _setStatus; private _releaseChannel; /** * Returns whether there is currently an operation (attach/detach/release) in progress * @returns True if an operation is in progress, false otherwise. */ private _operationInProgress; testForceHasAttachedOnce(firstAttach: boolean): void; }