export { Channel, ServerChannel, SERVER_CHANNEL_BRAND }; export { ChannelClosedError, ChannelOverflowError } from '../channel-errors.js'; export { NetworkError } from '../../shared/NetworkError.js'; declare const SERVER_CHANNEL_BRAND: unique symbol; import type { ChannelBase, ChannelShield, ChannelAck, ClientChannel, ChannelCloseCallback, ChannelCloseOptions, ChannelCloseResult, ChannelData, ChannelListener, ChannelBinaryListener } from '../channel.js'; import type { TELEFUNC_SHIELDS } from '../../node/shared/transformer/generateShield/shield-key.js'; import type { IndexedPeer } from './IndexedPeer.js'; import type { ShieldValidators } from '../../node/server/shield.js'; import { FlowControl } from '../flow-control/flow-control.js'; import { ServerChannelBuffer } from './ServerChannelBuffer.js'; import { ReplayBuffer } from '../replay-buffer.js'; import type { AckResultStatus, ChannelCtrlFrame, ChannelDataFrame, ChannelFrame } from '../shared-ws.js'; declare class ServerChannel implements Channel { readonly [SERVER_CHANNEL_BRAND] = true; /** @see ChannelShield in ../channel.ts — `data` validates incoming C2S, `ack` validates ack of own S2C sends. */ readonly [TELEFUNC_SHIELDS]: { data: ChannelData; ack: ChannelAck; }; readonly id: string; readonly ack: boolean; get client(): ClientChannel; static isServerChannel(value: unknown): value is ServerChannel; protected _isClosed: boolean; /** @internal */ _didShutdown: boolean; private _didRegister; protected _peer: IndexedPeer | null; private _listeners; private _binaryListeners; protected _prePeerBuffer: ServerChannelBuffer>; protected _pendingAcks: Map) => void; reject: (err: Error) => void; }>; private _closeCallbacks; private _openCallbacks; private _closeError; private _didFireClose; private _didFireOpen; private _closePromise; private _closeDeadline; private _closeWaiters; private _didReceiveCloseAck; private _awaitingCloseAck; private _pendingCloseCallbacks; protected _inflightAcks: number; private _ttlTimer; /** 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`. */ protected _flow: FlowControl; private _reconnectTimer; private _responseAbort; private _pendingAckRes; private _shutdownCallback; private _pendingCloseAck; /** Buffer of outgoing wire frames, used to replay missed frames on reconnect. * Allocated in `_registerChannel`; disposed in `_shutdown`. Null only between * construction and registration (no peer can attach before registration). */ /** @internal */ _replayBuffer: ReplayBuffer | null; /** Highest client→server seq the channel has received and dispatched. Used for * frame deduplication and reported back to the client in `CtrlReconciled.open[].lastSeq`. */ /** @internal */ _lastClientSeq: number; /** Shield validators keyed by name (see `ChannelShield` in ../channel.ts). * - `data`: validates incoming client data (_onPeerMessage / _dispatchAckReq) * - `ack`: validates client ack responses (_onPeerAckRes) * Each returns `true` on success or an error string — callers decide the action (drop, throw). */ _validators: ShieldValidators; constructor({ ack, id, bufferLimit, }?: { ack?: boolean; id?: string; bufferLimit?: number; }); get isClosed(): boolean; /** @internal — Register a one-shot callback that fires when the transport shuts down. * Replaces any previously registered callback (does not accumulate). */ _onShutdown(cb: () => void): void; 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; listen(callback: ChannelListener): () => void; listenBinary(callback: ChannelBinaryListener): () => void; onClose(callback: ChannelCloseCallback): void; onOpen(callback: () => void): void; _setResponseAbort(abortResponse: (abortValue?: unknown) => void): void; abort(): void; abort(abortValue: unknown, message?: string): void; close(opts?: ChannelCloseOptions): Promise; /** @internal — Prepare channel state so the mux can register it. Called by * `ChannelMux.registerChannel`; external code should call that instead. */ _registerChannel(): void; _attachPeer(peer: IndexedPeer): void; /** @internal — Entry point from the mux for an incoming wire frame. Handles ctrl routing, * client→server seq dedup, and delegation to `_dispatchDataFrame`. */ _dispatchFrame(frame: ChannelFrame): void; /** @internal — Tag-keyed data-frame switch. Subclasses (`ServerBroadcast`) override * to handle their extra tags and fall back to `super` for the common cases. */ protected _dispatchDataFrame(frame: ChannelDataFrame): void; /** @internal — Per-channel ctrl-message switch. Connection-level ctrls (ping, * reconcile, fin) never reach here — the mux's `handleFrame` handles them. */ _dispatchCtrl(frame: ChannelCtrlFrame): void; _onPeerMessage(text: string, bytes: number): void; _onPeerAckReqMessage(text: string, seq: number): Promise; _onPeerBinaryAckReqMessage(data: Uint8Array, seq: number): Promise; _onPeerBinaryMessage(data: Uint8Array): void; _onPeerAckRes(ackedSeq: number, resultText: string, status?: AckResultStatus): void; _onPeerCloseRequest(timeoutMs: number): void; _onPeerCloseAck(): void; _onPeerDisconnect(reconnectTimeout: number): void; _onPeerRecoveryFailure(): void; _onPeerClose(): void; /** Send an ack response, buffering it if the peer is currently disconnected. */ protected _sendAckRes(ackedSeq: number, result: string, status?: AckResultStatus): void; private _startClose; private _runFinalizationLoop; private _isCloseRoundtripDone; private _waitForCloseProgress; private _notifyCloseProgress; private _dispatchAckReq; private _dispatchBinaryAckReq; protected _trackAck(promise: Promise): Promise; protected _shutdown(err?: Error): void; private _fireClose; private _invokeCloseCallback; private _fireOpen; protected _handleCallbackError(err: unknown): boolean; private _clearTimer; } /** Server-side channel. `ClientToServer` = messages the server receives; `ServerToClient` = messages the server sends. */ type Channel = ChannelBase & ChannelShield & { /** The client-side end of the channel — return this from a telefunction. */ readonly client: ClientChannel; }; declare const Channel: { new (opts?: { ack?: false; }): Channel; new (opts: { ack: true; }): Channel; new (opts?: { ack?: boolean; }): Channel; };