@flux-control/effect-modbus-rs
    Preparing search index...

    Function wasmWsServerLayer

    • A scoped Layer that starts a browser Modbus server proxied over a WebSocket gateway (experimental upstream surface — browsers can't accept raw TCP connections, so this binds via modbus-gateway or an equivalent WS-to-TCP proxy).

      Unlike the native tcpServerLayer, the WASM server does not start serving on bind() — it requires an explicit, continuously-awaited serve() call to drive its request loop. This layer forks that call into the scope in the background so the returned Layer behaves the same as the native one from the consumer's perspective (no extra step needed).

      Parameters

      • options: WasmTcpServerOptions

        WebSocket gateway URL and unit ID.

      • handlers: ServerHandlers

        Callback functions that handle incoming Modbus requests (same ServerHandlers shape as the native TCP/serial servers).

      Returns Layer<never, ModbusError>

      A Layer that fails with ModbusError on bind failure.

      import { Effect, Layer } from "effect";
      import { wasmWsServerLayer } from "@flux-control/effect-modbus-rs";

      const ServerLive = wasmWsServerLayer(
      { wsUrl: "ws://localhost:8080", unitId: 1 },
      { onReadCoils: (req) => [false, false] },
      );

      Layer.launch(ServerLive).pipe(Effect.runPromise);
      • WasmTcpServerOptions — Options accepted by the upstream WASM WS server.
      • ServerHandlers — Interface for request handler callbacks.