libero/rpc

Client-side send machinery.

send is the entry point used by libero-generated client stubs. It takes the WebSocket URL, the module name, the typed ClientMsg variant, and a callback to wrap the server’s response into a Lustre Msg.

The JS FFI (rpc_ffi.mjs) opens the WebSocket lazily on first call and caches the connection. Sends issued before the socket is open are queued and flushed on the open event. Responses are matched to sends by request ID.

Developers don’t usually call this module directly. They import the per-module stubs the libero generator writes into their client package, and those stubs delegate here.

Values

pub fn on_connect(
  handler handler: fn() -> msg,
) -> effect.Effect(msg)

Register a callback that fires whenever the WebSocket connects: the initial connection and every successful reconnect. Use this to load (or reload) state without a separate code path for the first connection. Register early in your app’s init.

pub fn on_disconnect(
  handler handler: fn(String) -> msg,
) -> effect.Effect(msg)

Register a callback that fires when the WebSocket disconnects. The reason is a human-readable string suitable for display. Auto-reconnect kicks in after the disconnect with exponential backoff, so a paired on_connect will fire when service resumes.

pub fn on_push(
  module module: String,
  handler handler: fn(dynamic.Dynamic) -> msg,
) -> effect.Effect(msg)

Handle server-initiated push messages on a module. When the server pushes a typed message without a prior request, the callback wraps it into a Lustre Msg for dispatch.

pub fn send(
  url url: String,
  module module: String,
  msg msg: a,
  on_response on_response: fn(dynamic.Dynamic) -> msg,
) -> effect.Effect(msg)

Send a typed ClientMsg value to the server via WebSocket and deliver the server’s response back to the Lustre update loop.

The on_response callback wraps the decoded response (a Dynamic value reconstructed from ETF) into a Lustre Msg so it can be dispatched through update.

Search Document