pub struct WebSocket { /* private fields */ }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.
Source§impl WebSocket
impl WebSocket
Sourcepub fn has_pending_bytes(&self) -> bool
Available on crate feature io-util only.
pub fn has_pending_bytes(&self) -> bool
io-util only.Returns whether there are pending bytes left after calling AsyncRead::poll_read on this WebSocket.
When calling AsyncRead::poll_read, Stream::poll_next is called
under the hood, and when the received item is too big to fit into the provided buffer, leftover bytes are
stored. These leftover bytes are returned by subsequent calls to AsyncRead::poll_read.
Trait Implementations§
Source§impl AsyncRead for WebSocket
Available on crate feature io-util only.
impl AsyncRead for WebSocket
io-util only.Source§impl AsyncWrite for WebSocket
Available on crate feature io-util only.
impl AsyncWrite for WebSocket
io-util only.Source§fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>>
fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>
buf into the object. Read moreSource§fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Source§impl Sink<Message> for WebSocket
impl Sink<Message> for WebSocket
Source§type Error = WebSocketError
type Error = WebSocketError
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>>
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>
poll_ready which returned Poll::Ready(Ok(())). Read more