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: SocketAddrLocal SIP bind address
local_media_addr: SocketAddrLocal media bind address
user_agent: StringUser agent string
media: MediaConfigMedia configuration
max_concurrent_calls: usizeMaximum number of concurrent calls
session_timeout_secs: u64Session timeout in seconds
enable_audio: boolEnable audio processing
enable_video: boolEnable video processing (future)
domain: Option<String>SIP domain (optional)
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new() -> Self
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);Sourcepub fn with_sip_addr(self, addr: SocketAddr) -> Self
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);Sourcepub fn with_media_addr(self, addr: SocketAddr) -> Self
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());Sourcepub fn with_user_agent(self, user_agent: String) -> Self
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"));Sourcepub fn with_codecs(self, codecs: Vec<String>) -> Self
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);Sourcepub fn with_media(self, media: MediaConfig) -> Self
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);Sourcepub fn with_media_preset(self, preset: MediaPreset) -> Self
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);Sourcepub fn with_max_calls(self, max_calls: usize) -> Self
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);Sourcepub fn preferred_codecs(&self) -> &[String]
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
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientConfig
impl Debug for ClientConfig
Source§impl Default for ClientConfig
impl Default for ClientConfig
Source§impl<'de> Deserialize<'de> for ClientConfig
impl<'de> Deserialize<'de> for ClientConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ClientConfig
impl RefUnwindSafe for ClientConfig
impl Send for ClientConfig
impl Sync for ClientConfig
impl Unpin for ClientConfig
impl UnwindSafe for ClientConfig
Blanket Implementations§
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<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> SipJson for Twhere
T: Serialize + DeserializeOwned,
impl<T> SipJson for Twhere
T: Serialize + DeserializeOwned,
Source§fn to_sip_value(&self) -> Result<SipValue, SipJsonError>
fn to_sip_value(&self) -> Result<SipValue, SipJsonError>
Source§fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>
fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>
Source§impl<T> SipJsonExt for T
impl<T> SipJsonExt for T
Source§fn path(&self, path: impl AsRef<str>) -> Option<SipValue>
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>
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
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