Struct ClientConfig

Source
pub struct ClientConfig {
    pub local_sip_addr: SocketAddr,
    pub local_media_addr: SocketAddr,
    pub user_agent: String,
    pub media: MediaConfig,
    pub max_concurrent_calls: usize,
    pub session_timeout_secs: u64,
    pub enable_audio: bool,
    pub enable_video: bool,
    pub domain: Option<String>,
}
Expand description

Comprehensive configuration for the SIP client

This structure contains all the configuration needed to set up and run a VoIP client, including network settings, media configuration, session parameters, and feature flags. It uses the builder pattern for easy configuration and provides sensible defaults.

§Configuration Categories

§Network Configuration

  • SIP Address: Local address for SIP signaling
  • Media Address: Local address for RTP media streams
  • Domain: Optional SIP domain for routing

§Session Management

  • Concurrent Calls: Maximum number of simultaneous calls
  • Timeouts: Session and registration timeout values
  • User Agent: Client identification string

§Media Settings

  • Audio/Video: Enable/disable media types
  • MediaConfig: Detailed codec and processing settings

§Examples

§Basic Configuration

use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_sip_addr("127.0.0.1:5060".parse().unwrap())
    .with_user_agent("MyApp/1.0".to_string())
    .with_max_calls(5);
 
assert_eq!(config.max_concurrent_calls, 5);
assert_eq!(config.user_agent, "MyApp/1.0");
assert!(config.enable_audio);

§Enterprise Configuration

use rvoip_client_core::client::config::{ClientConfig, MediaPreset};
 
let enterprise_config = ClientConfig::new()
    .with_sip_addr("192.168.1.100:5060".parse().unwrap())
    .with_media_addr("192.168.1.100:0".parse().unwrap())
    .with_user_agent("EnterprisePhone/2.1".to_string())
    .with_media_preset(MediaPreset::Secure)
    .with_max_calls(20);
 
assert_eq!(enterprise_config.max_concurrent_calls, 20);
assert!(enterprise_config.media.require_srtp);
assert_eq!(enterprise_config.local_sip_addr.ip().to_string(), "192.168.1.100");

§Mobile Configuration

use rvoip_client_core::client::config::{ClientConfig, MediaPreset};
 
let mobile_config = ClientConfig::new()
    .with_media_preset(MediaPreset::LowBandwidth)
    .with_user_agent("MobileVoIP/1.0".to_string())
    .with_max_calls(2);
 
assert_eq!(mobile_config.max_concurrent_calls, 2);
assert_eq!(mobile_config.media.max_bandwidth_kbps, Some(32));
assert!(mobile_config.media.preferred_codecs.iter().any(|c| c == "G.729"));

§Custom Media Configuration

use rvoip_client_core::client::config::{ClientConfig, MediaConfig};
use std::collections::HashMap;
 
let custom_media = MediaConfig {
    preferred_codecs: vec!["opus".to_string(), "G722".to_string()],
    echo_cancellation: true,
    noise_suppression: true,
    auto_gain_control: false, // Disable AGC
    max_bandwidth_kbps: Some(128),
    require_srtp: true,
    srtp_profiles: vec!["AES_CM_128_HMAC_SHA1_80".to_string()],
    rtp_port_start: 16384,
    rtp_port_end: 32767,
    preferred_ptime: Some(20),
    custom_sdp_attributes: HashMap::new(),
    dtmf_enabled: true,
};
 
let config = ClientConfig::new()
    .with_media(custom_media)
    .with_user_agent("CustomApp/1.0".to_string());
 
assert!(!config.media.auto_gain_control);
assert!(config.media.require_srtp);
assert_eq!(config.media.rtp_port_start, 16384);

§Configuration Validation

use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_sip_addr("0.0.0.0:5060".parse().unwrap())
    .with_media_addr("0.0.0.0:0".parse().unwrap());
 
