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
impl PeerConnection
Sourcepub fn new(config: Configuration) -> Result<Self, Error>
pub fn new(config: Configuration) -> Result<Self, Error>
Returns a new RTCPeerConnection, representing a connection between the local device and a remote peer.
Sourcepub async fn set_local_description(&self, type_: SdpType) -> Result<(), Error>
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.
Sourcepub async fn set_remote_description(
&self,
description: &Description,
) -> Result<(), Error>
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).
Sourcepub fn local_description(&self) -> Result<Option<Description>, Error>
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.
Sourcepub fn remote_description(&self) -> Result<Option<Description>, Error>
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.
Sourcepub async fn add_ice_candidate(&self, cand: Option<&str>) -> Result<(), Error>
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.
Sourcepub fn set_on_ice_candidate(
&mut self,
cb: Option<impl Fn(Option<&str>) + Send + Sync + 'static>,
)
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.
Sourcepub fn set_on_ice_gathering_state_change(
&mut self,
cb: Option<impl Fn(IceGatheringState) + Send + Sync + 'static>,
)
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.
Sourcepub fn set_on_connection_state_change(
&mut self,
cb: Option<impl Fn(PeerConnectionState) + Send + Sync + 'static>,
)
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.
Sourcepub fn set_on_data_channel(
&mut self,
cb: Option<impl Fn(DataChannel) + Send + Sync + 'static>,
)
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().
Sourcepub fn create_data_channel(
&self,
label: &str,
options: DataChannelOptions,
) -> Result<DataChannel, Error>
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.