web-serial-rxjs API Documentation
    Preparing search index...

    Module index

    web-serial-rxjs

    A TypeScript library that wraps the Web Serial API with a minimal, RxJS-based session surface.

    The public API exposes a single, session-oriented surface so that apps (Angular, Vue, React, Svelte, vanilla JS/TS) can drive their UI from state$ (canonical lifecycle discriminated union) + errors$ (error event channel) + receive$ + terminalText$ + lines$ without rebuilding state, read loops, or write queues. Derive convenience booleans from state$ narrowing.

    Separates Web Serial API availability (what the browser implements) from this project's official support policy (what we test and guarantee).

    Where navigator.serial exists, this library can use the Web Serial API. Typical desktop availability: Chrome 89+, Edge 89+, Opera 75+, Firefox 151+. Safari does not currently implement the Web Serial API. Many mobile browsers also lack navigator.serial; when missing, isWebSerialSupported returns false.

    Official support covers the desktop browsers listed above. Mobile browsers are untested and out of official support. Untested does not mean the library rejects them — behavior is not guaranteed.

    Synchronous feature detection (navigator.serial present) before SerialSession.connect$. It is not a compatibility or official-support guarantee. Secure context is a separate requirement.

    import { filter } from 'rxjs';
    import {
    createSerialSession,
    isWebSerialSupported,
    isConnectedSessionState,
    SerialSessionStatus,
    SerialErrorCode,
    } from '@gurezo/web-serial-rxjs';

    const session = createSerialSession({ baudRate: 115200 });

    if (!isWebSerialSupported()) {
    console.error('Web Serial API is not supported in this browser');
    } else {
    session.state$.subscribe((state) => {
    if (state.status === SerialSessionStatus.Connected) {
    console.log('port:', state.portInfo);
    }
    });
    session.state$
    .pipe(filter(isConnectedSessionState))
    .subscribe((state) => {
    console.log('port:', state.portInfo);
    });
    session.receive$.subscribe((chunk) => console.log('rx:', chunk));
    session.errors$.subscribe((error) => {
    if (error.is(SerialErrorCode.READ_FAILED)) {
    console.error(error.context.cause);
    }
    });

    session.connect$().subscribe();
    session.send$('hello\r\n').subscribe();
    }
    SerialError
    ConnectedSessionState
    ConnectingSessionState
    DisconnectingSessionState
    DisposedSessionState
    ErrorSessionState
    IdleSessionState
    LineBufferOptions
    SerialErrorContextMap
    SerialSession
    SerialSessionFeatureOptions
    SerialSessionOptions
    TerminalBuffer
    TerminalBufferOptions
    UnsupportedSessionState
    ResolvedSerialSessionOptions
    SerialConnectionOptions
    SerialErrorCauseContext
    SerialErrorCode
    SerialPayload
    SerialSessionState
    SerialSessionStatus
    ValidationErrorConstraint
    ValidationErrorContext
    DEFAULT_LINE_BUFFER_OPTIONS
    DEFAULT_TERMINAL_BUFFER_OPTIONS
    SerialErrorCode
    SerialSessionStatus
    createSerialSession
    createTerminalBuffer
    isConnectedSessionState
    isWebSerialSupported
    resolveSerialSessionOptions