Struct PollingClient

Source
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

Source

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")?;
Source

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());
Source

pub fn status(&self) -> ConnectionStatus

Get the client’s current connection status

println!("Current status: {:#?}", client.status());
Source

pub fn send_string(&self, message: &str) -> Result<(), JsValue>

Send a text message to the server

client.send_string("Hello server!")?;
Source

pub fn send_binary(&self, message: Vec<u8>) -> Result<(), JsValue>

Send a binary message to the server

client.send_binary(vec![0x2, 0xF])?;
Source

pub fn close(&self) -> Result<(), JsValue>

Close the connection

client.close()?;
Source

pub fn close_with(&self, code: u16, reason: Option<&str>) -> Result<(), JsValue>

Close the connection with a custom close code and, optionally, a reason string

The reason string must be at most 123 bytes long.

client.close_with(1001, Some("going away"))?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.