pub struct WebRtcSocket<C: ChannelPlurality = SingleChannel> { /* private fields */ }
Expand description

Contains a set of WebRtcChannels and connection metadata.

Implementations§

source§

impl WebRtcSocket

source

pub fn builder(room_url: impl Into<String>) -> WebRtcSocketBuilder

Creates a new builder for a connection to a given room with a given number of re-connection attempts.

You must add at least one channel with WebRtcSocketBuilder::add_channel before you can build the WebRtcSocket

source

pub fn new_unreliable( room_url: impl Into<String> ) -> (WebRtcSocket<SingleChannel>, MessageLoopFuture)

Creates a WebRtcSocket and the corresponding MessageLoopFuture for a socket with a single unreliable channel.

The returned MessageLoopFuture should be awaited in order for messages to be sent and received.

Please use the WebRtcSocketBuilder to create non-trivial sockets.

source

pub fn new_reliable( room_url: impl Into<String> ) -> (WebRtcSocket<SingleChannel>, MessageLoopFuture)

Creates a WebRtcSocket and the corresponding MessageLoopFuture for a socket with a single reliable channel.

The returned MessageLoopFuture should be awaited in order for messages to be sent and received.

Please use the WebRtcSocketBuilder to create non-trivial sockets.

source§

impl<C: ChannelPlurality> WebRtcSocket<C>

source

pub fn close(&mut self)

Close this socket, disconnecting all channels.

source

pub fn update_peers(&mut self) -> Vec<(PeerId, PeerState)>

Handle peers connecting or disconnecting

Constructed using WebRtcSocketBuilder.

Update the set of peers used by WebRtcSocket::connected_peers and WebRtcSocket::disconnected_peers.

Returns the peers that connected or disconnected since the last time this method was called.

See also: PeerState

§Panics

Will panic if the socket future has been dropped.

WebRtcSocket::try_update_peers is the equivalent method that will instead return a Result.

source

pub fn try_update_peers( &mut self ) -> Result<Vec<(PeerId, PeerState)>, ChannelError>

Similar to WebRtcSocket::update_peers. Will instead return a Result::Err if the socket is closed.

source

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

Returns an iterator of the ids of the connected peers.

Note: You have to call WebRtcSocket::update_peers for this list to be accurate.

See also: WebRtcSocket::disconnected_peers

source

pub fn disconnected_peers(&self) -> impl Iterator<Item = &PeerId>

Returns an iterator of the ids of peers that are no longer connected.

Note: You have to call WebRtcSocket::update_peers for this list to be accurate.

See also: WebRtcSocket::connected_peers

source

pub fn id(&mut self) -> Option<PeerId>

Returns the id of this peer, this may be None if an id has not yet been assigned by the server.

source

pub fn channel(&self, channel: usize) -> &WebRtcChannel

Gets an immutable reference to the WebRtcChannel of a given id.

use matchbox_socket::*;

let (mut socket, message_loop) = WebRtcSocketBuilder::new("wss://example.invalid/")
    .add_channel(ChannelConfig::reliable())
    .add_channel(ChannelConfig::unreliable())
    .build();
let is_closed = socket.channel(0).is_closed();

See also: WebRtcSocket::channel_mut, WebRtcSocket::get_channel, WebRtcSocket::take_channel

§Panics

will panic if the channel cannot be found.

source

pub fn channel_mut(&mut self, channel: usize) -> &mut WebRtcChannel

Gets a mutable reference to the WebRtcChannel of a given id.

use matchbox_socket::*;

let (mut socket, message_loop) = WebRtcSocketBuilder::new("wss://example.invalid/")
    .add_channel(ChannelConfig::reliable())
    .add_channel(ChannelConfig::unreliable())
    .build();
let reliable_channel_messages = socket.channel_mut(0).receive();

See also: WebRtcSocket::channel, WebRtcSocket::get_channel_mut, WebRtcSocket::take_channel

§Panics

will panic if the channel cannot be found.

source

pub fn get_channel( &self, channel: usize ) -> Result<&WebRtcChannel, ChannelError>

Gets an immutable reference to the WebRtcChannel of a given id.

Returns an error if the channel was not found.

use matchbox_socket::*;

let (mut socket, message_loop) = WebRtcSocketBuilder::new("wss://example.invalid/")
    .add_channel(ChannelConfig::reliable())
    .add_channel(ChannelConfig::unreliable())
    .build();
let is_closed = socket.get_channel(0).unwrap().is_closed();

See also: WebRtcSocket::get_channel_mut, WebRtcSocket::take_channel

source

pub fn get_channel_mut( &mut self, channel: usize ) -> Result<&mut WebRtcChannel, ChannelError>

Gets a mutable reference to the WebRtcChannel of a given id.

Returns an error if the channel was not found.

use matchbox_socket::*;

let (mut socket, message_loop) = WebRtcSocketBuilder::new("wss://example.invalid/")
    .add_channel(ChannelConfig::reliable())
    .add_channel(ChannelConfig::unreliable())
    .build();
let reliable_channel_messages = socket.get_channel_mut(0).unwrap().receive();

See also: WebRtcSocket::channel, WebRtcSocket::take_channel

source

pub fn take_channel( &mut self, channel: usize ) -> Result<WebRtcChannel, ChannelError>

Takes the WebRtcChannel of a given id.

use matchbox_socket::*;

let (mut socket, message_loop) = WebRtcSocketBuilder::new("wss://example.invalid/")
    .add_channel(ChannelConfig::reliable())
    .add_channel(ChannelConfig::unreliable())
    .build();
let reliable_channel = socket.take_channel(0).unwrap();
let unreliable_channel = socket.take_channel(1).unwrap();

See also: WebRtcSocket::channel

source§

impl WebRtcSocket<SingleChannel>

source

pub fn receive(&mut self) -> Vec<(PeerId, Packet)>

Call this where you want to handle new received messages.

Messages are removed from the socket when called.

source

pub fn try_send( &mut self, packet: Packet, peer: PeerId ) -> Result<(), SendError>

Try to send a packet to the given peer. An error is propagated if the socket future is dropped. Ok is not a guarantee of delivery.

source

pub fn send(&mut self, packet: Packet, peer: PeerId)

Send a packet to the given peer. There is no guarantee of delivery.

§Panics

Panics if socket future is dropped.

source

pub fn is_closed(&self) -> bool

Returns whether the socket channel is closed

source§

impl WebRtcSocket<MultipleChannels>

source

pub fn any_closed(&self) -> bool

Returns whether any socket channel is closed

source

pub fn all_closed(&self) -> bool

Returns whether all socket channels are closed

Trait Implementations§

source§

impl<C: Debug + ChannelPlurality> Debug for WebRtcSocket<C>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C = SingleChannel> !RefUnwindSafe for WebRtcSocket<C>

§

impl<C> Send for WebRtcSocket<C>

§

impl<C> Sync for WebRtcSocket<C>

§

impl<C> Unpin for WebRtcSocket<C>
where C: Unpin,

§

impl<C = SingleChannel> !UnwindSafe for WebRtcSocket<C>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> CompatExt for T

source§

fn compat(self) -> Compat<T>

Applies the Compat adapter by value. Read more
source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more