pub struct UseWebsocket<In, Out, Enc = JsonEncoding>where
In: 'static,
Out: 'static,
Enc: 'static,{ /* private fields */ }Expand description
The return type of the use_websocket hook.
See the use_websocket documentation for more details.
This handle provides methods to send and receive messages, check the connection status, and wait for the connection to be established.
Implementations§
Source§impl<In, Out, E> UseWebsocket<In, Out, E>
impl<In, Out, E> UseWebsocket<In, Out, E>
Sourcepub async fn connect(&self) -> WebsocketState
pub async fn connect(&self) -> WebsocketState
Wait for the connection to be established. This guarantees that subsequent calls to methods like
.try_recv() will not fail due to the connection not being ready.
Sourcepub fn connecting(&self) -> bool
pub fn connecting(&self) -> bool
Returns true if the WebSocket is currently connecting.
This can be useful to present a loading state to the user while the connection is being established.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true if the WebSocket is currently shut down and cannot be used to send or receive messages.
Sourcepub fn status(&self) -> ReadSignal<WebsocketState>
pub fn status(&self) -> ReadSignal<WebsocketState>
Get the current status of the WebSocket connection.
Sourcepub async fn send_raw(&self, msg: Message) -> Result<(), WebsocketError>
pub async fn send_raw(&self, msg: Message) -> Result<(), WebsocketError>
Send a raw message over the WebSocket connection
To send a message with a particular type, see the .send() method instead.
Sourcepub async fn recv_raw(&mut self) -> Result<Message, WebsocketError>
pub async fn recv_raw(&mut self) -> Result<Message, WebsocketError>
Receive a raw message from the WebSocket connection
To receive a message with a particular type, see the .recv() method instead.
pub async fn send(&self, msg: In) -> Result<(), WebsocketError>
Sourcepub async fn recv(&mut self) -> Result<Out, WebsocketError>where
Out: DeserializeOwned,
E: Encoding,
pub async fn recv(&mut self) -> Result<Out, WebsocketError>where
Out: DeserializeOwned,
E: Encoding,
Receive the next message from the WebSocket connection, deserialized into the Out type.
If the connection is still opening, this will wait until the connection is established. If the connection fails to open or is killed while waiting, an error will be returned.
This method returns an error if the connection is closed since we assume closed connections are a “failure”.