Skip to main content

RTCConfigurationBuilder

Struct RTCConfigurationBuilder 

Source
pub struct RTCConfigurationBuilder(/* private fields */);
Expand description

Builder for creating RTCConfiguration instances.

This registry provides a fluent API for configuring WebRTC peer connection settings:

  • ICE servers (STUN/TURN) for NAT traversal
  • Transport policies (which ICE candidates to use)
  • Bundle and RTCP mux policies
  • Custom DTLS certificates
  • ICE candidate pool size

§Examples

§Basic configuration with STUN

use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCIceServer};

let config = RTCConfigurationBuilder::new()
    .with_ice_servers(vec![
        RTCIceServer {
            urls: vec!["stun:stun.l.google.com:19302".to_string()],
            ..Default::default()
        }
    ])
    .build();

§TURN server with credentials

use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCIceServer};

let config = RTCConfigurationBuilder::new()
    .with_ice_servers(vec![
        RTCIceServer {
            urls: vec!["turn:turn.example.com:3478".to_string()],
            username: "user".to_string(),
            credential: "password".to_string(),
            ..Default::default()
        }
    ])
    .build();

§Relay-only (privacy mode)

use rtc::peer_connection::configuration::{
    RTCConfigurationBuilder,
    RTCIceServer,
    RTCIceTransportPolicy
};

let config = RTCConfigurationBuilder::new()
    .with_ice_servers(vec![
        RTCIceServer {
            urls: vec!["turn:turn.example.com:3478".to_string()],
            username: "user".to_string(),
            credential: "password".to_string(),
            ..Default::default()
        }
    ])
    .with_ice_transport_policy(RTCIceTransportPolicy::Relay)
    .build();

§Custom certificate

use rtc::peer_connection::configuration::RTCConfigurationBuilder;
use rtc::peer_connection::certificate::RTCCertificate;
use rtc::crypto::{self, SignatureScheme};
use rtc::peer_connection::certificate::CertificateParams;

    let provider = crypto::default_provider()?;
let certificate = RTCCertificate::generate(
    provider.crypto(),
    SignatureScheme::EcdsaP256Sha256,
    CertificateParams::new(vec!["localhost".to_owned()])?,
)?;

let config = RTCConfigurationBuilder::new()
    .with_certificates(vec![certificate])
    .build();

Implementations§

Source§

impl RTCConfigurationBuilder

Source

pub fn new() -> RTCConfigurationBuilder

Creates a new RTCConfigurationBuilder with default settings.

Default values:

  • No ICE servers (local candidates only)
  • All ICE candidate types allowed
  • Balanced bundle policy
  • Required RTCP mux policy
  • No peer identity
  • Auto-generated certificates
  • ICE candidate pool size of 0
§Examples
use rtc::peer_connection::configuration::RTCConfigurationBuilder;

let config = RTCConfigurationBuilder::new().build();
Source

pub fn with_ice_servers( self, ice_servers: Vec<RTCIceServer>, ) -> RTCConfigurationBuilder

Sets the ICE servers for STUN and TURN.

ICE servers are used for NAT traversal to establish peer-to-peer connectivity. Multiple servers can be provided for redundancy.

§Examples
use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCIceServer};

let config = RTCConfigurationBuilder::new()
    .with_ice_servers(vec![
        RTCIceServer {
            urls: vec!["stun:stun.l.google.com:19302".to_string()],
            ..Default::default()
        },
        RTCIceServer {
            urls: vec!["turn:turn.example.com:3478".to_string()],
            username: "user".to_string(),
            credential: "pass".to_string(),
            ..Default::default()
        }
    ])
    .build();
Source

pub fn with_ice_transport_policy( self, ice_transport_policy: RTCIceTransportPolicy, ) -> RTCConfigurationBuilder

Sets the ICE transport policy.

Controls which types of ICE candidates are allowed:

  • All (default): Use all candidate types (host, srflx, relay)
  • Relay: Only use TURN relay candidates (hides IP addresses)
§Examples
use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCIceTransportPolicy};

// Privacy mode - only use TURN relays
let config = RTCConfigurationBuilder::new()
    .with_ice_transport_policy(RTCIceTransportPolicy::Relay)
    .build();
Source

pub fn with_bundle_policy( self, bundle_policy: RTCBundlePolicy, ) -> RTCConfigurationBuilder

Sets the bundle policy.

Controls how media tracks are bundled onto transports:

  • Balanced (default): Bundle audio/video separately if peer doesn’t support bundling
  • MaxCompat: Separate transports for each track (maximum compatibility)
  • MaxBundle: Single transport for all media (best performance)
§Examples
use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCBundlePolicy};

let config = RTCConfigurationBuilder::new()
    .with_bundle_policy(RTCBundlePolicy::MaxBundle)
    .build();
Source

pub fn with_rtcp_mux_policy( self, rtcp_mux_policy: RTCRtcpMuxPolicy, ) -> RTCConfigurationBuilder

Sets the RTCP multiplexing policy.

Controls whether RTCP is multiplexed with RTP:

  • Negotiate: Try to multiplex, fall back to separate ports
  • Require (default): Require multiplexing (standard for WebRTC)
§Examples
use rtc::peer_connection::configuration::{RTCConfigurationBuilder, RTCRtcpMuxPolicy};

let config = RTCConfigurationBuilder::new()
    .with_rtcp_mux_policy(RTCRtcpMuxPolicy::Require)
    .build();
Source

pub fn with_peer_identitys( self, peer_identity: String, ) -> RTCConfigurationBuilder

Sets the target peer identity.

If set, the peer connection will only connect to a remote peer that can be successfully authenticated with this identity.

§Examples
use rtc::peer_connection::configuration::RTCConfigurationBuilder;

let config = RTCConfigurationBuilder::new()
    .with_peer_identitys("peer@example.com".to_string())
    .build();
Source

pub fn with_certificates( self, certificates: Vec<RTCCertificate>, ) -> RTCConfigurationBuilder

Sets custom DTLS certificates.

If not provided, certificates are auto-generated. Providing certificates allows for consistent peer identity across connections.

§Examples
use rtc::peer_connection::configuration::RTCConfigurationBuilder;
use rtc::peer_connection::certificate::RTCCertificate;
use rtc::crypto::{self, SignatureScheme};
use rtc::peer_connection::certificate::CertificateParams;

    let provider = crypto::default_provider()?;
let certificate = RTCCertificate::generate(
    provider.crypto(),
    SignatureScheme::EcdsaP256Sha256,
    CertificateParams::new(vec!["localhost".to_owned()])?,
)?;

let config = RTCConfigurationBuilder::new()
    .with_certificates(vec![certificate])
    .build();
Source

pub fn with_ice_candidate_pool_size( self, ice_candidate_pool_size: u8, ) -> RTCConfigurationBuilder

Sets the ICE candidate pool size.

Specifies the number of ICE candidates to gather before needed. Pre-gathering candidates can reduce connection establishment time.

§Examples
use rtc::peer_connection::configuration::RTCConfigurationBuilder;

let config = RTCConfigurationBuilder::new()
    .with_ice_candidate_pool_size(5)
    .build();
Source

pub fn build(self) -> RTCConfiguration

Builds the RTCConfiguration.

Creates an immutable configuration that can be used to create a peer connection.

§Examples
use rtc::peer_connection::configuration::RTCConfigurationBuilder;

let config = RTCConfigurationBuilder::new().build();

Trait Implementations§

Source§

impl Default for RTCConfigurationBuilder

Source§

fn default() -> RTCConfigurationBuilder

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> 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<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> Same for T

Source§

type Output = T

Should always be Self
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.