// Verify default settings
assert!(config.max_concurrent_calls > 0);
assert!(config.session_timeout_secs > 0);
assert!(config.enable_audio);
assert!(!config.enable_video); // Default: video disabled
assert!(config.domain.is_none()); // Default: no domain
 
// Verify media defaults
assert_eq!(config.media.rtp_port_start, 10000);
assert_eq!(config.media.rtp_port_end, 20000);
assert!(config.media.rtp_port_start < config.media.rtp_port_end);

Fields§

§local_sip_addr: SocketAddr

Local SIP bind address

§local_media_addr: SocketAddr

Local media bind address

§user_agent: String

User agent string

§media: MediaConfig

Media configuration

§max_concurrent_calls: usize

Maximum number of concurrent calls

§session_timeout_secs: u64

Session timeout in seconds

§enable_audio: bool

Enable audio processing

§enable_video: bool

Enable video processing (future)

§domain: Option<String>

SIP domain (optional)

Implementations§

Source§

impl ClientConfig

Source

pub fn new() -> Self

Create a new client configuration with sensible defaults

Initializes a ClientConfig with default values suitable for most applications. The configuration can be customized using the builder pattern methods.

§Default Values
  • SIP Address: 127.0.0.1:5060 (bind to localhost, standard SIP port)
  • Media Address: 127.0.0.1:0 (port 0 = automatic allocation when media session is created)
  • User Agent: rvoip-client-core/0.1.0
  • Max Calls: 10 concurrent calls
  • Timeout: 300 seconds (5 minutes)
  • Audio: Enabled
  • Video: Disabled
  • Media: Default MediaConfig with standard codecs
§Returns

A new ClientConfig with default settings

§Examples
§Basic Usage
use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new();
 
// Verify defaults
assert_eq!(config.local_sip_addr.ip().to_string(), "127.0.0.1");
assert_eq!(config.local_sip_addr.port(), 5060); // Standard SIP port
assert_eq!(config.max_concurrent_calls, 10);
assert_eq!(config.session_timeout_secs, 300);
assert!(config.enable_audio);
assert!(!config.enable_video);
assert!(config.domain.is_none());
§Immediate Customization
use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_sip_addr("192.168.1.100:5060".parse().unwrap())
    .with_user_agent("MyApp/1.0".to_string())
    .with_max_calls(5);
 
assert_eq!(config.local_sip_addr.ip().to_string(), "192.168.1.100");
assert_eq!(config.local_sip_addr.port(), 5060);
assert_eq!(config.user_agent, "MyApp/1.0");
assert_eq!(config.max_concurrent_calls, 5);
Source

pub fn with_sip_addr(self, addr: SocketAddr) -> Self

Set the local SIP bind address for signaling

Configures the local address and port that the SIP client will bind to for receiving SIP messages. Use 0.0.0.0 to bind to all interfaces and port 0 to let the OS assign an available port.

§Arguments
  • addr - The socket address to bind SIP signaling to
§Examples
use rvoip_client_core::client::config::ClientConfig;
use std::net::SocketAddr;
 
// Bind to specific address and port
let config = ClientConfig::new()
    .with_sip_addr("192.168.1.100:5060".parse().unwrap());
 
assert_eq!(config.local_sip_addr.ip().to_string(), "192.168.1.100");
assert_eq!(config.local_sip_addr.port(), 5060);
 
// Bind to all interfaces with OS-assigned port
let config2 = ClientConfig::new()
    .with_sip_addr("0.0.0.0:0".parse().unwrap());
 
assert_eq!(config2.local_sip_addr.ip().to_string(), "0.0.0.0");
assert_eq!(config2.local_sip_addr.port(), 0);
Source

pub fn with_media_addr(self, addr: SocketAddr) -> Self

Set the local media bind address for RTP streams

Configures the local address that will be used for RTP media streams. This is typically the same as the SIP address but can be different for advanced network configurations.

§Arguments
  • addr - The socket address to bind RTP media to
§Examples
use rvoip_client_core::client::config::ClientConfig;
 
