Skip to main content

WebSocketBridge

Struct WebSocketBridge 

Source
pub struct WebSocketBridge { /* private fields */ }
Expand description

Accepts panels, broadcasts events to them, and collects their commands.

Built on the engine’s thread and used from there; the server runs elsewhere and shares nothing but data.

Implementations§

Source§

impl WebSocketBridge

Source

pub fn bind(address: &str) -> Result<Self, Error>

Binds a listener and starts serving in the background.

The socket is bound synchronously, so a port already in use is reported to the caller that can do something about it rather than disappearing into a thread.

§Errors

Error::Transport if the address cannot be bound, or Error::ThreadNotStarted if the server thread cannot be created.

Source

pub fn bind_with_page( address: &str, page: Option<String>, ) -> Result<Self, Error>

Binds, and also serves page to a browser asking for the root.

One address for both, so opening the host’s address is the whole setup and the panel need not be found on disk. It also gives the page and the socket the same origin, which is what makes an origin check meaningful; a page loaded from a file has an origin of null.

A browser request never consumes a connection slot or a subscription: it is answered and closed before either is taken.

§Errors

Error::Transport if the address cannot be bound, or Error::ThreadNotStarted if the server thread will not start.

Source

pub fn bind_with(address: &str, options: Options) -> Result<Self, Error>

Binds with everything the host wants to decide up front.

The way to reach the origin allowlist. See Options.

§Errors

Error::Transport if the address cannot be bound, or Error::ThreadNotStarted if the server thread will not start.

Source

pub const fn address(&self) -> SocketAddr

The address actually bound, which resolves a port of 0.

Source

pub fn client_count(&self) -> usize

How many panels are connected.

Source

pub fn publish(&self, event: &MessageEvent)

Sends an event to every connected panel.

Never blocks and never fails for want of an audience: with nobody connected the event is dropped, because a station must not stop testing because no one is watching.

Source

pub fn reply(&self, request: &Request, response: &Response)

Answers one request, addressed to the panel that made it.

Source

pub fn next_command(&self) -> Option<Request>

Takes the next command, if one is waiting.

Non-blocking on purpose. The engine thread has its own queue to pump and cannot afford to wait here; it drains what has arrived and gets on with the run.

Trait Implementations§

Source§

impl Debug for WebSocketBridge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for WebSocketBridge

Source§

fn drop(&mut self)

Closes the sessions rather than abandoning them.

The server runs on its own thread and does not stop when this type is dropped. Without telling the sessions to close, a panel is left holding a socket to a host that has gone, blocked on a read that never returns.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V