import { EventEmitter } from "events"; import type { ServerId } from "socket.io-adapter"; import { type MetricsRegistry } from "../metrics"; export interface MeshTransportOptions { uid: ServerId; wsPort: number; serverAddress: string; bufferedAmountThreshold?: number; authToken?: string; metrics?: MetricsRegistry; } export declare class MeshTransport extends EventEmitter { readonly uid: ServerId; readonly wsPort: number; readonly serverAddress: string; private readonly bufferedAmountThreshold; private readonly authToken?; private readonly metrics; private wss; /** Established peer connections, keyed by remote uid. */ private peers; /** Inbound sockets that have not yet sent HELLO. */ private pendingInbound; /** Outbound reconnect timers, keyed by remote uid. */ private reconnectTimers; /** Outbound connections currently being established (WS created, not yet open). */ private outboundConnecting; /** Latest known address per uid (from discovery), used for reconnects. */ private knownAddresses; private closed; constructor(opts: MeshTransportOptions); /** * Apply a fresh peer list from discovery. Initiates outbound connections to * peers whose uid is greater than ours (lex-smaller-initiates rule), drops * peers that are no longer present. */ applyPeerList(list: Array<{ serverId: ServerId; address: string; }>): void; /** * Initiate an outbound connection iff our uid is lex-smaller than the peer's. * Otherwise, do nothing and let the peer connect to us. */ private maybeInitiate; private openOutbound; private scheduleReconnect; private onInbound; private handleHello; private wirePeer; private sendHello; /** * Send an already-encoded mesh payload to every connected peer. Drops peers * whose buffered amount exceeds the threshold. The `messageType` is used * purely for metrics labelling. */ sendMeshToAll(payload: Buffer, messageType: number): void; /** * Send an already-encoded mesh payload to one peer. The `messageType` is * used purely for metrics labelling. */ sendMeshToPeer(targetUid: ServerId, payload: Buffer, messageType: number): void; private wrapMesh; /** @returns true if the frame was handed to the socket without error. */ private unicast; private dropPeer; /** Number of currently-connected peers (excludes self). */ peerCount(): number; /** Snapshot of connected peers, for monitoring/tests. */ listPeers(): Array<{ uid: ServerId; address: string; direction: "inbound" | "outbound"; }>; close(): Promise; } //# sourceMappingURL=mesh-transport.d.ts.map