import { type WsFrame, type WsTimers } from "./frames.js"; export declare const CONNECTING = 0; export declare const OPEN = 1; export declare const CLOSING = 2; export declare const CLOSED = 3; export interface WsCloseEventInit extends EventInit { code?: number; reason?: string; wasClean?: boolean; } /** * A `CloseEvent` for runtimes that have none: Node 22 has `Event` and * `MessageEvent` as globals, but not `CloseEvent`. */ export declare class WsCloseEvent extends Event { readonly code: number; readonly reason: string; readonly wasClean: boolean; constructor(type: string, init?: WsCloseEventInit); } /** A `close` event: the platform's `CloseEvent` where there is one. */ export declare function newCloseEvent(init: WsCloseEventInit): Event; export interface PortSocketOptions { timers?: WsTimers; /** How long to wait for the echo of a close frame before giving up with 1006. */ closeTimeoutMs?: number; } /** * What both ends of a socket over a `MessagePort` share: the frames, the close * handshake, and the byte accounting behind `bufferedAmount`. * * Not exported from the package: the two ends are `createWebSocketClass`'s * class and `ServerWebSocket`. */ export declare abstract class PortSocketCore extends EventTarget { protected _port?: MessagePort; protected _state: number; protected readonly _timers: WsTimers; protected readonly _closeTimeoutMs: number; /** Bytes sent and not yet acknowledged by the peer, plus those still being prepared. */ private _inFlight; /** Bytes of messages "sent" after the socket started closing: counted, never sent. */ private _discarded; private _toAck; private _ackScheduled; private _closeTimer; private _drainWaiters; constructor(options?: PortSocketOptions); get readyState(): number; /** * Bytes queued by `send()` that the peer has not consumed yet. A peer * acknowledges what it has dispatched, so this falls as the other side reads. */ get bufferedAmount(): number; /** * Resolves once `bufferedAmount` is at most `limit` (default 0), or the * socket is closed. The backpressure a producer applies: * `if (socket.bufferedAmount > HIGH) await socket.whenDrained(LOW)`. */ whenDrained(limit?: number): Promise; protected _attach(port: MessagePort): void; protected _onFrame(frame: WsFrame): void; /** A message or close frame the socket is ready to act on. */ protected _deliver(frame: Extract): void; protected abstract _dispatchMessage(data: string | ArrayBuffer): void; protected _onPing(_hb: number): void; protected _onPong(): void; protected _onClosed(): void; /** Acknowledge consumed bytes, coalescing the acks of one turn into one frame. */ protected _consumed(bytes: number): void; /** Reserves `bytes` in `bufferedAmount` for a message still being prepared (a Blob). */ protected _reserve(bytes: number): void; /** Sends one message whose bytes were reserved with `_reserve` (or `reserved = false`). */ protected _sendData(data: string | ArrayBuffer, reserved?: boolean): void; protected _post(frame: WsFrame): void; /** Starts the close handshake. */ protected _startClose(code: number, reason: string): void; protected _onCloseFrame(code: number, reason: string): void; /** The socket is closed: release the port and tell the listeners. */ protected _finish(code: number, reason: string, wasClean: boolean, error?: boolean): void; private _wakeDrainWaiters; } /** Copies `data` into a fresh `ArrayBuffer`: `send()` must never detach the caller's buffer. */ export declare function toArrayBuffer(data: ArrayBuffer | ArrayBufferView): ArrayBuffer; export declare function isBinary(data: unknown): data is ArrayBuffer | ArrayBufferView; export declare function isBlob(data: unknown): data is Blob; /** Valid close codes for an application to send: 1000, or 3000–4999. */ export declare function isApplicationCloseCode(code: number): boolean; //# sourceMappingURL=socket-core.d.ts.map