Skip to content
Liminal

Client Layer

Client.layerSocket(...) turns a Client protocol into a live Effect layer backed by a WebSocket.

Use it in browser runtimes that connect to a Liminal actor through an HTTP upgrade route.

Define the layer

Provide the client definition, reducers, the socket endpoint, and the platform WebSocket constructor.

 
const  = .({
  : ,
  : "/play",
  : { : "startup" },
  ,
}).(.(.))

layerSocket accepts:

  • client: the Client definition
  • reducers: a reducer table keyed by event tag
  • url: the WebSocket endpoint path, defaulting to "/"
  • protocols: one or more extra WebSocket sub-protocols
  • replay: optional event replay configuration
  • onConnect: optional effect that runs with the hydrated state once audition succeeds

Replay semantics are covered in Events.

layerSocket requires a Socket.WebSocketConstructor in the environment. In browsers, that usually comes from BrowserSocket.layerWebSocketConstructor in @effect/platform-browser.

Use the live client

After providing the layer, calls use Client.fn(...), event streams use Client.events, and hydrated state uses Client.state.

Read Client Calls and Events for those APIs.