T3.WebSocket (T3 v0.3.0)

Copy Markdown View Source

Raw WebSocket transport for T3's non-Effect media/device routes.

Text and binary frames are delivered unchanged as {:t3_web_socket, socket, delivery_ref, {:text | :binary, bytes}}. Call ack/2 after consuming each delivery. This acknowledgement only releases the local backlog; route-specific acknowledgements (for example preview's JSON {"type":"ack"}) must also be sent to the server. See T3.WebSocket.Routes.

Credentials are explicit: :token adds Authorization, :ticket adds wsTicket, and :headers/:query admit other route-specific inputs. No authentication is inferred from an MCP client. WSS is required except on loopback. A credential is sent only to the configured URL; redirects are never followed.

Options: :owner (defaults to starter), :connect_timeout (10 seconds), :idle_timeout (60 seconds; :infinity allowed), :lifetime (:infinity), :max_message_bytes (16 MiB), :max_pending_frames (16), and :max_pending_bytes (32 MiB). Exceeding an input/backlog bound closes the connection and reports an error rather than accumulating unbounded mail. Ping frames receive automatic pongs. Owner death closes the connection. Server-close messages are {:t3_web_socket, socket, {:closed, reason}}; failures additionally send {:t3_web_socket, socket, {:error, %T3.Error{}}}.

Summary

Functions

Release a consumed delivery from the local backlog; sends nothing to the server.

Returns a specification to start this module under a supervisor.

Close the socket and release resources. Safe to call repeatedly.

Send literal binary bytes, such as a route-specific control/video payload.

Encode a value as JSON and send it in a text frame.

Send a literal text frame. No JSON encoding or protocol envelope is added.

Functions

ack(socket, delivery_ref)

Release a consumed delivery from the local backlog; sends nothing to the server.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(socket)

Close the socket and release resources. Safe to call repeatedly.

ping(socket, data \\ "")

pong(socket, data \\ "")

send_binary(socket, data)

Send literal binary bytes, such as a route-specific control/video payload.

send_json(socket, value)

Encode a value as JSON and send it in a text frame.

send_text(socket, data)

Send a literal text frame. No JSON encoding or protocol envelope is added.

start_link(opts)