pub struct PollingClient {
pub url: String,
pub event_client: EventClient,
pub status: Rc<RefCell<ConnectionStatus>>,
/* private fields */
}
Fields§
§url: String
The URL this client is connected to
event_client: EventClient
The 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!")?;
Auto Trait Implementations§
impl Freeze for PollingClient
impl !RefUnwindSafe for PollingClient
impl !Send for PollingClient
impl !Sync for PollingClient
impl Unpin for PollingClient
impl !UnwindSafe for PollingClient
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