webserial-core
Version:
A strongly-typed, event-driven, abstract TypeScript library for the Web Serial API with custom parsers, command queue, handshake validation, and auto-reconnect.
28 lines (27 loc) • 1.02 kB
TypeScript
import { SerialParser } from '../types/index.js';
export interface InterByteTimeoutOptions {
/** Period of silence in milliseconds after which buffered data is emitted. */
interval: number;
/** Maximum number of bytes to buffer before forcing an emit. Defaults to 65536. */
maxBufferSize?: number;
}
/**
* Creates an inter-byte timeout parser that buffers incoming bytes and emits
* the accumulated data after a silence period of at least `interval` ms, or
* when the buffer reaches `maxBufferSize`.
*
* @param options - Configuration options.
* @returns A {@link SerialParser} that emits `Uint8Array` values.
*
* @example
* ```ts
* import { AbstractSerialDevice, interByteTimeout } from 'webserial-core';
*
* class MyDevice extends AbstractSerialDevice<Uint8Array> {
* constructor() {
* super({ baudRate: 9600, parser: interByteTimeout({ interval: 30 }) });
* }
* }
* ```
*/
export declare function interByteTimeout(options: InterByteTimeoutOptions): SerialParser<Uint8Array>;