Phoenix Channel transport over WebSocket.
Implements the Phoenix Channel V2 wire protocol:
[join_ref, ref, topic, event, payload]Connection Flow
- Connects to
{node_url}?api_key={key}&vsn=2.0.0 - Sends
phx_joinwith registered protocols and DID spec - Fires heartbeat every 30 seconds
- Auto-reconnects with exponential backoff (1s → 30s) on disconnect
Callbacks
on_message/1— called with the decoded payload of inbound"message"eventson_disconnect/1— called with the error reason on disconnecton_reconnect/0— called after successful reconnection
Not meant to be used directly; interact through Layr8.Client.
Summary
Functions
Returns the DID assigned by the cloud-node (for ephemeral identities).
Returns the capabilities advertised by the cloud-node on join.
Returns a specification to start this module under a supervisor.
Closes the WebSocket connection.
Connects to the cloud-node WebSocket and joins the Phoenix channel.
Sends an acknowledgment for a list of message IDs.
Sends a message event fire-and-forget (no reply tracking).
Sends a message event and waits for a server acknowledgment.
Starts the Channel GenServer.
Types
@type callbacks() :: %{ on_message: on_message_fn(), on_disconnect: on_disconnect_fn() | nil, on_reconnect: on_reconnect_fn() | nil }
@type on_reconnect_fn() :: (-> any())
Functions
Returns the DID assigned by the cloud-node (for ephemeral identities).
Returns the capabilities advertised by the cloud-node on join.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec close(pid()) :: :ok
Closes the WebSocket connection.
Connects to the cloud-node WebSocket and joins the Phoenix channel.
Blocks until the join is acknowledged or returns {:error, reason}.
Sends an acknowledgment for a list of message IDs.
Used in legacy mode (cloud nodes without reply protocol).
Sends a message event fire-and-forget (no reply tracking).
Sends a message event and waits for a server acknowledgment.
Returns {:ok, reply} where reply is %{status: String.t(), reason: String.t()},
or {:error, reason} on timeout or disconnect.
@spec start_link(start_opts()) :: GenServer.on_start()
Starts the Channel GenServer.
Options
:ws_url— WebSocket URL:api_key— API key for the?api_key=query parameter:agent_did— agent DID (used as the Phoenix topicplugins:{did}):callbacks— map of callback functions (see module doc)