// Use same address for SIP and media
let addr = "192.168.1.100:0".parse().unwrap();
let config = ClientConfig::new()
    .with_sip_addr(addr)
    .with_media_addr(addr);
 
assert_eq!(config.local_sip_addr.ip(), config.local_media_addr.ip());
 
// Use different addresses (advanced networking)
let config2 = ClientConfig::new()
    .with_sip_addr("10.0.0.100:5060".parse().unwrap())
    .with_media_addr("192.168.1.100:0".parse().unwrap());
 
assert_ne!(config2.local_sip_addr.ip(), config2.local_media_addr.ip());
Source

pub fn with_user_agent(self, user_agent: String) -> Self

Set the User-Agent string for SIP identification

The User-Agent header identifies the client software in SIP messages. It’s helpful for debugging and server-side logging.

§Arguments
  • user_agent - String identifying the client application
§Examples
use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_user_agent("MyVoIPApp/2.1.0".to_string());
 
assert_eq!(config.user_agent, "MyVoIPApp/2.1.0");
 
// Enterprise naming convention
let enterprise_config = ClientConfig::new()
    .with_user_agent("CorporatePhone/1.0 (Build 12345)".to_string());
 
assert!(enterprise_config.user_agent.contains("CorporatePhone"));
assert!(enterprise_config.user_agent.contains("Build"));
Source

pub fn with_codecs(self, codecs: Vec<String>) -> Self

Set preferred audio codecs (convenience method)

This is a convenience method that sets the preferred codec list in the media configuration. Codecs are tried in the order specified.

§Arguments
  • codecs - Vector of codec names in order of preference
§Examples
use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_codecs(vec![
        "opus".to_string(),
        "G722".to_string(),
        "PCMU".to_string()
    ]);
 
assert_eq!(config.media.preferred_codecs[0], "opus");
assert_eq!(config.media.preferred_codecs[1], "G722");
assert_eq!(config.media.preferred_codecs[2], "PCMU");
assert_eq!(config.media.preferred_codecs.len(), 3);
Source

pub fn with_media(self, media: MediaConfig) -> Self

Set complete media configuration

Replaces the entire media configuration with a custom MediaConfig. This provides full control over all media-related settings.

§Arguments
  • media - Custom MediaConfig with desired settings
§Examples
use rvoip_client_core::client::config::{ClientConfig, MediaConfig};
use std::collections::HashMap;
 
let custom_media = MediaConfig {
    preferred_codecs: vec!["opus".to_string()],
    echo_cancellation: false,
    noise_suppression: true,
    auto_gain_control: true,
    max_bandwidth_kbps: Some(64),
    require_srtp: true,
    srtp_profiles: vec!["AES_CM_128_HMAC_SHA1_80".to_string()],
    rtp_port_start: 20000,
    rtp_port_end: 30000,
    preferred_ptime: Some(40),
    custom_sdp_attributes: HashMap::new(),
    dtmf_enabled: true,
};
 
let config = ClientConfig::new().with_media(custom_media);
 
assert!(!config.media.echo_cancellation);
assert!(config.media.require_srtp);
assert_eq!(config.media.max_bandwidth_kbps, Some(64));
assert_eq!(config.media.rtp_port_start, 20000);
Source

pub fn with_media_preset(self, preset: MediaPreset) -> Self

Set media configuration using a preset

Applies a predefined media configuration optimized for specific use cases. This is a convenience method that replaces the current media config with one generated from the specified preset.

§Arguments
  • preset - MediaPreset to use for configuration
§Examples
use rvoip_client_core::client::config::{ClientConfig, MediaPreset};
 
// Voice-optimized for phone calls
let voice_config = ClientConfig::new()
    .with_media_preset(MediaPreset::VoiceOptimized);
 
assert!(voice_config.media.echo_cancellation);
assert!(voice_config.media.noise_suppression);
 
// Low bandwidth for mobile
let mobile_config = ClientConfig::new()
    .with_media_preset(MediaPreset::LowBandwidth);
 
