Skip to main content

PeerConnection

Struct PeerConnection 

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

Implementations§

Source§

impl PeerConnection

Source

pub fn new(config: RtcConfiguration) -> Self

Source

pub fn config(&self) -> &RtcConfiguration

Source

pub fn bridge_rtp_with_rewrite_to( &self, dst: &PeerConnection, params: RtpRewriteBridgeParams, ) -> RtcResult<()>

Source

pub fn bridge_rtp_with_rewrite_to_self( &self, params: RtpRewriteBridgeParams, ) -> RtcResult<()>

Source

pub fn bridge_rtp_with_rewrite_rules( &self, dst: &PeerConnection, options: RtpRewriteBridgeOptions, rules: &[RtpRewriteRule], ) -> RtcResult<()>

Install a payload-type-aware rewrite bridge between two PeerConnections. Rules are matched per packet (exact-PT first, then catch-all); packets matching no rule pass through with their SSRC/PT untouched.

Source

pub fn clear_rtp_rewrite_bridge(&self)

Source

pub fn add_observer(&self, observer: Arc<dyn RtpObserver>)

Register a plaintext RtpObserver on this PeerConnection’s transports. The observer fires on clear RTP for BOTH directions (inbound post-SRTP-unprotect, outbound pre-SRTP-protect / pre-relay-push) and ALL forwarding modes, including the relay fast-path.

Use this for stats / DTMF / recording / sipflow capture. For NACK / retransmission / RTCP feedback, use the existing RtpReceiverInterceptor / RtpSenderInterceptor (installed via [RtcConfigurationBuilder]) instead.

Applied to the primary transport and all muxed media transports.

Observers may be registered before any transport exists (a WebRTC transport only appears after ICE selects a pair): they are remembered here and attached automatically when transports are created, so the first inbound packets are never missed.

Source

pub fn clear_observers(&self)

Remove all observers from the primary and muxed media transports.

Source

pub async fn send_raw_rtp(&self, packet: RtpPacket) -> RtcResult<()>

Send a raw RTP packet on this connection’s RTP transport.

This is the escape hatch for out-of-band packets that do not fit the sample-track path — most importantly RFC 4733 telephone-event (DTMF) packets, which use a separate payload type from the audio codec (the RtpSender always stamps the audio codec’s PT, so DTMF cannot ride the sample track).

The packet is sent on the audio sender’s transport when available (so it egresses on the same 5-tuple as media), falling back to the primary RTP transport. It is SRTP-protected and fire&forget (same as RtpTransport::send_rtp). Callers should gate DTMF on the leg having a negotiated profile. Sends nothing (and still returns Ok) while the negotiated direction forbids the packet’s stream to send.

Source

pub fn received_rtp_packets(&self) -> u64

Cumulative count of inbound RTP packets accepted at the transport layer across the primary and muxed media transports. Monotonically increasing; safe to poll concurrently. Used by the host to detect RTP inactivity (e.g. media-proxy rtp-timeout) regardless of the active forwarding mode (rewrite-bridge fast-path or depacketize chain).

Source

pub async fn wait_for_rtp_transport_ready( &self, timeout: Duration, ) -> RtcResult<()>

Source

pub fn ice_transport(&self) -> IceTransport

Source

pub fn add_transceiver( &self, kind: MediaKind, direction: TransceiverDirection, ) -> Arc<RtpTransceiver> ⓘ

Source

pub fn add_track( &self, track: Arc<dyn MediaStreamTrack>, params: RtpCodecParameters, ) -> RtcResult<Arc<RtpSender>>

Source

pub fn add_track_with_stream_id( &self, track: Arc<dyn MediaStreamTrack>, stream_id: String, params: RtpCodecParameters, ) -> RtcResult<Arc<RtpSender>>

Source

pub fn get_transceivers(&self) -> Vec<Arc<RtpTransceiver>>

Source

pub async fn create_offer(&self) -> RtcResult<SessionDescription>

Source

pub async fn create_answer(&self) -> RtcResult<SessionDescription>

Source

pub fn set_local_description(&self, desc: SessionDescription) -> RtcResult<()>

Source

pub async fn set_remote_description( &self, desc: SessionDescription, ) -> RtcResult<()>

Source

pub fn update_rtcp_mux_from_remote(&self)

Update the RTCP address based on the current remote description.

Call this after set_remote_description to ensure the transport correctly separates RTP and RTCP when the remote peer does not support rtcp-mux. If the remote SDP contains a=rtcp-mux, RTCP will be multiplexed on the RTP port. Otherwise, RTCP is sent to the port specified by a=rtcp or the default RTP port + 1.

Source

pub fn signaling_state(&self) -> SignalingState

Source

pub fn subscribe_signaling_state(&self) -> Receiver<SignalingState>

Source

pub fn subscribe_peer_state(&self) -> Receiver<PeerConnectionState>

Source

pub async fn wait_for_connected(&self) -> RtcResult<()>

Source

pub fn subscribe_ice_connection_state(&self) -> Receiver<IceConnectionState>

Source

pub fn subscribe_ice_gathering_state(&self) -> Receiver<IceGatheringState>

Source

pub fn subscribe_disconnect_reason(&self) -> Receiver<Option<DisconnectReason>>

Subscribe to disconnect reason updates. The value changes from None to Some(reason) when the connection is disconnected, failed, or closed.

Source

pub fn disconnect_reason(&self) -> Option<DisconnectReason>

Returns the current disconnect reason, if any.

Source

pub fn local_description(&self) -> Option<SessionDescription>

Source

pub fn remote_description(&self) -> Option<SessionDescription>

Source

pub fn close(&self)

Source

pub async fn recv(&self) -> Option<PeerConnectionEvent>

Source

pub fn create_data_channel( &self, label: &str, config: Option<DataChannelConfig>, ) -> RtcResult<Arc<DataChannel>>

Source

pub async fn send_data(&self, channel_id: u16, data: &[u8]) -> RtcResult<()>

Source

pub async fn send_text( &self, channel_id: u16, data: impl AsRef<str>, ) -> RtcResult<()>

Source

pub fn sctp_buffered_amount(&self) -> usize

Source

pub fn sctp_diagnostic_info(&self) -> Option<String>

Returns the SCTP transport’s diagnostic summary, if an SCTP association has been established. Covers duration, rto (RTT estimate), sent/recv bytes, retransmits, heartbeat failures and association error count. Returns None when there is no SCTP transport (e.g. RTP-only sessions).

Returns a snapshot of the SCTP transport’s key link statistics, if an SCTP association has been established. Useful for structured periodic logging of bytes sent/received and round-trip time.

Source

pub async fn get_stats(&self) -> RtcResult<StatsReport>

Source

pub async fn get_transport_stats(&self) -> RtcResult<StatsReport>

Collect transport-level (UDP tx/rx) stats from all active IceConn instances.

Source

pub async fn wait_for_gathering_complete(&self)

Source

pub fn subscribe_ice_candidates(&self) -> Receiver<IceCandidate>

Source

pub fn add_ice_candidate(&self, candidate: IceCandidate) -> RtcResult<()>

Source

pub async fn restart_ice(&self) -> RtcResult<()>

Restart ICE for this connection (RFC 8445 §9), the equivalent of the W3C RTCPeerConnection.restartIce() / a re-INVITE with fresh ice-ufrag/ice-pwd.

Rolls fresh local credentials, resets nomination state and re-runs connectivity checks; DTLS/SRTP survive across the restart. Call this before create_offer so the new offer carries the restart (new ice-ufrag/ice-pwd). The peer detects the credential change and restarts its own side.

Trait Implementations§

Source§

impl Clone for PeerConnection

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

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