/** * Server-side core of the WebSocket serial bridge — deliberately free of any * `serialport`/`ws`/Node imports so it is unit-testable with fakes. The thin * `bin/expose-serial.js` wrapper supplies the real `serialport` port and `ws` * socket objects and calls {@link attachBridge} for each connection. */ import { type PortInfo } from './protocol'; /** The subset of a `serialport` SerialPort that the bridge uses (callback API). */ export interface SerialLike { write(data: Uint8Array, cb?: (err?: Error | null) => void): void; set(opts: { dtr?: boolean; rts?: boolean; brk?: boolean; }, cb?: (err?: Error | null) => void): void; get(cb: (err: Error | null, signals?: { cts?: boolean; dsr?: boolean; dcd?: boolean; ri?: boolean; }) => void): void; update(opts: { baudRate: number; }, cb?: (err?: Error | null) => void): void; flush(cb?: (err?: Error | null) => void): void; drain(cb?: (err?: Error | null) => void): void; close(cb?: (err?: Error | null) => void): void; on(event: 'data', listener: (data: Uint8Array) => void): void; on(event: 'error', listener: (err: Error) => void): void; on(event: 'open' | 'close', listener: () => void): void; removeListener(event: string, listener: (...args: never[]) => void): void; } /** The subset of a `ws` WebSocket that the bridge uses. */ export interface WsLike { send(data: string | Uint8Array): void; on(event: 'message', listener: (data: unknown, isBinary: boolean) => void): void; on(event: 'close', listener: () => void): void; on(event: 'error', listener: (err: Error) => void): void; } export type BridgeOptions = { /** Whether the port forwards serial→client data before `startReading`. */ readingByDefault?: boolean; /** Optional logger for diagnostics. */ log?: (message: string) => void; /** Optional static metadata or callback exposed via `getPortInfo`. */ portInfo?: PortInfo | (() => PortInfo | null | undefined); }; /** * Wire a single WebSocket connection to a single serial port: binary frames are * piped both ways, JSON control frames invoke the corresponding serial method * and get a response, and the port's data/error/close are surfaced as frames. * Returns a teardown function that detaches the serial listeners. */ export declare function attachBridge(serial: SerialLike, ws: WsLike, options?: BridgeOptions): () => void; export type BridgeArgs = { port?: string; baudRate: number; wsPort: number; host: string; allowRemote: boolean; help: boolean; }; /** Parse `expose-serial` CLI args + env into a normalised options object. */ export declare function parseBridgeArgs(argv: readonly string[], env?: Record): BridgeArgs; export declare const USAGE = "expose-serial-websocket \u2014 bridge a serial port to a WebSocket\n\nUsage:\n expose-serial-websocket --port [--baudrate 115200] [--ws-port 8080]\n [--host 127.0.0.1] [--allow-remote]\n\nOptions:\n -p, --port Serial device (e.g. /dev/ttyUSB0, COM3) [env SERIAL_PORT]\n -b, --baudrate Baud rate (default 115200) [env BAUD_RATE]\n -w, --ws-port WebSocket port (default 8080) [env WS_PORT]\n --host Listen address (default 127.0.0.1) [env HOST]\n --allow-remote Bind 0.0.0.0 (exposes the port to the network!)\n -h, --help Show this help\n\nConnect from the app with:\n new Serial(new WebSocketSerialTransport('ws://localhost:8080'))\n"; //# sourceMappingURL=bridge.d.ts.map