Struct Server

Source
pub struct Server<R: Runtime> { /* private fields */ }

Implementations§

Source§

impl<R: Runtime> Server<R>

Source

pub fn new( runtime: R, listen_addr: SocketAddr, public_addr: SocketAddr, ) -> Result<Self, IoError>

Start a new WebRTC data channel server listening on listen_addr and advertising its publicly available address as public_addr.

WebRTC connections must be started via an external communication channel from a browser via the SessionEndpoint, after which a WebRTC data channel can be opened.

Source

pub fn with_ssl_config( runtime: R, listen_addr: SocketAddr, public_addr: SocketAddr, crypto: SslConfig, ) -> Result<Self, IoError>

Start a new WebRTC data channel server with the given SslConfig.

This can be used to share self-signed TLS certificates between different Server instances, which is important in certain browsers (Firefox) when connecting to multiple WebRTC endpoints from the same page.

Source

pub fn session_endpoint(&self) -> SessionEndpoint

Returns a SessionEndpoint which can be used to start new WebRTC sessions.

WebRTC connections must be started via an external communication channel from a browser via the returned SessionEndpoint, and this communication channel will be used to exchange session descriptions in SDP format.

The returned SessionEndpoint will notify this Server of new sessions via a shared async channel. This is done so that the SessionEndpoint is easy to use in a separate server task (such as a hyper HTTP server).

Source

pub fn active_clients(&self) -> usize

The total count of clients in any active state, whether still starting up, fully established, or still shutting down.

Source

pub fn connected_clients(&self) -> impl Iterator<Item = &SocketAddr> + '_

List all the currently fully established client connections.

Source

pub fn is_connected(&self, remote_addr: &SocketAddr) -> bool

Returns true if the client has a completely established WebRTC data channel connection and can send messages back and forth. Returns false for disconnected clients as well as those that are still starting up or are in the process of shutting down.

Source

pub async fn disconnect( &mut self, remote_addr: &SocketAddr, ) -> Result<(), IoError>

Disconect the given client, does nothing if the client is not currently connected.

Source

pub async fn send( &mut self, message: &[u8], message_type: MessageType, remote_addr: &SocketAddr, ) -> Result<(), SendError>

Send the given message to the given remote client, if they are connected.

The given message must be less than MAX_MESSAGE_LEN.

Source

pub async fn recv(&mut self) -> Result<MessageResult<'_>, IoError>

Receive a WebRTC data channel message from any connected client.

Server::recv must be called for proper operation of the server, as it also handles background tasks such as responding to STUN packets and timing out existing sessions.

If the provided buffer is not large enough to hold the received message, the received message will be truncated, and the original length will be returned as part of MessageResult.

Auto Trait Implementations§

§

impl<R> Freeze for Server<R>
where R: Freeze, <R as Runtime>::UdpSocket: Freeze,

§

impl<R> !RefUnwindSafe for Server<R>

§

impl<R> Send for Server<R>
where R: Send, <R as Runtime>::UdpSocket: Send, <R as Runtime>::Timer: Send,

§

impl<R> Sync for Server<R>
where R: Sync, <R as Runtime>::UdpSocket: Sync, <R as Runtime>::Timer: Sync,

§

impl<R> Unpin for Server<R>
where R: Unpin, <R as Runtime>::UdpSocket: Unpin,

§

impl<R> !UnwindSafe for Server<R>

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.
Source§

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

Source§

fn vzip(self) -> V