export default class VelociousHttpServerClientWebsocketSession {
    /**
     * Runs constructor.
     * @param {object} args - Options object.
     * @param {import("../../configuration.js").default} args.configuration - Configuration instance.
     * @param {import("./index.js").default} args.client - Client instance.
     * @param {import("./request.js").default | import("./websocket-request.js").default} [args.upgradeRequest] - Initial websocket upgrade request.
     * @param {import("../../configuration-types.js").WebsocketMessageHandler} [args.messageHandler] - Optional raw message handler.
     * @param {Promise<import("../../configuration-types.js").WebsocketMessageHandler | void>} [args.messageHandlerPromise] - Optional raw message handler promise.
     */
    constructor({ client, configuration, upgradeRequest, messageHandler, messageHandlerPromise }: {
        configuration: import("../../configuration.js").default;
        client: import("./index.js").default;
        upgradeRequest?: WebsocketRequest | import("./request.js").default | undefined;
        messageHandler?: import("../../configuration-types.js").WebsocketMessageHandler | undefined;
        messageHandlerPromise?: Promise<void | import("../../configuration-types.js").WebsocketMessageHandler> | undefined;
    });
    events: import("eventemitter3").EventEmitter<string | symbol, any>;
    subscriptions: Set<any>;
    channels: Set<any>;
    subscriptionHandlers: Map<any, any>;
    handlerSubscriptions: Map<any, any>;
    channelTenants: Map<any, any>;
    channelReplayStates: Map<any, any>;
    /**
     * Message queue.
      @type {WebsocketSessionMessage[]} */
    messageQueue: WebsocketSessionMessage[];
    buffer: Buffer<ArrayBuffer>;
    client: import("./index.js").default;
    configuration: import("../../configuration.js").default;
    upgradeRequest: WebsocketRequest | import("./request.js").default | undefined;
    messageHandler: import("../../configuration-types.js").WebsocketMessageHandler | undefined;
    messageHandlerPromise: Promise<void | import("../../configuration-types.js").WebsocketMessageHandler> | undefined;
    pendingMessageHandler: boolean;
    logger: Logger;
    /**
     * Narrows the runtime value to the documented type.
      @type {Record<string, ?>} */
    _metadata: Record<string, unknown>;
    /**
     * Long-lived per-session state bag. Stable across reconnects once
     * grace-period resumption lands in Phase 2; today it just lives
     * for the duration of the underlying socket.
     * @type {Record<string, ?>}
     */
    data: Record<string, unknown>;
    /**
     * Narrows the runtime value to the documented type.
      @type {Map<string, import("../websocket-connection.js").default>} */
    _connections: Map<string, import("../websocket-connection.js").default>;
    /**
     * Narrows the runtime value to the documented type.
      @type {Map<string, {channelType: string, subscription: import("../websocket-channel.js").default}>} */
    _channelSubscriptions: Map<string, {
        channelType: string;
        subscription: import("../websocket-channel.js").default;
    }>;
    /**
     * Unique id assigned to this session on first connect. Sent to the
     * client via `session-established`; the client echoes it back via
     * `session-resume` after a WS drop to reattach to this session
     * within the grace period.
     * @type {string}
     */
    sessionId: string;
    /**
     * Narrows the runtime value to the documented type.
     * @type {boolean} - true after `_handleClose` pauses instead of tearing down.
     */
    _paused: boolean;
    /**
     * Narrows the runtime value to the documented type.
     * @type {Array<?>} - frames produced while paused; flushed on resume.
     */
    _outboundQueue: Array<unknown>;
    /**
     * Narrows the runtime value to the documented type.
      @type {import("./index.js").default | null} */
    socket: import("./index.js").default | null;
    /**
     * Tail of a per-session promise chain that serializes message
     * handling. Prevents races where message B reads `session.data`
     * before message A's handler finishes writing it (e.g. a
     * connection-message setting the locale vs. a subsequent request
     * whose aroundRequest wrapper reads it).
     * @type {Promise<void>}
     */
    _messageChain: Promise<void>;
    /**
     * Promise that resolves to the auth identity captured at pause
     * time by `getWebsocketSessionIdentityResolver`. Awaited at resume
     * time to compare against the fresh caller's identity. Undefined
     * on a live (non-paused) session.
     * @type {Promise<?> | undefined}
     */
    _resumeIdentityPromise: Promise<unknown> | undefined;
    /**
     * Accumulates payloads for a fragmented websocket message per
     * RFC 6455. Non-null while mid-fragment; cleared when the frame
     * with FIN=1 completes and the message is dispatched.
     * @type {Buffer[] | null}
     */
    _fragmentedPayloads: Buffer[] | null;
    /**
     * Opcode (TEXT/BINARY) captured from the first frame of a
     * fragmented message. Continuation frames (opcode 0) inherit it
     * at reassembly time.
     * @type {number | null}
     */
    _fragmentedOpcode: number | null;
    /**
     * Running byte total for `_fragmentedPayloads`. Used to enforce
     * `WEBSOCKET_MAX_FRAGMENTED_MESSAGE_BYTES` so a peer cannot
     * exhaust memory by streaming non-final fragments indefinitely.
     * @type {number}
     */
    _fragmentedBytes: number;
    /**
     * Sends the client its sessionId + grace window. Called by
     * `VelociousHttpServerClient` after the WS upgrade completes.
     * @returns {void}
     */
    sendSessionEstablished(): void;
    /**
     * Removes a closed connection from the session registry. Called by
     * `VelociousWebsocketConnection.close()` after it sends the final
     * `connection-closed` frame.
     * @param {string} connectionId
     * @returns {void}
     */
    _removeConnection(connectionId: string): void;
    /**
     * Runs get metadata.
     * @returns {Record<string, ?>} - Client-provided metadata (defensive copy).
     */
    getMetadata(): Record<string, unknown>;
    /**
     * Runs is paused.
     * @returns {boolean} - true while the session is in the paused/grace registry.
     */
    isPaused(): boolean;
    /**
     * Runs add subscription.
     * @param {string} channel - Channel name.
     * @returns {void} - No return value.
     */
    addSubscription(channel: string): void;
    destroy(): void;
    /**
     * Runs has subscription.
     * @param {string} channel - Channel name.
     * @returns {boolean} - Whether it has subscription.
     */
    hasSubscription(channel: string): boolean;
    /**
     * Runs on data.
     * @param {Buffer} data - Data payload.
     * @returns {void} - No return value.
     */
    onData(data: Buffer): void;
    /**
     * Runs send event.
     * @param {string} channel - Channel name.
     * @param {?} payload - Payload data.
     * @param {{createdAt?: string, eventId?: string, replayed?: boolean, sequence?: number}} [options] - Event metadata.
     * @returns {Promise<void>} - Resolves when complete.
     */
    sendEvent(channel: string, payload: unknown, options?: {
        createdAt?: string;
        eventId?: string;
        replayed?: boolean;
        sequence?: number;
    }): Promise<void>;
    /**
     * Runs initialize channel.
     * @returns {Promise<void>} - Resolves when complete.
     */
    initializeChannel(): Promise<void>;
    /**
     * Runs send goodbye.
     * @param {import("./index.js").default} client - Client instance.
     * @returns {void} - No return value.
     */
    sendGoodbye(client: import("./index.js").default): void;
    /**
     * Runs handle message.
     * @param {WebsocketSessionMessage} message - Message text.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _handleMessage(message: WebsocketSessionMessage): Promise<void>;
    /**
     * Runs dispatch message.
     * @param {WebsocketSessionMessage} message - Message text.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _dispatchMessage(message: WebsocketSessionMessage): Promise<void>;
    /**
     * The actual message dispatch, extracted so
     * `configuration.getWebsocketAroundRequest()` can wrap it in any
     * per-request context (AsyncLocalStorage, tracing, etc.).
     * @param {WebsocketSessionMessage} message
     * @returns {Promise<void>}
     */
    _handleMessageInner(message: WebsocketSessionMessage): Promise<void>;
    /**
     * Runs process buffer.
     * @returns {void} - No return value.
     */
    _processBuffer(): void;
    /**
     * Appends a continuation-frame payload to the in-progress
     * fragmented message. Returns true when the fragment was accepted
     * and false when the per-message cap was hit and the socket has
     * been closed.
     * @param {Buffer} payload
     * @returns {boolean}
     */
    _appendFragment(payload: Buffer): boolean;
    /**
     * Verifies the fragmented message has not exceeded the byte or
     * fragment-count caps. On overflow, clears the buffer, sends a
     * close frame, and tears the session down. Returns true when the
     * caller can continue processing, false when the session is being
     * closed.
     * @returns {boolean}
     */
    _enforceFragmentLimits(): boolean;
    /**
     * Runs reset fragment buffer.
      @returns {void} */
    _resetFragmentBuffer(): void;
    /**
     * Runs send control frame.
     * @param {number} opcode - Opcode.
     * @param {Buffer} payload - Payload data.
     * @returns {void} - No return value.
     */
    _sendControlFrame(opcode: number, payload: Buffer): void;
    /**
     * Runs send json.
     * @param {object} body - Request body.
     * @returns {void} - No return value.
     */
    sendJson(body: object): void;
    /**
     * Flushes the paused outbound queue over the current socket.
     * Called during resume after `session-resumed` has been sent on
     * the NEW session's socket (not this session's).
     * @returns {void}
     */
    _flushOutboundQueue(): void;
    /**
     * Runs subscribe to channel.
     * @param {string} channel - Channel name.
     * @param {{acknowledge?: boolean, channelHandler?: import("../websocket-channel.js").default, lastEventId?: string, params?: Record<string, ?>, subscriptionChannel?: string}} [options] - Subscribe options.
     * @returns {Promise<boolean>} - Whether the subscription was added.
     */
    subscribeToChannel(channel: string, { acknowledge, channelHandler, lastEventId, params, subscriptionChannel }?: {
        acknowledge?: boolean;
        channelHandler?: import("../websocket-channel.js").default;
        lastEventId?: string;
        params?: Record<string, unknown>;
        subscriptionChannel?: string;
    }): Promise<boolean>;
    _handleClose(): void;
    /**
     * Called by the grace timer when the paused period expires without
     * a resume. Tears down all live Connections + Channel subs and
     * drops the session.
     * @returns {void}
     */
    _finalizeGraceExpiry(): void;
    /**
     * Runs the configured identity resolver against this session.
     * The returned promise is stored at pause time and awaited at
     * resume time so we can reject resume attempts from a different
     * authenticated caller (signed out, swapped user, expired cookie).
     * @returns {Promise<?>}
     */
    _captureResumeIdentity(): Promise<unknown>;
    /**
     * Fires `onDisconnect` on every live Connection and Channel sub so
     * apps can pause per-instance work while the session is paused.
     * Errors are logged, not rethrown — one broken handler must not
     * block the rest.
     * @returns {Promise<void>}
     */
    _fireOnDisconnect(): Promise<void>;
    /**
     * Fires `onResume` on every live Connection and Channel sub after
     * a successful `session-resume` handoff.
     * @returns {Promise<void>}
     */
    _fireOnResume(): Promise<void>;
    /**
     * Runs fire lifecycle callback.
     * @param {"onDisconnect" | "onResume"} callbackName Lifecycle callback to fire.
     * @returns {Promise<void>} Resolves when every live handler has been attempted.
     */
    _fireLifecycleCallback(callbackName: "onDisconnect" | "onResume"): Promise<void>;
    /**
     * Handles `{type: "session-resume"}`. This session (the newly-
     * created one whose socket just connected) transfers state from
     * the paused session and instructs the client via
     * `session-resumed` or `session-gone`.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleSessionResume(message: Record<string, unknown>): Promise<void>;
    /**
     * Fires `onClose(reason)` on every live app-defined connection, then
     * drops them from the registry. No network frame is sent — the
     * socket is already going away.
     * @param {"session_destroyed" | "grace_expired" | "error"} reason
     * @returns {Promise<void>}
     */
    _teardownConnections(reason: "session_destroyed" | "grace_expired" | "error"): Promise<void>;
    /**
     * Handles a `{type: "connection-open"}` message — instantiates the
     * registered connection class, stores it on `_connections`, and
     * fires `onConnect()`. Sends `connection-opened` on success or
     * `connection-error` on failure.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleConnectionOpen(message: Record<string, unknown>): Promise<void>;
    /**
     * Handles a `{type: "connection-message"}` from the client.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleConnectionMessage(message: Record<string, unknown>): Promise<void>;
    /**
     * Handles a `{type: "connection-close"}` from the client — fires
     * `onClose("client_close")` and confirms with `connection-closed`.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleConnectionClose(message: Record<string, unknown>): Promise<void>;
    /**
     * Handles `{type: "channel-subscribe"}` — runs `canSubscribe()`,
     * registers with the Configuration's global routing registry on
     * success, and sends `channel-subscribed` or `channel-error`.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleChannelSubscribe(message: Record<string, unknown>): Promise<void>;
    /**
     * Replays missed events from the persistent event-log store for a
     * channel subscription that provided `lastEventId`. Sends each
     * missed event as a `channel-message` with `replayed: true`.
     * @param {object} args - Options.
     * @param {string} args.channelType - Channel type name (event-log key).
     * @param {string} args.lastEventId - Client's last-seen event id.
     * @param {import("../websocket-channel.js").default} args.subscription - Live subscription.
     * @returns {Promise<void>}
     */
    _replayChannelEventsForSubscription({ channelType, lastEventId, subscription }: {
        channelType: string;
        lastEventId: string;
        subscription: import("../websocket-channel.js").default;
    }): Promise<void>;
    /**
     * Handles `{type: "channel-unsubscribe"}` from the client — calls
     * `unsubscribed()` and sends `channel-unsubscribed`.
     * @param {Record<string, ?>} message
     * @returns {Promise<void>}
     */
    _handleChannelUnsubscribe(message: Record<string, unknown>): Promise<void>;
    /**
     * Fires `unsubscribed()` on every live channel-v2 subscription,
     * removes them from the Configuration's global registry, and
     * drops the session's own map. No network frames — the socket
     * is already going away.
     * @returns {Promise<void>}
     */
    _teardownChannelSubscriptions(): Promise<void>;
    _teardownChannel(): Promise<void>;
    /**
     * Runs teardown single channel.
     * @param {WebsocketChannel} channel - Channel instance.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _teardownSingleChannel(channel: WebsocketChannel): Promise<void>;
    /**
     * Runs register channel.
     * @param {WebsocketChannel | undefined} channel - Channel instance.
     * @param {string | null | undefined} tenant - Tenant key.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _registerChannel(channel: WebsocketChannel | undefined, tenant: string | null | undefined): Promise<void>;
    /**
     * Runs with connections.
     * @param {() => Promise<void>} callback - Callback.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _withConnections(callback: () => Promise<void>): Promise<void>;
    /**
     * Runs handle channel subscription.
     * @param {{channel: string, lastEventId?: string, params?: Record<string, ?>}} args - Subscription args.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _handleChannelSubscription({ channel, lastEventId, params }: {
        channel: string;
        lastEventId?: string;
        params?: Record<string, unknown>;
    }): Promise<void>;
    /**
     * Runs prepare replay state.
     * @param {object} args - Options.
     * @param {string} args.channel - Internal channel name.
     * @param {string | undefined} args.lastEventId - Last received event id.
     * @param {string} args.subscriptionChannel - Client-facing channel name.
     * @param {Record<string, ?> | undefined} args.subscriptionParams - Client-facing params.
     * @returns {Promise<false | {buffered: boolean, ceilingSequence: number, checkpointSequence: number, replaying: boolean} | null>} - Replay state.
     */
    _prepareReplayState({ channel, lastEventId, subscriptionChannel, subscriptionParams }: {
        channel: string;
        lastEventId: string | undefined;
        subscriptionChannel: string;
        subscriptionParams: Record<string, unknown> | undefined;
    }): Promise<false | {
        buffered: boolean;
        ceilingSequence: number;
        checkpointSequence: number;
        replaying: boolean;
    } | null>;
    /**
     * Runs replay channel events.
     * @param {object} args - Options.
     * @param {string} args.channel - Channel name.
     * @param {{buffered: boolean, ceilingSequence: number, checkpointSequence: number, replaying: boolean}} args.replayState - Replay state.
     * @returns {Promise<void>} - Resolves when replay completes.
     */
    _replayChannelEvents({ channel, replayState }: {
        channel: string;
        replayState: {
            buffered: boolean;
            ceilingSequence: number;
            checkpointSequence: number;
            replaying: boolean;
        };
    }): Promise<void>;
    /**
     * Runs finish replay state.
     * @param {string} channel - Channel name.
     * @param {{buffered: boolean, ceilingSequence: number, checkpointSequence: number, replaying: boolean}} replayState - Replay state.
     * @returns {Promise<void>} - Resolves when buffered events are flushed.
     */
    _finishReplayState(channel: string, replayState: {
        buffered: boolean;
        ceilingSequence: number;
        checkpointSequence: number;
        replaying: boolean;
    }): Promise<void>;
    /**
     * Runs resolve tenant.
     * @param {{channel?: string, params?: Record<string, ?>}} args - Tenant resolution args.
     * @returns {Promise<string | null | undefined>} - Resolved tenant.
     */
    _resolveTenant({ channel, params }: {
        channel?: string;
        params?: Record<string, unknown>;
    }): Promise<string | null | undefined>;
    /**
     * Runs unmask payload.
     * @param {Buffer} payload - Payload data.
     * @param {Buffer} mask - Mask.
     * @returns {Buffer} - The unmask payload.
     */
    _unmaskPayload(payload: Buffer, mask: Buffer): Buffer;
    _runMessageHandlerOpen(): Promise<void>;
    /**
     * Runs run message handler message.
     * @param {WebsocketSessionMessage} message - Incoming websocket message.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _runMessageHandlerMessage(message: WebsocketSessionMessage): Promise<void>;
    _runMessageHandlerClose(): Promise<void>;
    /**
     * Runs remote address.
     * @returns {string | undefined} - Remote address resolved from the websocket upgrade request.
     */
    remoteAddress(): string | undefined;
    /**
     * Runs set message handler.
     * @param {import("../../configuration-types.js").WebsocketMessageHandler} handler - Handler instance.
     * @returns {void}
     */
    setMessageHandler(handler: import("../../configuration-types.js").WebsocketMessageHandler): void;
    _resolveMessageHandlerPromise(): Promise<void>;
    /**
     * Runs flush queued messages.
     * @param {{useHandler: boolean}} args - Args.
     * @returns {Promise<void>} - Resolves when complete.
     */
    _flushQueuedMessages({ useHandler }: {
        useHandler: boolean;
    }): Promise<void>;
}
/**
 * Defines this typedef.
 */
export type WebsocketSessionMessage = {
    type: "subscribe";
    channel: string;
    lastEventId?: string;
    params?: Record<string, unknown>;
} | {
    type: "metadata";
    data?: Record<string, unknown>;
} | {
    type?: "request";
    body?: unknown;
    headers?: Record<string, unknown>;
    id?: string | number | null;
    method: string;
    path: string;
} | Record<string, unknown>;
import WebsocketRequest from "./websocket-request.js";
import Logger from "../../logger.js";
import WebsocketChannel from "../websocket-channel.js";
//# sourceMappingURL=websocket-session.d.ts.map