signalk-server
Version:
An implementation of a [Signal K](http://signalk.org) server for boats.
74 lines • 2.29 kB
TypeScript
/**
* Binary Stream Manager
*
* Manages WebSocket streaming of high-frequency binary data from WASM plugins.
* Handles buffering, client connections, and slow consumer disconnection.
*/
import type { WebSocket } from 'ws';
/**
* Security principal representing the authenticated user/device
*/
export interface StreamPrincipal {
identifier: string;
}
/**
* Manages binary data streaming to WebSocket clients
*/
export declare class BinaryStreamManager {
private clients;
private buffers;
/**
* Emit binary data to all clients subscribed to a stream
* Called by WASM plugins via FFI binding
*
* @param streamId - Stream identifier (e.g., "radars/radar-0")
* @param data - Binary data to send
*/
private emitCount;
emitData(streamId: string, data: Buffer): void;
/**
* Add a WebSocket client to a stream
*
* @param streamId - Stream identifier
* @param ws - WebSocket connection
* @param principal - Security principal (authenticated user)
*/
addClient(streamId: string, ws: WebSocket, principal: StreamPrincipal): void;
/**
* Remove a WebSocket client from a stream
*
* @param streamId - Stream identifier
* @param ws - WebSocket connection to remove
*/
removeClient(streamId: string, ws: WebSocket): void;
/**
* Clean up all clients and buffers for a stream
* Called when plugin stops
*
* @param streamId - Stream identifier
*/
cleanupStream(streamId: string): void;
/**
* Send binary data to a specific client, disconnecting slow consumers
*
* @param client - Client to send to
* @param data - Binary data
*/
private sendToClient;
/**
* Get number of buffered frames for a stream (for testing)
*
* @param streamId - Stream identifier
* @returns Number of buffered frames
*/
getBufferSize(streamId: string): number;
/**
* Get number of connected clients for a stream (for testing)
*
* @param streamId - Stream identifier
* @returns Number of connected clients
*/
getClientCount(streamId: string): number;
}
export declare const binaryStreamManager: BinaryStreamManager;
//# sourceMappingURL=binary-stream-manager.d.ts.map