UNPKG

node-labstreaminglayer

Version:
141 lines 5.06 kB
/** * @fileoverview StreamOutlet class for broadcasting data streams. * * This module provides the StreamOutlet class which broadcasts data samples * to the network. Outlets are the data sources in LSL - they push samples * that can be received by any number of StreamInlets. * * @module outlet * @see {@link https://labstreaminglayer.readthedocs.io/} - LSL Documentation */ import { StreamInfo } from './streamInfo.js'; /** * A stream outlet broadcasts data samples to the network. * * StreamOutlet is the data source in LSL. It pushes samples containing * measurement data or event markers to the network where they can be * received by any number of StreamInlets. * * Key features: * - Automatic buffering with configurable size * - Support for all LSL data types * - Optional pushthrough mode for low latency * - Chunk transmission for efficiency * - Consumer detection * * @example * ```typescript * // Create an EEG data outlet * const info = new StreamInfo('BioSemi', 'EEG', 32, 256, 'float32'); * const outlet = new StreamOutlet(info); * * // Push samples at regular intervals * setInterval(() => { * const sample = generateEEGData(); // 32 channels * outlet.pushSample(sample); * }, 1000/256); // 256 Hz * ``` * * @class */ export declare class StreamOutlet { /** Pointer to the underlying LSL outlet C object */ private obj; /** Numeric channel format constant for type checking */ private channelFormat; /** Number of channels for validation */ private channelCount; /** Function pointer for pushing single samples */ private doPushSample; /** Function pointer for pushing chunks (single timestamp) */ private doPushChunk; /** Function pointer for pushing chunks (multiple timestamps) */ private doPushChunkN; /** * Creates a new StreamOutlet. * * @param {StreamInfo} info - Stream metadata object describing the stream * @param {number} chunkSize - Preferred chunk size for transmission (0 = no chunking) * Samples are buffered until this size is reached. * @param {number} maxBuffered - Maximum amount of data to buffer in seconds (default: 360) * Older samples are dropped if buffer is full. * * @throws {Error} If outlet creation fails or channel format is unsupported * * @example * ```typescript * const outlet = new StreamOutlet(info, 0, 360); // No chunking, 6 min buffer * const outlet = new StreamOutlet(info, 128, 10); // 128-sample chunks, 10s buffer * ``` */ constructor(info: StreamInfo, chunkSize?: number, maxBuffered?: number); /** * Destroy the outlet and free resources. * Called automatically when the object is garbage collected. */ destroy(): void; /** * Push a single sample into the outlet. * @param x Array of channel values * @param timestamp Optional timestamp (0 = use current LSL time) * @param pushthrough Whether to push through network buffers */ pushSample(x: any[], timestamp?: number, pushthrough?: boolean): void; /** * Push a chunk of samples into the outlet. * @param x 2D array of samples or flattened array * @param timestamp Single timestamp or array of timestamps * @param pushthrough Whether to push through network buffers */ pushChunk(x: any[] | any[][], timestamp?: number | number[], pushthrough?: boolean): void; /** * Check if any inlets are currently connected to this outlet. * * @returns {boolean} True if at least one inlet is connected * * @example * ```typescript * if (outlet.haveConsumers()) { * // Someone is listening, send data * outlet.pushSample(data); * } * ``` */ haveConsumers(): boolean; /** * Wait for inlets to connect to this outlet. * * Blocks until at least one inlet subscribes or timeout expires. * Useful for ensuring data isn't lost at stream startup. * * @param {number} timeout - Maximum time to wait in seconds * @returns {boolean} True if a consumer connected, false if timeout * * @example * ```typescript * console.log('Waiting for receivers...'); * if (outlet.waitForConsumers(5.0)) { * console.log('Connected! Starting data transmission.'); * } else { * console.log('No receivers found after 5 seconds.'); * } * ``` */ waitForConsumers(timeout: number): boolean; /** * Get the StreamInfo object associated with this outlet. * * Returns a new StreamInfo object with updated metadata including * hostname, session ID, and creation time. * * @returns {StreamInfo} Updated stream information * * @example * ```typescript * const info = outlet.getInfo(); * console.log(`Stream ${info.name()} created at ${info.createdAt()}`); * ``` */ getInfo(): StreamInfo; } //# sourceMappingURL=outlet.d.ts.map