Skip to main content

Module client

Module client 

Source
Expand description

tokio-tungstenite-backed client for the studio WS worker channel.

Responsibilities:

  • coerce http(s):// API URLs to ws(s):// and append /connect
  • attach Authorization: Bearer <token> and the studio-worker-v1 sub-protocol header to the upgrade
  • map 401 upgrade responses + 4001 close codes to a typed WsClientError::AuthFailed so the runtime can surface a friendly hint
  • serialise WorkerInbound to JSON text frames and parse WorkerOutbound from incoming frames
  • clean shutdown via WsClient::close()
  • emit structured tracing breadcrumbs (target studio_worker::ws::client) at the transport boundary so connect / recv / send failures are never silent. The session discards recv errors in its generic Disconnected(_) arm and fires let _ = sender.send(...) for accept / reject / fail / completeJson, so this layer is the only place those faults can surface. Mirrors the studio_worker::http breadcrumb contract.

Structs§

WsClient
Active worker-side WS session. Cheap to construct, expensive to drop (closes the socket gracefully).
WsReceiver
Single-owner receive half. Owned by the session’s reader task.
WsSender
Cheap-to-clone send half. All senders share one Mutex over the underlying sink so writes from heartbeat / log-shipper / engine dispatch tasks are serialised correctly.

Enums§

WsClientError
Errors surfaced by the client. All variants carry just enough context to log a useful warning + to drive the reconnect policy.

Constants§

SUBPROTOCOL

Functions§

connect
Establish the WebSocket session. Sends the upgrade with the bearer token + sub-protocol header and returns a ready-to-use client.

Type Aliases§

WsResult
Result wrapper for WS-client operations.