pub struct WebSocket { /* private fields */ }
Available on crate feature
websocket
only.Expand description
Wrapper around browser’s WebSocket API.
Implementations§
source§impl WebSocket
impl WebSocket
sourcepub fn open(url: &str) -> Result<Self, JsError>
pub fn open(url: &str) -> Result<Self, JsError>
Establish a WebSocket connection.
This function may error in the following cases:
- The port to which the connection is being attempted is being blocked.
- The URL is invalid.
The error returned is JsError
. See the
MDN Documentation
to learn more.
sourcepub fn open_with_protocol(url: &str, protocol: &str) -> Result<Self, JsError>
pub fn open_with_protocol(url: &str, protocol: &str) -> Result<Self, JsError>
Establish a WebSocket connection.
This function may error in the following cases:
- The port to which the connection is being attempted is being blocked.
- The URL is invalid.
- The specified protocol is not supported
The error returned is JsError
. See the
MDN Documentation
to learn more.
sourcepub fn open_with_protocols<S: AsRef<str> + Serialize>(
url: &str,
protocols: &[S]
) -> Result<Self, JsError>
Available on crate feature json
only.
pub fn open_with_protocols<S: AsRef<str> + Serialize>(
url: &str,
protocols: &[S]
) -> Result<Self, JsError>
json
only.Establish a WebSocket connection.
This function may error in the following cases:
- The port to which the connection is being attempted is being blocked.
- The URL is invalid.
- The specified protocols are not supported
- The protocols cannot be converted to a JSON string list
The error returned is JsError
. See the
MDN Documentation
to learn more.
This function requires json
features because protocols are parsed by serde
into JsValue
.
sourcepub fn close(self, code: Option<u16>, reason: Option<&str>) -> Result<(), JsError>
pub fn close(self, code: Option<u16>, reason: Option<&str>) -> Result<(), JsError>
Closes the websocket.
See the MDN Documentation
to learn about parameters passed to this function and when it can return an Err(_)
sourcepub fn extensions(&self) -> String
pub fn extensions(&self) -> String
The extensions in use.
Trait Implementations§
source§impl Sink<Message> for WebSocket
impl Sink<Message> for WebSocket
§type Error = WebSocketError
type Error = WebSocketError
The type of value produced by the sink when an error occurs.
source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
Attempts to prepare the
Sink
to receive a value. Read moresource§fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: Message) -> Result<(), Self::Error>
Begin the process of sending a value to the sink.
Each call to this function must be preceded by a successful call to
poll_ready
which returned Poll::Ready(Ok(()))
. Read moresource§impl Stream for WebSocket
impl Stream for WebSocket
§type Item = Result<Message, WebSocketError>
type Item = Result<Message, WebSocketError>
Values yielded by the stream.