assert_eq!(mobile_config.media.max_bandwidth_kbps, Some(32));
 
// Secure for enterprise
let secure_config = ClientConfig::new()
    .with_media_preset(MediaPreset::Secure);
 
assert!(secure_config.media.require_srtp);
Source

pub fn with_max_calls(self, max_calls: usize) -> Self

Set maximum number of concurrent calls

Configures the maximum number of calls that can be active simultaneously. This helps with resource management and prevents overloading the client.

§Arguments
  • max_calls - Maximum number of concurrent calls (must be > 0)
§Examples
use rvoip_client_core::client::config::ClientConfig;
 
// Single-line phone
let single_line = ClientConfig::new().with_max_calls(1);
assert_eq!(single_line.max_concurrent_calls, 1);
 
// Small office setup
let office_phone = ClientConfig::new().with_max_calls(5);
assert_eq!(office_phone.max_concurrent_calls, 5);
 
// Call center agent
let call_center = ClientConfig::new().with_max_calls(20);
assert_eq!(call_center.max_concurrent_calls, 20);
 
// Enterprise server
let enterprise = ClientConfig::new().with_max_calls(100);
assert_eq!(enterprise.max_concurrent_calls, 100);
Source

pub fn preferred_codecs(&self) -> &[String]

Get the preferred codecs list (backwards compatibility)

Returns a slice of the preferred codec names in order of preference. This is a convenience method that provides direct access to the codec list without going through the media configuration.

§Returns

A slice containing codec names in preference order

§Examples
use rvoip_client_core::client::config::ClientConfig;
 
let config = ClientConfig::new()
    .with_codecs(vec![
        "opus".to_string(),
        "G722".to_string(),
        "PCMU".to_string()
    ]);
 
let codecs = config.preferred_codecs();
assert_eq!(codecs.len(), 3);
assert_eq!(codecs[0], "opus");
assert_eq!(codecs[1], "G722");
assert_eq!(codecs[2], "PCMU");
 
// Check for specific codec support
assert!(codecs.contains(&"opus".to_string()));
assert!(!codecs.contains(&"G729".to_string()));

Trait Implementations§

Source§

impl Clone for ClientConfig

Source§

fn clone(&self) -> ClientConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ClientConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ClientConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<'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> 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> SipJson for T

Source§

fn to_sip_value(&self) -> Result<SipValue, SipJsonError>

Convert this type to a SipValue. Read more
Source§

fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>

Create this type from a SipValue. Read more
Source§

impl<T> SipJsonExt for T

Source§

fn path(&self, path: impl AsRef<str>) -> Option<SipValue>

Simple path accessor that returns an Option directly

Source§

fn path_str(&self, path: impl AsRef<str>) -> Option<String>

Get a string value at the given path

Source§

fn path_str_or(&self, path: impl AsRef<str>, default: &str) -> String

Get a string value at the given path, or return the default value if not found

Source§

fn to_sip_value(&self) -> Result<SipValue, SipJsonError>

Convert to a SipValue. Read more
Source§

fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>

Convert from a SipValue. Read more
Source§

fn get_path(&self, path: impl AsRef<str>) -> SipValue

Access a value via path notation (e.g., “headers.from.tag”). Read more
Source§

fn path_accessor(&self) -> PathAccessor

Get a PathAccessor for chained access to fields. Read more
Source§

fn query(&self, query_str: impl AsRef<str>) -> Vec<SipValue>

Query for values using a JSONPath-like syntax. Read more
Source§

fn to_json_string(&self) -> Result<String, SipJsonError>

Convert to a JSON string. Read more
Source§

fn to_json_string_pretty(&self) -> Result<String, SipJsonError>

Convert to a pretty-printed JSON string. Read more
Source§

fn from_json_str(json_str: &str) -> Result<T, SipJsonError>

Create from a JSON string. Read more
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

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> SipMessageJson for T
where T: SipJsonExt,