Module common

Source
Expand description

Common API Types

This module provides shared types and handles used across the dialog-core API, offering convenient access to dialog operations and events.

§Overview

The common types provide high-level abstractions over SIP dialogs and calls:

  • DialogHandle: General-purpose dialog operations and state management
  • CallHandle: Call-specific operations built on top of DialogHandle
  • CallInfo: Information about active calls
  • DialogEvent: Events that can be monitored by applications

§Quick Start

§Using DialogHandle

use rvoip_dialog_core::api::common::DialogHandle;
use rvoip_sip_core::Method;

// Send a request within the dialog
let tx_key = dialog.send_request(Method::Info, Some("Hello".to_string())).await?;
println!("Sent INFO request: {}", tx_key);

// Check dialog state
let state = dialog.state().await?;
println!("Dialog state: {:?}", state);

// Send BYE to terminate
dialog.send_bye().await?;

§Using CallHandle

use rvoip_dialog_core::api::common::CallHandle;

// Get call information
let info = call.info().await?;
println!("Call from {} to {}", info.local_uri, info.remote_uri);

// Put call on hold
call.hold(Some("SDP with hold attributes".to_string())).await?;

// Transfer the call
call.transfer("sip:voicemail@example.com".to_string()).await?;

// Hang up
call.hangup().await?;

§Handle Architecture

CallHandle
    │
    └── DialogHandle
            │
            └── DialogManager
                    │
                    └── Dialog (actual state)

CallHandle provides call-specific operations while DialogHandle provides general dialog operations. Both are lightweight wrappers that delegate to the underlying DialogManager.

§Event Monitoring

Applications can monitor dialog events for state changes:

use rvoip_dialog_core::api::common::DialogEvent;

fn handle_dialog_event(event: DialogEvent) {
    match event {
        DialogEvent::Created { dialog_id } => {
            println!("New dialog: {}", dialog_id);
        },
        DialogEvent::StateChanged { dialog_id, old_state, new_state } => {
            println!("Dialog {} changed from {:?} to {:?}", dialog_id, old_state, new_state);
        },
        DialogEvent::Terminated { dialog_id, reason } => {
            println!("Dialog {} terminated: {}", dialog_id, reason);
        },
        _ => {}
    }
}

Structs§

CallHandle
A handle to a SIP call (specific type of dialog) for call-related operations
CallInfo
Information about a call
DialogHandle
A handle to a SIP dialog for convenient operations

Enums§

DialogEvent
Dialog events that applications can listen for