Phoenix.SocketClient.Agent (phoenix_socket_client v0.7.0)
Agent-based state management for WebSocket connection configuration and status.
This module provides centralized state management for socket connections, including configuration parameters, connection status, and custom state values. All state is stored in an Agent process for concurrent access and updates.
The state is managed by the Phoenix.SocketClient.State struct.
Summary
Functions
Returns a specification to start this module under a supervisor.
Checks if the socket is connected.
Retrieves a value from the state by key.
Retrieves the entire state map.
Pops all messages pending to be sent.
Updates the state with a new key-value pair.
Removes a channel from the state.
Starts the Agent with the given configuration options.
Updates the status of a channel.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Checks if the socket is connected.
Retrieves a value from the state by key.
Parameters
pid- The Agent PIDkey- The key to retrieve
Examples
value = Phoenix.SocketClient.Agent.get(pid, :url)
Retrieves the entire state map.
@spec pop_all_to_send(pid()) :: [Phoenix.SocketClient.Message.t()]
Pops all messages pending to be sent.
Updates the state with a new key-value pair.
Parameters
pid- The Agent PIDkey- The key to setvalue- The value to associate with the key
Examples
:ok = Phoenix.SocketClient.Agent.put(pid, :status, :connected)
Removes a channel from the state.
Starts the Agent with the given configuration options.
Parameters
opts- Keyword list or map of configuration options
Examples
{:ok, pid} = Phoenix.SocketClient.Agent.start_link(url: "ws://localhost:4000/socket")
Updates the status of a channel.