export { ClientChannel, ClientBroadcast }; import type { ChannelAck, ClientChannel as ClientChannelType, ChannelCloseCallback, ChannelCloseOptions, ChannelCloseResult, ChannelData, ChannelListener, ChannelBinaryListener, ChannelPublishAck, BroadcastBinaryListener, BroadcastListener } from '../channel.js'; import type { TELEFUNC_SHIELDS } from '../../node/shared/transformer/generateShield/shield-key.js'; import { type AckResultStatus, type ChannelCtrlFrame, type ChannelDataFrame, type ChannelFrame, type WirePublishInfo } from '../shared-ws.js'; import { type ChannelTransports } from '../constants.js'; import type { MuxChannel, MuxConnection } from './connection.js'; declare const CLIENT_BROADCAST_BRAND: unique symbol; declare class ClientChannel implements ClientChannelType, MuxChannel { /** @see ChannelShield in ../channel.ts — `data` validates C2S; `ack` validates ack of own C2S send. */ readonly [TELEFUNC_SHIELDS]: { data: ChannelData; ack: ChannelAck; }; readonly id: string; readonly ack: boolean; readonly key: string | undefined; protected _connection: MuxConnection; private _listeners; private _binaryListeners; private _openCallbacks; private _closeCallbacks; private _closeError; protected _isClosed: boolean; private _didTerminate; private _didFireClose; private _didFireOpen; private _closePromise; private _closeDeadline; private _closeWaiters; private _didReceiveCloseAck; private _expectCloseAck; private _pendingCloseCallbacks; protected _inflightAcks: number; /** Outstanding ack-bearing sends, keyed by the seq the server will echo on `ACK_RES`. * Lives on the channel (mirrors server-side `_pendingAcks`) so per-channel state * stays encapsulated; connection just routes ACK_RES frames in. `resolve` is typed * `any` because the channel hosts ack-bearing sends with several distinct resolution * types (`ChannelAck`, `unknown` for binary, `ChannelPublishAck` for broadcast * publishes); the stored resolver is always invoked with `parse(text)` at the boundary. */ protected _pendingAcks: Map void; reject: (err: Error) => void; }>; /** Owns sender-side credit, receiver-side consumption tracking, BDP estimator, * and the queue of senders blocked on credit refresh. Credit governs fire-and- * forget TEXT/BINARY only — see `constants.ts`. */ private _flow; constructor({ channelId, ack, key, transports, connectionKey, headers, telefuncUrl, idleTimeout, }: { channelId: string; ack?: boolean; key?: string; transports: ChannelTransports; connectionKey?: string; headers?: Record; telefuncUrl: string; idleTimeout?: number; }); get isClosed(): boolean; send(data: ChannelData): Promise; send(data: ChannelData, opts: { ack: true; }): Promise>; send(data: ChannelData, opts: { ack: false; }): Promise; _send(data: ChannelData, opts?: { ack?: boolean; }): void | Promise> | Promise; sendBinary(data: Uint8Array): Promise; sendBinary(data: Uint8Array, opts: { ack: true; }): Promise; sendBinary(data: Uint8Array, opts: { ack: false; }): Promise; _sendBinary(data: Uint8Array, opts?: { ack?: boolean; }): void | Promise | Promise; /** Decrement credit by `bytes`; return void if credit remains, otherwise a Promise * that resolves when credit refreshes (so the caller's next `await` blocks). * * Cooperative model: the send already fired in `connection.send(...)`; this only * gates the return value. Awaiting throttles the caller's next send; not awaiting * bypasses (matches the user-facing "skip await for max bandwidth" escape hatch). */ private _waitForWindow; listen(callback: ChannelListener): () => void; listenBinary(callback: ChannelBinaryListener): () => void; onClose(callback: ChannelCloseCallback): void; onOpen(callback: () => void): void; close(opts?: ChannelCloseOptions): Promise; abort(): void; abort(abortValue: unknown, message?: string): void; _onTransportOpen(batched: boolean): void; _onTransportMessage(data: string, bytes: number): void; _onTransportAckReqMessage(data: string, seq: number): Promise; _onTransportBinaryAckReqMessage(data: Uint8Array, seq: number): Promise; _onTransportBinaryMessage(data: Uint8Array): void; /** @internal — Entry point for every per-channel wire frame. The connection routes * here for any frame carrying an index; this method then splits ctrl vs data. */ _dispatchFrame(frame: ChannelFrame): void; /** @internal — Tag-keyed data-frame switch. `ClientBroadcast` overrides to add the * PUBLISH variants and falls back to `super` for the common cases. Receive-time * BDP accounting happens inside each credit-counted `_onTransport*` handler. */ protected _dispatchDataFrame(frame: ChannelDataFrame): void; /** @internal — Per-channel ctrl-message switch. Connection-level ctrls (PING/PONG/ * FIN/RECONCILED) and channel-termination ctrls (ABORT/ERROR — which involve * connection-side cleanup) are handled by the connection and never reach here. */ protected _dispatchCtrl(frame: ChannelCtrlFrame): void; /** Settle an outstanding ack-bearing send. Mirrors server-side `_onPeerAckRes`. */ protected _onPeerAckRes(ackedSeq: number, text: string, status: AckResultStatus): void; _onTransportCloseRequest(timeoutMs: number): void; _onTransportCloseAck(): void; _onTransportClose(err?: Error): void; private _fireOpen; private _fireClose; private _runFinalizationLoop; private _isCloseRoundtripDone; private _waitForCloseProgress; private _notifyCloseProgress; private _dispatchAckReq; private _dispatchBinaryAckReq; protected _trackAck(promise: Promise): Promise; private _finalizeClose; private _invokeCloseCallback; protected _handleCallbackError(err: unknown): boolean; } declare class ClientBroadcast extends ClientChannel { readonly [CLIENT_BROADCAST_BRAND] = true; private _broadcastListeners; private _broadcastBinaryListeners; static isClientBroadcast(value: unknown): value is ClientBroadcast; publish(data: ChannelData): Promise; subscribe(callback: BroadcastListener): () => void; publishBinary(data: Uint8Array): Promise; subscribeBinary(callback: BroadcastBinaryListener): () => void; _dispatchDataFrame(frame: ChannelDataFrame): void; _onTransportPublish(data: string, wireInfo: WirePublishInfo): void; _onTransportPublishBinary(data: Uint8Array, wireInfo: WirePublishInfo): void; }