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

    Function createSerialSession

    • Create a v2 SerialSession.

      This release wires the internal read pump (#202) and the internal send queue (#203) into the session so that connect$, disconnect$, receive$, and send$ all operate end-to-end. Error handling is centralised through a single reportError helper (#204) so every failure path normalises through normalizeSerialError and emits on the one errors$ channel.

      Key behaviors:

      • isBrowserSupported() returns whether navigator.serial is available.
      • state$ replays the current lifecycle state driven by SessionStateMachine.
      • connect$() opens a user-selected port, starts the internal read pump, and transitions idle -> connecting -> connected.
      • disconnect$() stops the read pump, closes the port, and transitions connected -> disconnecting -> idle.
      • receive$ emits UTF-8 decoded text chunks pushed by the pump. It is not subscription-lazy - the pump is started by connect$ and decoded text is multicast to all subscribers; late subscribers see only new data.
      • lines$ emits the same decoded stream split into line-terminated segments (\n, \r\n); a trailing line without a terminator is buffered. It is also not subscription-lazy relative to the pump.
      • send$ enqueues each payload on an internal FIFO queue so concurrent subscribers are written to the port in call order. String payloads are UTF-8 encoded through a shared TextEncoder.
      • errors$ multiplexes every SerialError produced by the session. Connect / read / close failures are treated as fatal and also drive state$ to 'error'; write failures are non-fatal and do not mutate state$ because a real connection loss will be observed by the read pump on the next tick anyway.

      Parameters

      • Optionaloptions: SerialSessionOptions

        Session options. Only filters is consulted by connect$ today (forwarded to navigator.serial.requestPort); the remaining fields are passed to port.open using defaults when omitted.

      Returns SerialSession

      A SerialSession instance.