[−][src]Struct wasm_sockets::EventClient
Fields
url: Rc<RefCell<String>>
The URL this client is connected to
status: Rc<RefCell<ConnectionStatus>>
The current connection status
on_error: Rc<RefCell<Option<Box<dyn Fn(ErrorEvent)>>>>
The function bound to the on_error event
on_connection: Rc<RefCell<Option<Box<dyn Fn(&EventClient)>>>>
The function bound to the on_connection event
on_message: Rc<RefCell<Option<Box<dyn Fn(&EventClient, Message)>>>>
The function bound to the on_message event
on_close: Rc<RefCell<Option<Box<dyn Fn()>>>>
The function bound to the on_close event
Implementations
impl EventClient
[src]
pub fn new(url: &str) -> Result<Self, WebSocketError>
[src]
Create a new EventClient and connect to a WebSocket URL
Note: An Ok() from this function does not mean the connection has succeeded.
EventClient::new("wss://echo.websocket.org")?;
pub fn set_on_error(&mut self, f: Option<Box<dyn Fn(ErrorEvent)>>)
[src]
Set an on_error event handler. This handler will be run when the client disconnects from the server due to an error. This will overwrite the previous handler. You can set None to disable the on_error handler.
client.set_on_error(Some(Box::new(|error| { panic!("Error: {:#?}", error); })));
pub fn set_on_connection(&mut self, f: Option<Box<dyn Fn(&EventClient)>>)
[src]
Set an on_connection event handler. This handler will be run when the client successfully connects to a server. This will overwrite the previous handler. You can set None to disable the on_connection handler.
client.set_on_connection(Some(Box::new(|client| { info!("Connected"); })));
pub fn set_on_message(&mut self, f: Option<Box<dyn Fn(&EventClient, Message)>>)
[src]
Set an on_message event handler. This handler will be run when the client receives a message from a server. This will overwrite the previous handler. You can set None to disable the on_message handler.
client.set_on_message(Some(Box::new( |c, m| { info!("New Message: {:#?}", m); }, )));
pub fn set_on_close(&mut self, f: Option<Box<dyn Fn()>>)
[src]
Set an on_close event handler. This handler will be run when the client disconnects from a server without an error. This will overwrite the previous handler. You can set None to disable the on_close handler.
client.set_on_close(Some(Box::new(|| { info!("Closed"); })));
pub fn send_string(&self, message: &str) -> Result<(), JsValue>
[src]
Send a text message to the server
client.send_string("Hello server!")?;
pub fn send_binary(&self, message: Vec<u8>) -> Result<(), JsValue>
[src]
Send a binary message to the server
client.send_binary(vec![0x2, 0xF])?;
Auto Trait Implementations
impl !RefUnwindSafe for EventClient
[src]
impl !Send for EventClient
[src]
impl !Sync for EventClient
[src]
impl Unpin for EventClient
[src]
impl !UnwindSafe for EventClient
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,