pub struct DialogServer { /* private fields */ }
Expand description
High-level server interface for SIP dialog management
Provides a clean, intuitive API for server-side SIP operations including:
- Automatic INVITE handling
- Response generation
- Dialog lifecycle management
- Session coordination
- NEW: Dialog-level coordination for session-core integration
§Example Usage
use rvoip_dialog_core::api::{DialogServer, DialogApi};
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create server with simple configuration
let server = DialogServer::new("0.0.0.0:5060").await?;
// Set up session coordination
let (session_tx, session_rx) = mpsc::channel(100);
server.set_session_coordinator(session_tx).await?;
// Start processing SIP messages
server.start().await?;
Ok(())
}
Implementations§
Source§impl DialogServer
impl DialogServer
Sourcepub async fn new(local_address: &str) -> ApiResult<Self>
pub async fn new(local_address: &str) -> ApiResult<Self>
Create a new dialog server with simple configuration
This is the easiest way to create a server - just provide a local address and the server will be configured with sensible defaults.
§Arguments
local_address
- Address to bind to (e.g., “0.0.0.0:5060”)
§Returns
A configured DialogServer ready to start
Sourcepub async fn with_config(config: ServerConfig) -> ApiResult<Self>
pub async fn with_config(config: ServerConfig) -> ApiResult<Self>
Create a dialog server with custom configuration
ARCHITECTURAL NOTE: This method requires dependency injection to maintain proper separation of concerns. dialog-core should not directly manage transport concerns - that’s the responsibility of transaction-core.
Use with_global_events()
or with_dependencies()
instead, where you provide
a pre-configured TransactionManager that handles all transport setup.
§Arguments
config
- Server configuration (for validation and future use)
§Returns
An error directing users to the proper dependency injection constructors
Sourcepub async fn with_global_events(
transaction_manager: Arc<TransactionManager>,
transaction_events: Receiver<TransactionEvent>,
config: ServerConfig,
) -> ApiResult<Self>
pub async fn with_global_events( transaction_manager: Arc<TransactionManager>, transaction_events: Receiver<TransactionEvent>, config: ServerConfig, ) -> ApiResult<Self>
Create a dialog server with dependency injection and global events (RECOMMENDED)
This constructor follows the working pattern from transaction-core examples by using global transaction event subscription for proper event consumption.
§Arguments
transaction_manager
- Pre-configured transaction managertransaction_events
- Global transaction event receiverconfig
- Server configuration
§Returns
A configured DialogServer ready to start
Sourcepub async fn with_dependencies(
transaction_manager: Arc<TransactionManager>,
config: ServerConfig,
) -> ApiResult<Self>
pub async fn with_dependencies( transaction_manager: Arc<TransactionManager>, config: ServerConfig, ) -> ApiResult<Self>
Create a dialog server with dependency injection
Use this when you want full control over dependencies, particularly useful for testing or when integrating with existing infrastructure.
NOTE: This method still uses the old individual transaction subscription pattern.
For proper event consumption, use with_global_events()
instead.
§Arguments
transaction_manager
- Pre-configured transaction managerconfig
- Server configuration
§Returns
A configured DialogServer ready to start
Sourcepub fn config(&self) -> &ServerConfig
pub fn config(&self) -> &ServerConfig
Get server configuration
Source§impl DialogServer
Call operation implementations for DialogServer
impl DialogServer
Call operation implementations for DialogServer
Sourcepub async fn handle_invite(
&self,
request: Request,
source: SocketAddr,
) -> ApiResult<CallHandle>
pub async fn handle_invite( &self, request: Request, source: SocketAddr, ) -> ApiResult<CallHandle>
Sourcepub async fn accept_call(
&self,
dialog_id: &DialogId,
sdp_answer: Option<String>,
) -> ApiResult<()>
pub async fn accept_call( &self, dialog_id: &DialogId, sdp_answer: Option<String>, ) -> ApiResult<()>
Sourcepub async fn reject_call(
&self,
dialog_id: &DialogId,
status_code: StatusCode,
reason: Option<String>,
) -> ApiResult<()>
pub async fn reject_call( &self, dialog_id: &DialogId, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>
Source§impl DialogServer
Dialog operation implementations for DialogServer
impl DialogServer
Dialog operation implementations for DialogServer
Sourcepub async fn send_request_in_dialog(
&self,
dialog_id: &DialogId,
method: Method,
body: Option<Bytes>,
) -> ApiResult<TransactionKey>
pub async fn send_request_in_dialog( &self, dialog_id: &DialogId, method: Method, body: Option<Bytes>, ) -> ApiResult<TransactionKey>
Send a SIP request within an existing dialog
This method provides direct access to sending arbitrary SIP methods within established dialogs, which is essential for session-core coordination.
§Arguments
dialog_id
- The dialog ID to send the request withinmethod
- SIP method to send (BYE, REFER, NOTIFY, etc.)body
- Optional message body
§Returns
Transaction key for tracking the request
Sourcepub async fn create_outgoing_dialog(
&self,
local_uri: Uri,
remote_uri: Uri,
call_id: Option<String>,
) -> ApiResult<DialogId>
pub async fn create_outgoing_dialog( &self, local_uri: Uri, remote_uri: Uri, call_id: Option<String>, ) -> ApiResult<DialogId>
Create an outgoing dialog for client-initiated communications
This method allows session-core to create dialogs for outgoing calls and other client-initiated SIP operations.
§Arguments
local_uri
- Local URI (From header)remote_uri
- Remote URI (To header)call_id
- Optional Call-ID (will be generated if None)
§Returns
The created dialog ID
Sourcepub async fn get_dialog_info(&self, dialog_id: &DialogId) -> ApiResult<Dialog>
pub async fn get_dialog_info(&self, dialog_id: &DialogId) -> ApiResult<Dialog>
Sourcepub async fn get_dialog_state(
&self,
dialog_id: &DialogId,
) -> ApiResult<DialogState>
pub async fn get_dialog_state( &self, dialog_id: &DialogId, ) -> ApiResult<DialogState>
Sourcepub async fn terminate_dialog(&self, dialog_id: &DialogId) -> ApiResult<()>
pub async fn terminate_dialog(&self, dialog_id: &DialogId) -> ApiResult<()>
Sourcepub async fn list_active_dialogs(&self) -> Vec<DialogId>
pub async fn list_active_dialogs(&self) -> Vec<DialogId>
List all active dialog IDs
Provides access to all active dialogs for monitoring and management purposes.
§Returns
Vector of active dialog IDs
Sourcepub async fn active_calls(&self) -> Vec<DialogHandle>
pub async fn active_calls(&self) -> Vec<DialogHandle>
Get active calls as DialogHandles
Provides access to all active calls for management purposes.
§Returns
Vector of active call handles
Sourcepub async fn send_response(
&self,
transaction_id: &TransactionKey,
response: Response,
) -> ApiResult<()>
pub async fn send_response( &self, transaction_id: &TransactionKey, response: Response, ) -> ApiResult<()>
Source§impl DialogServer
Response building implementations for DialogServer
impl DialogServer
Response building implementations for DialogServer
Sourcepub async fn send_simple_response(
&self,
transaction_id: &TransactionKey,
status_code: StatusCode,
_reason: Option<String>,
) -> ApiResult<()>
pub async fn send_simple_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, _reason: Option<String>, ) -> ApiResult<()>
Sourcepub async fn send_status_response(
&self,
transaction_id: &TransactionKey,
status_code: StatusCode,
reason: Option<String>,
) -> ApiResult<()>
pub async fn send_status_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>
Sourcepub async fn send_trying_response(
&self,
transaction_id: &TransactionKey,
) -> ApiResult<()>
pub async fn send_trying_response( &self, transaction_id: &TransactionKey, ) -> ApiResult<()>
Sourcepub async fn send_ringing_response(
&self,
transaction_id: &TransactionKey,
dialog_id: Option<&DialogId>,
early_media_sdp: Option<String>,
contact_uri: Option<String>,
) -> ApiResult<()>
pub async fn send_ringing_response( &self, transaction_id: &TransactionKey, dialog_id: Option<&DialogId>, early_media_sdp: Option<String>, contact_uri: Option<String>, ) -> ApiResult<()>
Send a 180 Ringing response
Indicates that the user agent is alerting the user.
§Arguments
transaction_id
- Transaction to respond todialog_id
- Optional dialog context for early dialog creationearly_media_sdp
- Optional SDP for early mediacontact_uri
- Optional Contact header value
§Returns
Success or error
Sourcepub async fn send_ok_invite_response(
&self,
transaction_id: &TransactionKey,
dialog_id: Option<&DialogId>,
sdp_answer: String,
contact_uri: String,
) -> ApiResult<()>
pub async fn send_ok_invite_response( &self, transaction_id: &TransactionKey, dialog_id: Option<&DialogId>, sdp_answer: String, contact_uri: String, ) -> ApiResult<()>
Sourcepub async fn send_invite_error_response(
&self,
transaction_id: &TransactionKey,
status_code: StatusCode,
reason: Option<String>,
) -> ApiResult<()>
pub async fn send_invite_error_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>
Source§impl DialogServer
Specialized SIP method implementations for DialogServer
impl DialogServer
Specialized SIP method implementations for DialogServer
Sourcepub async fn send_bye(&self, dialog_id: &DialogId) -> ApiResult<TransactionKey>
pub async fn send_bye(&self, dialog_id: &DialogId) -> ApiResult<TransactionKey>
Sourcepub async fn send_refer(
&self,
dialog_id: &DialogId,
target_uri: String,
refer_body: Option<String>,
) -> ApiResult<TransactionKey>
pub async fn send_refer( &self, dialog_id: &DialogId, target_uri: String, refer_body: Option<String>, ) -> ApiResult<TransactionKey>
Send a REFER request for call transfer
Implements call transfer functionality according to RFC 3515.
§Arguments
dialog_id
- The dialog to send REFER withintarget_uri
- The URI to transfer the call to (Refer-To header)refer_body
- Optional REFER request body
§Returns
Transaction key for tracking the REFER request
Sourcepub async fn send_notify(
&self,
dialog_id: &DialogId,
event: String,
body: Option<String>,
) -> ApiResult<TransactionKey>
pub async fn send_notify( &self, dialog_id: &DialogId, event: String, body: Option<String>, ) -> ApiResult<TransactionKey>
Sourcepub async fn send_update(
&self,
dialog_id: &DialogId,
sdp: Option<String>,
) -> ApiResult<TransactionKey>
pub async fn send_update( &self, dialog_id: &DialogId, sdp: Option<String>, ) -> ApiResult<TransactionKey>
Trait Implementations§
Source§impl DialogApi for DialogServer
Implementation of DialogApi trait
impl DialogApi for DialogServer
Implementation of DialogApi trait