Module unified

Source
Expand description

Unified API for DialogManager

This module provides a unified, high-level API that replaces the separate DialogClient and DialogServer APIs with a single, comprehensive interface. The behavior is determined by the DialogManagerConfig provided during construction.

§Overview

The unified API eliminates the artificial client/server split while maintaining all functionality from both previous APIs. The UnifiedDialogApi provides:

  • All Client Operations: make_call, outgoing dialog creation, authentication
  • All Server Operations: handle_invite, auto-responses, incoming call handling
  • All Shared Operations: Dialog management, response building, SIP method helpers
  • Session Coordination: Integration with session-core for media management
  • Statistics & Monitoring: Comprehensive metrics and dialog state tracking

§Architecture

UnifiedDialogApi
       │
       ├── Configuration-based behavior
       │   ├── Client mode: make_call, create_dialog, auth
       │   ├── Server mode: handle_invite, auto-options, domain
       │   └── Hybrid mode: all operations available
       │
       ├── Shared operations (all modes)
       │   ├── Dialog management
       │   ├── Response building
       │   ├── SIP method helpers (BYE, REFER, etc.)
       │   └── Session coordination
       │
       └── Convenience handles
           ├── DialogHandle (dialog operations)
           └── CallHandle (call-specific operations)

§Examples

§Client Mode Usage

use rvoip_dialog_core::api::unified::UnifiedDialogApi;
use rvoip_dialog_core::config::DialogManagerConfig;

let config = DialogManagerConfig::client("127.0.0.1:0".parse()?)
    .with_from_uri("sip:alice@example.com")
    .with_auth("alice", "secret123")
    .build();

let api = UnifiedDialogApi::new(transaction_manager, config).await?;
api.start().await?;

// Make outgoing calls
let call = api.make_call(
    "sip:alice@example.com",
    "sip:bob@example.com",
    Some("SDP offer".to_string())
).await?;

// Use call operations
call.hold(Some("SDP with hold".to_string())).await?;
call.transfer("sip:voicemail@example.com".to_string()).await?;
call.hangup().await?;

§Server Mode Usage

use rvoip_dialog_core::api::unified::UnifiedDialogApi;
use rvoip_dialog_core::config::DialogManagerConfig;
use rvoip_dialog_core::events::SessionCoordinationEvent;

let config = DialogManagerConfig::server("0.0.0.0:5060".parse()?)
    .with_domain("sip.company.com")
    .with_auto_options()
    .build();

let api = UnifiedDialogApi::new(transaction_manager, config).await?;

// Set up session coordination
let (session_tx, mut session_rx) = tokio::sync::mpsc::channel(100);
api.set_session_coordinator(session_tx).await?;
api.start().await?;

// Handle incoming calls
tokio::spawn(async move {
    while let Some(event) = session_rx.recv().await {
        match event {
            SessionCoordinationEvent::IncomingCall { dialog_id, request, .. } => {
                // Handle the incoming call
                if let Ok(call) = api.handle_invite(request, source_addr).await {
                    call.answer(Some("SDP answer".to_string())).await.ok();
                }
            },
            _ => {}
        }
    }
});

§Hybrid Mode Usage

use rvoip_dialog_core::api::unified::UnifiedDialogApi;
use rvoip_dialog_core::config::DialogManagerConfig;

let config = DialogManagerConfig::hybrid("192.168.1.100:5060".parse()?)
    .with_from_uri("sip:pbx@company.com")
    .with_domain("company.com")
    .with_auth("pbx", "pbx_password")
    .with_auto_options()
    .build();

let api = UnifiedDialogApi::new(transaction_manager, config).await?;
api.start().await?;

// Can both make outgoing calls AND handle incoming calls
let outgoing_call = api.make_call(
    "sip:pbx@company.com",
    "sip:external@provider.com",
    None
).await?;

// Also handles incoming calls via session coordination

Structs§

UnifiedDialogApi
Unified Dialog API