pub struct Client { /* private fields */ }
Expand description
A Client
manages the underlying WebSocket connection used to talk to Phoenix.
It acts as the primary interface (along with Channel
) for working with Phoenix Channels.
When a client is created, it is disconnected, and must be explicitly connected via Self::connect
.
Once connected, a worker task is spawned that acts as the broker for messages being sent or
received over the socket.
Once connected, the more useful Channel
instance can be obtained via Self::join
. Most functionality
related to channels is exposed there.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: Config) -> Result<Self, ClientError>
pub fn new(config: Config) -> Result<Self, ClientError>
Creates a new, disconnected Phoenix Channels client
Sourcepub fn config_mut(&mut self) -> &mut Config
pub fn config_mut(&mut self) -> &mut Config
Gets a mutable reference to this client’s configuration
Sourcepub async fn connect(&mut self) -> Result<(), ClientError>
pub async fn connect(&mut self) -> Result<(), ClientError>
Connects this client to the configured Phoenix Channels endpoint
This function must be called before using the client to join channels, etc.
A join handle to the socket worker is returned, we can use this to wait until the worker exits to ensure graceful termination. Otherwise, when the handle is dropped, it detaches the worker from the task runtime (though it will continue to run in the background)
Sourcepub async fn disconnect(&mut self) -> Result<(), ClientError>
pub async fn disconnect(&mut self) -> Result<(), ClientError>
Disconnect the client, regardless of any outstanding channel references
Connected channels will return ChannelError::Closed
when next used.
New channels will need to be obtained from this client after connect
is
called again.