pub struct SettingEngine { /* private fields */ }Expand description
Advanced configuration engine for fine-tuning WebRTC behavior.
SettingEngine provides granular control over transport-level settings that
are not exposed through the standard WebRTC API. Use this to optimize for
specific deployment scenarios, network conditions, or security requirements.
§Configuration Categories
- Timeout: ICE connection health monitoring and keepalive
- Candidates: NAT traversal, network filtering, ICE credentials
- Replay Protection: Anti-replay window sizes for DTLS/SRTP/SRTCP
- DTLS: Certificate verification and role selection
- Media Engine: Codec registration behavior
- SCTP: Data channel message size limits
§Examples
§Basic usage with RTCConfiguration
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use std::time::Duration;
let mut setting_engine = SettingEngine::default();
// Configure timeouts
setting_engine.set_ice_timeouts(
Some(Duration::from_secs(10)),
Some(Duration::from_secs(30)),
Some(Duration::from_secs(3)),
);
// Enable loopback for testing
setting_engine.set_include_loopback_candidate(true);
// Use with peer connection configuration
// let api = APIBuilder::new().with_setting_engine(setting_engine).build();§See Also
Implementations§
Source§impl SettingEngine
impl SettingEngine
Sourcepub fn set_srtp_protection_profiles(
&mut self,
profiles: Vec<SrtpProtectionProfile>,
)
pub fn set_srtp_protection_profiles( &mut self, profiles: Vec<SrtpProtectionProfile>, )
Overrides the default SRTP protection profiles.
SRTP profiles define the encryption algorithms used for media streams. Only override this if you need specific security requirements or compatibility with non-standard implementations.
§Parameters
profiles- List of SRTP protection profiles to use
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use dtls::extension::extension_use_srtp::SrtpProtectionProfile;
let mut setting_engine = SettingEngine::default();
// Use specific SRTP profile
setting_engine.set_srtp_protection_profiles(vec![
SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_80,
]);Sourcepub fn set_ice_timeouts(
&mut self,
disconnected_timeout: Option<Duration>,
failed_timeout: Option<Duration>,
keep_alive_interval: Option<Duration>,
)
pub fn set_ice_timeouts( &mut self, disconnected_timeout: Option<Duration>, failed_timeout: Option<Duration>, keep_alive_interval: Option<Duration>, )
Configures ICE timeout behavior for connection health monitoring.
These timeouts control when ICE transitions between connection states and when keepalive packets are sent. Adjust these for different network conditions:
- Increase for unstable networks (mobile, satellite)
- Decrease for low-latency applications
§Parameters
disconnected_timeout- Duration without activity before considered disconnected (default: 5s)failed_timeout- Duration after disconnected before considered failed (default: 25s)keep_alive_interval- How often to send keepalives when idle (default: 2s)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use std::time::Duration;
let mut setting_engine = SettingEngine::default();
// Conservative settings for mobile networks
setting_engine.set_ice_timeouts(
Some(Duration::from_secs(10)), // Longer before disconnected
Some(Duration::from_secs(40)), // Longer before failed
Some(Duration::from_secs(5)), // Less frequent keepalives
);§See Also
Sourcepub fn set_host_acceptance_min_wait(&mut self, t: Option<Duration>)
pub fn set_host_acceptance_min_wait(&mut self, t: Option<Duration>)
Sets minimum wait time before accepting host candidates.
§Parameters
t- Minimum wait duration, orNonefor immediate acceptance
Sourcepub fn set_srflx_acceptance_min_wait(&mut self, t: Option<Duration>)
pub fn set_srflx_acceptance_min_wait(&mut self, t: Option<Duration>)
Sets minimum wait time before accepting server reflexive candidates.
Server reflexive candidates are discovered through STUN servers.
§Parameters
t- Minimum wait duration, orNonefor immediate acceptance
Sourcepub fn set_prflx_acceptance_min_wait(&mut self, t: Option<Duration>)
pub fn set_prflx_acceptance_min_wait(&mut self, t: Option<Duration>)
Sets minimum wait time before accepting peer reflexive candidates.
Peer reflexive candidates are discovered during connectivity checks.
§Parameters
t- Minimum wait duration, orNonefor immediate acceptance
Sourcepub fn set_relay_acceptance_min_wait(&mut self, t: Option<Duration>)
pub fn set_relay_acceptance_min_wait(&mut self, t: Option<Duration>)
Sets minimum wait time before accepting relay candidates.
Relay candidates are provided by TURN servers.
§Parameters
t- Minimum wait duration, orNonefor immediate acceptance
Sourcepub fn set_lite(&mut self, lite: bool)
pub fn set_lite(&mut self, lite: bool)
Configures ICE Lite mode.
In ICE Lite mode, the agent only responds to connectivity checks but does not initiate them. This is typically used by servers that have public IP addresses and don’t need full ICE functionality.
§Parameters
lite-trueto enable ICE Lite,falsefor full ICE
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Enable ICE Lite for a publicly accessible server
setting_engine.set_lite(true);§See Also
Sourcepub fn set_network_types(&mut self, candidate_types: Vec<NetworkType>)
pub fn set_network_types(&mut self, candidate_types: Vec<NetworkType>)
Restricts candidate gathering to specific network types.
This reduces the number of candidates gathered, which can speed up connection establishment and reduce SDP size. Useful when you know certain network types won’t work in your deployment.
§Parameters
candidate_types- List of allowed network types (e.g., UDP4, UDP6, TCP4)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use ice::network_type::NetworkType;
let mut setting_engine = SettingEngine::default();
// Only use IPv4 UDP (most common case)
setting_engine.set_network_types(vec![NetworkType::Udp4]);
// Or allow both IPv4 and IPv6 UDP
setting_engine.set_network_types(vec![
NetworkType::Udp4,
NetworkType::Udp6,
]);Sourcepub fn set_nat_1to1_ips(
&mut self,
ips: Vec<String>,
candidate_type: RTCIceCandidateType,
)
pub fn set_nat_1to1_ips( &mut self, ips: Vec<String>, candidate_type: RTCIceCandidateType, )
Configures 1:1 NAT IP mapping for cloud deployments.
This is essential for WebRTC servers running on cloud instances (e.g., AWS EC2) that have a private IP address but are accessible via a public IP through 1:1 NAT.
§Parameters
ips- List of external/public IP addressescandidate_type- How to advertise the public IPs:RTCIceCandidateType::Host: Replace private IP with public IP (mDNS disabled)RTCIceCandidateType::Srflx: Add public IP as server reflexive candidate
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use rtc::peer_connection::transport::RTCIceCandidateType;
let mut setting_engine = SettingEngine::default();
// AWS EC2: Private IP 10.0.1.5, Elastic IP 54.123.45.67
setting_engine.set_nat_1to1_ips(
vec!["54.123.45.67".to_string()],
RTCIceCandidateType::Host,
);
// Or use Srflx to keep private IP available
setting_engine.set_nat_1to1_ips(
vec!["54.123.45.67".to_string()],
RTCIceCandidateType::Srflx,
);§Notes
- With
Hosttype, the private IP is not advertised to the peer - With
Srflxtype, both private and public IPs are available - Cannot use STUN servers when using
Srflxtype - Cannot use with mDNS when using
Hosttype
Sourcepub fn set_answering_dtls_role(&mut self, role: RTCDtlsRole) -> Result<()>
pub fn set_answering_dtls_role(&mut self, role: RTCDtlsRole) -> Result<()>
Sets the DTLS role to use when answering an offer.
The DTLS role determines whether this peer acts as a DTLS client (initiating the handshake) or server (waiting for handshake). Normally this is negotiated automatically, but you can override it for debugging or compatibility with non-compliant implementations.
§Parameters
role- DTLS role to use:DTLSRole::Client: Act as DTLS client, send ClientHelloDTLSRole::Server: Act as DTLS server, wait for ClientHello
§Returns
Ok(())on successErr(Error)if role is not Client or Server
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
use rtc::peer_connection::transport::RTCDtlsRole;
let mut setting_engine = SettingEngine::default();
// Force this peer to always act as DTLS client when answering
setting_engine.set_answering_dtls_role(RTCDtlsRole::Client)?;§See Also
pub fn set_multicast_dns_timeout(&mut self, timeout: Option<Duration>)
Sourcepub fn set_multicast_dns_mode(&mut self, multicast_dns_mode: MulticastDnsMode)
pub fn set_multicast_dns_mode(&mut self, multicast_dns_mode: MulticastDnsMode)
set_ice_multicast_dns_mode controls if ice queries and generates mDNS ICE Candidates
Sourcepub fn set_multicast_dns_local_name(&mut self, local_name: String)
pub fn set_multicast_dns_local_name(&mut self, local_name: String)
set_ice_multicast_dns_host_name sets a static HostName to be used by ice instead of generating one on startup This should only be used for a single PeerConnection. Having multiple PeerConnections with the same HostName will cause undefined behavior
pub fn set_multicast_dns_local_ip(&mut self, local_ip: Option<IpAddr>)
Sourcepub fn set_ice_credentials(
&mut self,
username_fragment: String,
password: String,
)
pub fn set_ice_credentials( &mut self, username_fragment: String, password: String, )
Sets static ICE credentials for reproducible sessions.
By default, ICE generates random credentials (ufrag/password) for each session. Setting static credentials allows for signalless WebRTC or reproducible testing environments.
§Parameters
username_fragment- ICE username fragment (ufrag)password- ICE password
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Set static credentials for reproducible testing
setting_engine.set_ice_credentials(
"test_ufrag".to_string(),
"test_password".to_string(),
);§Security Note
Only use static credentials in controlled environments. Random credentials provide better security for production deployments.
Sourcepub fn disable_certificate_fingerprint_verification(
&mut self,
is_disabled: bool,
)
pub fn disable_certificate_fingerprint_verification( &mut self, is_disabled: bool, )
Disables DTLS certificate fingerprint verification.
Warning: Disabling fingerprint verification removes a critical security check and should only be used for testing or debugging.
§Parameters
is_disabled-trueto disable verification,falseto enable
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Only for testing/debugging!
setting_engine.disable_certificate_fingerprint_verification(true);Sourcepub fn allow_insecure_verification_algorithm(&mut self, is_allowed: bool)
pub fn allow_insecure_verification_algorithm(&mut self, is_allowed: bool)
Allows insecure signature verification algorithms.
Some signature algorithms are known to be vulnerable or deprecated. This setting allows their use for compatibility with legacy systems.
Warning: Only enable this if absolutely necessary for compatibility.
§Parameters
is_allowed-trueto allow insecure algorithms,falseto disallow
Sourcepub fn set_dtls_replay_protection_window(&mut self, n: usize)
pub fn set_dtls_replay_protection_window(&mut self, n: usize)
Sets the DTLS replay protection window size.
The replay protection window prevents attackers from re-sending captured packets. Larger windows protect against more packet reordering but use more memory. Set to 0 to disable (not recommended).
§Parameters
n- Window size in packets (0 = disabled)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Increase window for high-latency or reordering networks
setting_engine.set_dtls_replay_protection_window(128);§See Also
Sourcepub fn set_srtp_replay_protection_window(&mut self, n: usize)
pub fn set_srtp_replay_protection_window(&mut self, n: usize)
Sets the SRTP replay protection window size.
SRTP replay protection prevents replay attacks on encrypted media packets. Adjust the window size based on expected packet reordering in your network.
§Parameters
n- Window size in packets (0 = disabled, not recommended)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Standard size for most applications
setting_engine.set_srtp_replay_protection_window(256);§See Also
Sourcepub fn set_srtcp_replay_protection_window(&mut self, n: usize)
pub fn set_srtcp_replay_protection_window(&mut self, n: usize)
Sets the SRTCP replay protection window size.
SRTCP replay protection applies to RTCP control packets. Usually a smaller window is sufficient since RTCP packets are less frequent.
§Parameters
n- Window size in packets (0 = disabled, not recommended)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Smaller window sufficient for RTCP
setting_engine.set_srtcp_replay_protection_window(64);Sourcepub fn set_include_loopback_candidate(&mut self, allow_loopback: bool)
pub fn set_include_loopback_candidate(&mut self, allow_loopback: bool)
Allows gathering of loopback candidates.
By default, loopback candidates (127.x.x.x, ::1) are not gathered per RFC 8445. However, some VM configurations map public IPs to the loopback interface, making this necessary.
§Parameters
allow_loopback-trueto gather loopback candidates,falseto skip
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Enable for certain VM configurations
setting_engine.set_include_loopback_candidate(true);§Note
This is non-standard behavior per RFC 8445 §5.1.1.1. Use with caution.
Sourcepub fn set_sdp_media_level_fingerprints(
&mut self,
sdp_media_level_fingerprints: bool,
)
pub fn set_sdp_media_level_fingerprints( &mut self, sdp_media_level_fingerprints: bool, )
Controls where DTLS fingerprints are placed in SDP.
By default, fingerprints are placed at the session level. Setting this
to true places them at the media level instead, which improves
compatibility with some WebRTC implementations.
§Parameters
sdp_media_level_fingerprints-truefor media-level,falsefor session-level
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Use media-level fingerprints for better compatibility
setting_engine.set_sdp_media_level_fingerprints(true);Sourcepub fn disable_media_engine_copy(&mut self, is_disabled: bool)
pub fn disable_media_engine_copy(&mut self, is_disabled: bool)
Prevents the MediaEngine from being copied for each PeerConnection.
By default, each PeerConnection gets a copy of the MediaEngine, allowing independent codec configurations. Disabling this allows sharing a single MediaEngine and modifying it after PeerConnection creation.
§Parameters
is_disabled-trueto share MediaEngine,falseto copy (default)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Share MediaEngine across connections
setting_engine.disable_media_engine_copy(true);
// Warning: Don't share MediaEngine between multiple PeerConnections
// unless you understand the implications§Warning
When disabled, ensure you don’t share the same MediaEngine between multiple PeerConnections unless you specifically intend to do so.
Sourcepub fn disable_media_engine_multiple_codecs(&mut self, is_disabled: bool)
pub fn disable_media_engine_multiple_codecs(&mut self, is_disabled: bool)
Disables negotiating different codecs for different media sections.
By default, each media section in the SDP can negotiate different codecs, which is the spec-compliant behavior. This setting forces all media sections to use the same codecs.
§Parameters
is_disabled-trueto use single codec set,falsefor per-section (default)
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Force same codecs for all media sections
setting_engine.disable_media_engine_multiple_codecs(true);§Deprecation Note
This setting is targeted for removal in a future release (4.2.0 or later).
Sourcepub fn set_receive_mtu(&mut self, receive_mtu: usize)
pub fn set_receive_mtu(&mut self, receive_mtu: usize)
Sets the MTU size for the receive buffer.
This controls the maximum size of packets that can be received. Leave at 0 to use the default MTU (1460 bytes, equal to UDP MTU).
§Parameters
receive_mtu- MTU size in bytes, or 0 for default
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Use larger MTU for jumbo frames
setting_engine.set_receive_mtu(9000);
// Or use default
setting_engine.set_receive_mtu(0);Sourcepub fn set_mid_generator(
&mut self,
f: impl Fn(isize) -> String + Send + Sync + 'static,
)
pub fn set_mid_generator( &mut self, f: impl Fn(isize) -> String + Send + Sync + 'static, )
Sets a custom MID (media stream ID) generator function.
By default, MIDs are generated automatically. This allows you to provide a custom generation scheme, useful for reducing complexity when handling SDP offer/answer collisions.
§Parameters
f- Function that takes the highest seen numeric MID and returns a new MID string
§Examples
use rtc::peer_connection::configuration::setting_engine::SettingEngine;
let mut setting_engine = SettingEngine::default();
// Generate MIDs with a custom prefix
setting_engine.set_mid_generator(|max_mid| {
format!("custom_{}", max_mid + 1)
});§Notes
- MIDs should be generated without leaking user information (e.g., randomly)
- MIDs should be 3 bytes or less for efficient RTP header extension encoding
- The
isizeargument is the greatest seen numeric MID (doesn’t include non-numeric MIDs)
§See Also
Sourcepub fn set_sctp_max_message_size(
&mut self,
max_message_size: SctpMaxMessageSize,
)
pub fn set_sctp_max_message_size( &mut self, max_message_size: SctpMaxMessageSize, )
Sets the maximum message size for SCTP data channels.
This controls the largest message that can be sent through a data channel. Larger messages will be fragmented or rejected depending on the configuration.
§Parameters
max_message_size- Maximum size (Bounded or Unbounded)
§Examples
use rtc::peer_connection::configuration::setting_engine::{SettingEngine, SctpMaxMessageSize};
let mut setting_engine = SettingEngine::default();
// Use default 64KB
setting_engine.set_sctp_max_message_size(
SctpMaxMessageSize::Bounded(SctpMaxMessageSize::DEFAULT_MESSAGE_SIZE)
);
// Or allow larger messages
setting_engine.set_sctp_max_message_size(
SctpMaxMessageSize::Bounded(256 * 1024) // 256KB
);
// Or unbounded (uses MAX_MESSAGE_SIZE internally)
setting_engine.set_sctp_max_message_size(SctpMaxMessageSize::Unbounded);§See Also
Sourcepub fn set_ignore_rid_pause_for_recv(&mut self, ignore_rid_pause_for_recv: bool)
pub fn set_ignore_rid_pause_for_recv(&mut self, ignore_rid_pause_for_recv: bool)
Controls whether to ignore RID pause signals for receiving transceivers.
RID (RTP Stream Identifier) can signal pause/resume for individual streams in simulcast scenarios. This setting controls whether to honor those signals.
§Parameters
ignore_rid_pause_for_recv-trueto ignore pause signals,falseto honor them
Sourcepub fn set_write_ssrc_attributes_for_simulcast(
&mut self,
write_ssrc_attributes_for_simulcast: bool,
)
pub fn set_write_ssrc_attributes_for_simulcast( &mut self, write_ssrc_attributes_for_simulcast: bool, )
Controls whether to ignore SSRC attribute in SDP’s sendonly or sendrecv for simulcast
§Parameters
write_ssrc_attributes_for_simulcast-trueto write,falseto ignore
Trait Implementations§
Source§impl Clone for SettingEngine
impl Clone for SettingEngine
Source§fn clone(&self) -> SettingEngine
fn clone(&self) -> SettingEngine
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for SettingEngine
impl Default for SettingEngine
Source§fn default() -> SettingEngine
fn default() -> SettingEngine
Auto Trait Implementations§
impl !RefUnwindSafe for SettingEngine
impl !UnwindSafe for SettingEngine
impl Freeze for SettingEngine
impl Send for SettingEngine
impl Sync for SettingEngine
impl Unpin for SettingEngine
impl UnsafeUnpin for SettingEngine
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.