Struct wasm_sockets::PollingClient
source · pub struct PollingClient {
pub url: String,
pub event_client: EventClient,
pub status: Rc<RefCell<ConnectionStatus>>,
/* private fields */
}Fields§
§url: StringThe URL this client is connected to
event_client: EventClientThe core EventClient this client is using
status: Rc<RefCell<ConnectionStatus>>The current connection status
Implementations§
source§impl PollingClient
impl PollingClient
sourcepub fn new(url: &str) -> Result<Self, WebSocketError>
pub fn new(url: &str) -> Result<Self, WebSocketError>
Create a new PollingClient and connect to a WebSocket URL
Note: An Ok() from this function does not mean the connection has succeeded.
PollingClient::new("wss://ws.ifelse.io")?;sourcepub fn receive(&mut self) -> Vec<Message>
pub fn receive(&mut self) -> Vec<Message>
Get all new WebSocket messages that were received since this function was last called
println!("New messages: {:#?}", client.receive());sourcepub fn status(&self) -> ConnectionStatus
pub fn status(&self) -> ConnectionStatus
Get the client’s current connection status
println!("Current status: {:#?}", client.status());sourcepub fn send_string(&self, message: &str) -> Result<(), JsValue>
pub fn send_string(&self, message: &str) -> Result<(), JsValue>
Send a text message to the server
client.send_string("Hello server!")?;