Worker-safe. The transport half that talks toDocumentation Index
Fetch the complete documentation index at: https://openturn.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
@openturn/server. Most React apps use it indirectly through @openturn/react’s <OpenturnProvider> (with runtime: "multiplayer" bindings) plus useMatch / useRoom. Import it directly when you are writing a non-React UI or a server-side bot.
Install
Creating a client
createHostedClient(options)
HostedClient<TPublicState, TResult>. HostedClientOptions extends HostedConnectionDescriptor — the connection fields live at the top level.
HostedConnectionDescriptor
HostedClientOptions<TPublicState, TResult>
Client API
HostedClient<TPublicState, TResult>
getInitialSnapshot() returns the first MatchSnapshot/PlayerViewSnapshot received after connect — useful for reproducing the exact server state before any batches were applied.
dispatchEvent returns a promise that resolves with the real outcome once the server acks or rejects the action. If the connection drops while the action is in flight, the promise resolves with { ok: false, error: "disconnected" }.
Client state
HostedClientState<TPublicState, TResult>
lastEvent is the most recent raw server message the client processed — handy for debugging or driving telemetry without re-subscribing to every batch.
Rejections are surfaced through the dispatchEvent promise, not through state — handle them at the call site.
HostedConnectionStatus
"idle" | "authorizing" | "connecting" | "connected" | "disconnected" | "error".
HostedSnapshot<TPublicState, TResult>
Union: MatchSnapshot | PlayerViewSnapshot. The server sends the player variant; observer/spectator clients see MatchSnapshot.
HostedDispatchOptions
Optional per-dispatch options: clientActionID, baseRevision.
Transport
HostedSocket / HostedTransport
Abstract over the underlying WebSocket. You can implement your own HostedTransport to route over a non-WebSocket channel (for tests, for integration with another socket layer). The default uses globalThis.WebSocket.
HostedSocketEventMap
The events a socket can raise: open, message, close, error.
Re-exports
For convenience,@openturn/client re-exports the protocol types you typically need:
See also
- Reference: bridge for the iframe↔shell wire that
@openturn/reactuses to resolve the connection descriptor inside a hosted shell. - Reference: server for the producer on the other end.
- Reference: react for the hooks (
useMatch,useRoom) that wrap this client for most apps.