Skip to main content

SettingEngine

Struct SettingEngine 

Source
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

Source

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,
]);
Source

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
Source

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, or None for immediate acceptance
Source

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, or None for immediate acceptance
Source

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, or None for immediate acceptance
Source

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, or None for immediate acceptance
Source

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 - true to enable ICE Lite, false for 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
Source

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,
]);
Source

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 addresses
  • candidate_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 Host type, the private IP is not advertised to the peer
  • With Srflx type, both private and public IPs are available
  • Cannot use STUN servers when using Srflx type
  • Cannot use with mDNS when using Host type
Source

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 ClientHello
    • DTLSRole::Server: Act as DTLS server, wait for ClientHello
§Returns
  • Ok(()) on success
  • Err(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
Source

pub fn set_multicast_dns_timeout(&mut self, timeout: Option<Duration>)

Source

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

Source

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

Source

pub fn set_multicast_dns_local_ip(&mut self, local_ip: Option<IpAddr>)

Source

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.

Source

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 - true to disable verification, false to 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);
Source

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 - true to allow insecure algorithms, false to disallow
Source

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
Source

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
Source

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);
Source

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 - true to gather loopback candidates, false to 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.

Source

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 - true for media-level, false for 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);
Source

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 - true to share MediaEngine, false to 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.

Source

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 - true to use single codec set, false for 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).

Source

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);
Source

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 isize argument is the greatest seen numeric MID (doesn’t include non-numeric MIDs)
§See Also
Source

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
Source

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 - true to ignore pause signals, false to honor them
Source

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 - true to write, false to ignore

Trait Implementations§

Source§

impl Clone for SettingEngine

Source§

fn clone(&self) -> SettingEngine

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
Source§

impl Default for SettingEngine

Source§

fn default() -> SettingEngine

Returns the “default value” for a type. 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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, 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V