pub struct WebSocketClient { /* private fields */ }Expand description
A WebSocket client for browser / WASM environments.
When the wasm-bindgen feature is active (the default) this struct can be
exported to JavaScript via #[wasm_bindgen].
Implementations§
Source§impl WebSocketClient
impl WebSocketClient
Sourcepub fn new(url: String, config: WebSocketConfig) -> Self
pub fn new(url: String, config: WebSocketConfig) -> Self
Create a new client for url with the given WebSocketConfig.
The connection is not established until connect is called.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true when the underlying socket is open and ready to send.
Source§impl WebSocketClient
impl WebSocketClient
Sourcepub async fn connect(&mut self) -> Result<(), JsValue>
Available on crate feature wasm-bindgen only.
pub async fn connect(&mut self) -> Result<(), JsValue>
wasm-bindgen only.Sourcepub fn send_text(&self, text: &str) -> Result<(), JsValue>
Available on crate feature wasm-bindgen only.
pub fn send_text(&self, text: &str) -> Result<(), JsValue>
wasm-bindgen only.Sourcepub fn send_binary(&self, data: &[u8]) -> Result<(), JsValue>
Available on crate feature wasm-bindgen only.
pub fn send_binary(&self, data: &[u8]) -> Result<(), JsValue>
wasm-bindgen only.Sourcepub fn ready_state(&self) -> u16
Available on crate feature wasm-bindgen only.
pub fn ready_state(&self) -> u16
wasm-bindgen only.Return the underlying WebSocket ready-state code.
| Code | Meaning |
|---|---|
| 0 | CONNECTING |
| 1 | OPEN |
| 2 | CLOSING |
| 3 | CLOSED |
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WebSocketClient
impl RefUnwindSafe for WebSocketClient
impl !Send for WebSocketClient
impl !Sync for WebSocketClient
impl Unpin for WebSocketClient
impl UnsafeUnpin for WebSocketClient
impl UnwindSafe for WebSocketClient
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