pub struct Server<R: Runtime> { /* private fields */ }
Implementations§
Source§impl<R: Runtime> Server<R>
impl<R: Runtime> Server<R>
Sourcepub fn new(
runtime: R,
listen_addr: SocketAddr,
public_addr: SocketAddr,
) -> Result<Self, IoError>
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.
Sourcepub fn with_ssl_config(
runtime: R,
listen_addr: SocketAddr,
public_addr: SocketAddr,
crypto: SslConfig,
) -> Result<Self, IoError>
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.
Sourcepub fn session_endpoint(&self) -> SessionEndpoint
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).
Sourcepub fn active_clients(&self) -> usize
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.
Sourcepub fn connected_clients(&self) -> impl Iterator<Item = &SocketAddr> + '_
pub fn connected_clients(&self) -> impl Iterator<Item = &SocketAddr> + '_
List all the currently fully established client connections.
Sourcepub fn is_connected(&self, remote_addr: &SocketAddr) -> bool
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.
Sourcepub async fn disconnect(
&mut self,
remote_addr: &SocketAddr,
) -> Result<(), IoError>
pub async fn disconnect( &mut self, remote_addr: &SocketAddr, ) -> Result<(), IoError>
Disconect the given client, does nothing if the client is not currently connected.
Sourcepub async fn send(
&mut self,
message: &[u8],
message_type: MessageType,
remote_addr: &SocketAddr,
) -> Result<(), SendError>
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
.
Sourcepub async fn recv(&mut self) -> Result<MessageResult<'_>, IoError>
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
.