pub struct Socket { /* private fields */ }Expand description
Handle used to configure channels and control the managed connection.
The companion Driver owns all protocol and transport state and must be
polled continuously.
Implementations§
Source§impl Socket
impl Socket
Sourcepub fn new(
connector: impl Connector + 'static,
timer: impl Timer + 'static,
options: Options,
) -> (Self, Driver)
pub fn new( connector: impl Connector + 'static, timer: impl Timer + 'static, options: Options, ) -> (Self, Driver)
Creates a socket and driver using the bounded default Phoenix v2 codec.
Sourcepub fn new_with_codec(
connector: impl Connector + 'static,
timer: impl Timer + 'static,
options: Options,
codec: impl Codec + 'static,
) -> (Self, Driver)
pub fn new_with_codec( connector: impl Connector + 'static, timer: impl Timer + 'static, options: Options, codec: impl Codec + 'static, ) -> (Self, Driver)
Creates a socket and driver using an application-provided codec.
Sourcepub fn channel(
&self,
topic: impl Into<String>,
payload_loader: JoinPayloadLoader,
) -> Result<Channel, ClientError>
pub fn channel( &self, topic: impl Into<String>, payload_loader: JoinPayloadLoader, ) -> Result<Channel, ClientError>
Registers one channel topic and its per-attempt join payload loader.
Only one live Channel handle may exist for a topic.
Sourcepub fn events(&self) -> Result<SocketEvents, ClientError>
pub fn events(&self) -> Result<SocketEvents, ClientError>
Creates an independent bounded socket event subscriber.
Sourcepub fn status(&self) -> SocketStatus
pub fn status(&self) -> SocketStatus
Returns the latest socket status.
Sourcepub fn status_changes(&self) -> SocketStatusChanges
pub fn status_changes(&self) -> SocketStatusChanges
Creates a stream of subsequent socket status changes.
Sourcepub async fn connect(&self) -> Result<(), ClientError>
pub async fn connect(&self) -> Result<(), ClientError>
Enables connection attempts and waits until the command is accepted.
Sourcepub async fn disconnect(&self) -> Result<(), ClientError>
pub async fn disconnect(&self) -> Result<(), ClientError>
Disables automatic reconnection and closes the active transport.
Sourcepub async fn disconnect_with(
&self,
code: u16,
reason: impl Into<String>,
) -> Result<(), ClientError>
pub async fn disconnect_with( &self, code: u16, reason: impl Into<String>, ) -> Result<(), ClientError>
Disconnects with an explicit WebSocket close code and reason.
Sourcepub async fn reconnect(&self) -> Result<(), ClientError>
pub async fn reconnect(&self) -> Result<(), ClientError>
Disconnects and immediately enables a new connection cycle.
Sourcepub async fn ping(&self) -> Result<Duration, ClientError>
pub async fn ping(&self) -> Result<Duration, ClientError>
Sends a heartbeat using the default call timeout and returns its RTT.
Sourcepub async fn ping_with_timeout(
&self,
timeout: Duration,
) -> Result<Duration, ClientError>
pub async fn ping_with_timeout( &self, timeout: Duration, ) -> Result<Duration, ClientError>
Sends a heartbeat with an explicit timeout and returns its RTT.
Sourcepub async fn shutdown(&self) -> Result<(), ClientError>
pub async fn shutdown(&self) -> Result<(), ClientError>
Permanently stops the driver and closes the active transport.