PeerConnection

Struct PeerConnection 

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

The RTCPeerConnection interface represents a WebRTC connection between the local computer and a remote peer. It provides methods to connect to a remote peer, maintain and monitor the connection, and close the connection once it’s no longer needed.

Implementations§

Source§

impl PeerConnection

Source

pub fn new(config: Configuration) -> Result<Self, Error>

Returns a new RTCPeerConnection, representing a connection between the local device and a remote peer.

Source

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

Closes the current peer connection.

Source

pub async fn set_local_description(&self, type_: SdpType) -> Result<(), Error>

The RTCPeerConnection method setLocalDescription() changes the local description associated with the connection. This description specifies the properties of the local end of the connection, including the media format. The method takes a single parameter—the session description—and it returns a Promise which is fulfilled once the description has been changed, asynchronously.

In datachannel-facade, this will also perform createOffer/createAnswer behind the scenes. The resulting description can be retrieved by calling PeerConnection::local_description.
Source

pub async fn set_remote_description( &self, description: &Description, ) -> Result<(), Error>

The RTCPeerConnection method setRemoteDescription() sets the specified session description as the remote peer’s current offer or answer. The description specifies the properties of the remote end of the connection, including the media format. The method takes a single parameter—the session description—and it returns a Promise which is fulfilled once the description has been changed, asynchronously.

This is typically called after receiving an offer or answer from another peer over the signaling server. Keep in mind that if setRemoteDescription() is called while a connection is already in place, it means renegotiation is underway (possibly to adapt to changing network conditions).

Source

pub fn local_description(&self) -> Result<Option<Description>, Error>

The read-only property RTCPeerConnection.localDescription returns an RTCSessionDescription describing the session for the local end of the connection. If it has not yet been set, this is null.

Source

pub fn remote_description(&self) -> Result<Option<Description>, Error>

The read-only property RTCPeerConnection.remoteDescription returns a RTCSessionDescription describing the session (which includes configuration and media information) for the remote end of the connection. If this hasn’t been set yet, this is null.

The returned value typically reflects a remote description which has been received over the signaling server (as either an offer or an answer) and then put into effect by your code calling RTCPeerConnection.setRemoteDescription() in response.

Source

pub async fn add_ice_candidate(&self, cand: Option<&str>) -> Result<(), Error>

Adds a new remote candidate to the RTCPeerConnection’s remote description, which describes the state of the remote end of the connection.

Source

pub fn set_on_ice_candidate( &mut self, cb: Option<impl Fn(Option<&str>) + Send + Sync + 'static>, )

An icecandidate event is sent to an RTCPeerConnection when:

  • An RTCIceCandidate has been identified and added to the local peer by a call to RTCPeerConnection.setLocalDescription(),

  • Every RTCIceCandidate correlated with a particular username fragment and password combination (a generation) has been so identified and added, and

  • All ICE gathering on all transports is complete.

In the first two cases, the event handler should transmit the candidate to the remote peer over the signaling channel so the remote peer can add it to its set of remote candidates.

Source

pub fn set_on_ice_gathering_state_change( &mut self, cb: Option<impl Fn(IceGatheringState) + Send + Sync + 'static>, )

The icegatheringstatechange event is sent to the onicegatheringstatechange event handler on an RTCPeerConnection when the state of the ICE candidate gathering process changes. This signifies that the value of the connection’s iceGatheringState property has changed.

When ICE first starts to gather connection candidates, the value changes from new to gathering to indicate that the process of collecting candidate configurations for the connection has begun. When the value changes to complete, all of the transports that make up the RTCPeerConnection have finished gathering ICE candidates.

Source

pub fn set_on_connection_state_change( &mut self, cb: Option<impl Fn(PeerConnectionState) + Send + Sync + 'static>, )

The connectionstatechange event is sent to the onconnectionstatechange event handler on an RTCPeerConnection object after a new track has been added to an RTCRtpReceiver which is part of the connection. The new connection state can be found in connectionState, and is one of the string values: new, connecting, connected, disconnected, failed, or closed.

Source

pub fn set_on_data_channel( &mut self, cb: Option<impl Fn(DataChannel) + Send + Sync + 'static>, )

A datachannel event is sent to an RTCPeerConnection instance when an RTCDataChannel has been added to the connection, as a result of the remote peer calling RTCPeerConnection.createDataChannel().

Source

pub fn create_data_channel( &self, label: &str, options: DataChannelOptions, ) -> Result<DataChannel, Error>

The createDataChannel() method on the RTCPeerConnection interface creates a new channel linked with the remote peer, over which any kind of data may be transmitted. This can be useful for back-channel content, such as images, file transfer, text chat, game update packets, and so forth.

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.