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.
impl<'pin> Unpin for WebSocketwhere __WebSocket<'pin>: Unpin,
Auto Trait Implementations§
impl !RefUnwindSafe for WebSocket
impl !Send for WebSocket
impl !Sync for WebSocket
impl !UnwindSafe for WebSocket
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more