Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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.

import { BrowserSocket } from "@effect/platform-browser"
import { Layer } from "effect"
import { Client } from "liminal"
 
import { TicTacToeClient } from "./TicTacToeClient.ts"
import * as reducers from "./reducers.ts"
 
const TicTacToeClientLive = Client.layerSocket({
  client: TicTacToeClient,
  url: "/play",
  replay: { mode: "startup" },
  reducers,
}).pipe(Layer.provide(BrowserSocket.layerWebSocketConstructor))

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.