pub struct PeerConnection { /* private fields */ }Implementations§
Source§impl PeerConnection
impl PeerConnection
pub fn new(config: RtcConfiguration) -> Self
pub fn config(&self) -> &RtcConfiguration
pub fn bridge_rtp_with_rewrite_to( &self, dst: &PeerConnection, params: RtpRewriteBridgeParams, ) -> RtcResult<()>
pub fn bridge_rtp_with_rewrite_to_self( &self, params: RtpRewriteBridgeParams, ) -> RtcResult<()>
Sourcepub fn bridge_rtp_with_rewrite_rules(
&self,
dst: &PeerConnection,
options: RtpRewriteBridgeOptions,
rules: &[RtpRewriteRule],
) -> RtcResult<()>
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.
pub fn clear_rtp_rewrite_bridge(&self)
Sourcepub fn add_observer(&self, observer: Arc<dyn RtpObserver>)
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.
Sourcepub fn clear_observers(&self)
pub fn clear_observers(&self)
Remove all observers from the primary and muxed media transports.
Sourcepub async fn send_raw_rtp(&self, packet: RtpPacket) -> RtcResult<()>
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.
Sourcepub fn received_rtp_packets(&self) -> u64
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).
pub async fn wait_for_rtp_transport_ready( &self, timeout: Duration, ) -> RtcResult<()>
pub fn ice_transport(&self) -> IceTransport
pub fn add_transceiver( &self, kind: MediaKind, direction: TransceiverDirection, ) -> Arc<RtpTransceiver> ⓘ
pub fn add_track( &self, track: Arc<dyn MediaStreamTrack>, params: RtpCodecParameters, ) -> RtcResult<Arc<RtpSender>>
pub fn add_track_with_stream_id( &self, track: Arc<dyn MediaStreamTrack>, stream_id: String, params: RtpCodecParameters, ) -> RtcResult<Arc<RtpSender>>
pub fn get_transceivers(&self) -> Vec<Arc<RtpTransceiver>>
pub async fn create_offer(&self) -> RtcResult<SessionDescription>
pub async fn create_answer(&self) -> RtcResult<SessionDescription>
pub fn set_local_description(&self, desc: SessionDescription) -> RtcResult<()>
pub async fn set_remote_description( &self, desc: SessionDescription, ) -> RtcResult<()>
Sourcepub fn update_rtcp_mux_from_remote(&self)
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.
pub fn signaling_state(&self) -> SignalingState
pub fn subscribe_signaling_state(&self) -> Receiver<SignalingState>
pub fn subscribe_peer_state(&self) -> Receiver<PeerConnectionState>
pub async fn wait_for_connected(&self) -> RtcResult<()>
pub fn subscribe_ice_connection_state(&self) -> Receiver<IceConnectionState>
pub fn subscribe_ice_gathering_state(&self) -> Receiver<IceGatheringState>
Sourcepub fn subscribe_disconnect_reason(&self) -> Receiver<Option<DisconnectReason>>
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.
Sourcepub fn disconnect_reason(&self) -> Option<DisconnectReason>
pub fn disconnect_reason(&self) -> Option<DisconnectReason>
Returns the current disconnect reason, if any.
pub fn local_description(&self) -> Option<SessionDescription>
pub fn remote_description(&self) -> Option<SessionDescription>
pub fn close(&self)
pub async fn recv(&self) -> Option<PeerConnectionEvent>
pub fn create_data_channel( &self, label: &str, config: Option<DataChannelConfig>, ) -> RtcResult<Arc<DataChannel>>
pub async fn send_data(&self, channel_id: u16, data: &[u8]) -> RtcResult<()>
pub async fn send_text( &self, channel_id: u16, data: impl AsRef<str>, ) -> RtcResult<()>
pub fn sctp_buffered_amount(&self) -> usize
Sourcepub fn sctp_diagnostic_info(&self) -> Option<String>
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).
Sourcepub fn sctp_link_stats(&self) -> Option<SctpLinkStats>
pub fn sctp_link_stats(&self) -> Option<SctpLinkStats>
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.
pub async fn get_stats(&self) -> RtcResult<StatsReport>
Sourcepub async fn get_transport_stats(&self) -> RtcResult<StatsReport>
pub async fn get_transport_stats(&self) -> RtcResult<StatsReport>
Collect transport-level (UDP tx/rx) stats from all active IceConn instances.
pub async fn wait_for_gathering_complete(&self)
pub fn subscribe_ice_candidates(&self) -> Receiver<IceCandidate>
pub fn add_ice_candidate(&self, candidate: IceCandidate) -> RtcResult<()>
Sourcepub async fn restart_ice(&self) -> RtcResult<()>
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.