Struct DialogServer

Source
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

Source

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

Source

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

Source

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 manager
  • transaction_events - Global transaction event receiver
  • config - Server configuration
§Returns

A configured DialogServer ready to start

Source

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 manager
  • config - Server configuration
§Returns

A configured DialogServer ready to start

Source

pub fn config(&self) -> &ServerConfig

Get server configuration

Source§

impl DialogServer

Call operation implementations for DialogServer

Source

pub async fn handle_invite( &self, request: Request, source: SocketAddr, ) -> ApiResult<CallHandle>

Handle an incoming INVITE request

This is typically called automatically when INVITEs are received, but can also be called manually for testing or custom routing.

§Arguments
  • request - The INVITE request
  • source - Source address of the request
§Returns

A CallHandle for managing the call

Source

pub async fn accept_call( &self, dialog_id: &DialogId, sdp_answer: Option<String>, ) -> ApiResult<()>

Accept an incoming call

Sends a 200 OK response to an INVITE request.

§Arguments
  • dialog_id - The dialog ID for the call
  • sdp_answer - Optional SDP answer for media negotiation
§Returns

Success or error

Source

pub async fn reject_call( &self, dialog_id: &DialogId, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>

Reject an incoming call

Sends an error response to an INVITE request.

§Arguments
  • dialog_id - The dialog ID for the call
  • status_code - SIP status code for rejection
  • reason - Optional reason phrase
§Returns

Success or error

Source

pub async fn terminate_call(&self, dialog_id: &DialogId) -> ApiResult<()>

Terminate a call

Sends a BYE request to end an active call.

§Arguments
  • dialog_id - The dialog ID for the call
§Returns

Success or error

Source§

impl DialogServer

Dialog operation implementations for DialogServer

Source

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 within
  • method - SIP method to send (BYE, REFER, NOTIFY, etc.)
  • body - Optional message body
§Returns

Transaction key for tracking the request

Source

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

Source

pub async fn get_dialog_info(&self, dialog_id: &DialogId) -> ApiResult<Dialog>

Get detailed information about a dialog

Provides access to the complete dialog state for session coordination and monitoring purposes.

§Arguments
  • dialog_id - The dialog ID to query
§Returns

Complete dialog information

Source

pub async fn get_dialog_state( &self, dialog_id: &DialogId, ) -> ApiResult<DialogState>

Get the current state of a dialog

Provides quick access to dialog state without retrieving the full dialog information.

§Arguments
  • dialog_id - The dialog ID to query
§Returns

Current dialog state

Source

pub async fn terminate_dialog(&self, dialog_id: &DialogId) -> ApiResult<()>

Terminate a dialog and clean up resources

This method provides direct control over dialog termination, which is essential for session lifecycle management.

§Arguments
  • dialog_id - The dialog ID to terminate
§Returns

Success or error

Source

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

Source

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

Source

pub async fn send_response( &self, transaction_id: &TransactionKey, response: Response, ) -> ApiResult<()>

Send a SIP response for a transaction

Provides direct control over response generation, which is essential for custom response handling in session coordination.

§Arguments
  • transaction_id - Transaction to respond to
  • response - Complete SIP response
§Returns

Success or error

Source§

impl DialogServer

Response building implementations for DialogServer

Source

pub async fn send_simple_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, _reason: Option<String>, ) -> ApiResult<()>

Build a simple SIP response

Creates a basic SIP response for the given transaction.

§Arguments
  • transaction_id - Transaction to respond to
  • status_code - SIP status code
  • _reason - Optional custom reason phrase (unused for now)
§Returns

Success or error

Source

pub async fn send_status_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>

Send a status response with optional reason phrase

Convenience method for sending simple status responses.

§Arguments
  • transaction_id - Transaction to respond to
  • status_code - SIP status code
  • reason - Optional custom reason phrase
§Returns

Success or error

Source

pub async fn send_trying_response( &self, transaction_id: &TransactionKey, ) -> ApiResult<()>

Send a 100 Trying response

Standard provisional response to indicate request processing.

§Arguments
  • transaction_id - Transaction to respond to
§Returns

Success or error

Source

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 to
  • dialog_id - Optional dialog context for early dialog creation
  • early_media_sdp - Optional SDP for early media
  • contact_uri - Optional Contact header value
§Returns

Success or error

Source

pub async fn send_ok_invite_response( &self, transaction_id: &TransactionKey, dialog_id: Option<&DialogId>, sdp_answer: String, contact_uri: String, ) -> ApiResult<()>

Send a 200 OK response to INVITE

Successful response indicating call acceptance.

§Arguments
  • transaction_id - Transaction to respond to
  • dialog_id - Optional dialog context
  • sdp_answer - SDP answer for media negotiation
  • contact_uri - Contact URI for the dialog
§Returns

Success or error

Source

pub async fn send_invite_error_response( &self, transaction_id: &TransactionKey, status_code: StatusCode, reason: Option<String>, ) -> ApiResult<()>

Send an error response to INVITE

Negative response indicating call rejection or failure.

§Arguments
  • transaction_id - Transaction to respond to
  • status_code - Error status code (4xx, 5xx, 6xx)
  • reason - Optional custom reason phrase
§Returns

Success or error

Source§

impl DialogServer

Specialized SIP method implementations for DialogServer

Source

pub async fn send_bye(&self, dialog_id: &DialogId) -> ApiResult<TransactionKey>

Send a BYE request to terminate a dialog

Sends a BYE request within the specified dialog to terminate the call.

§Arguments
  • dialog_id - The dialog to send BYE within
§Returns

Transaction key for tracking the BYE request

Source

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 within
  • target_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

Source

pub async fn send_notify( &self, dialog_id: &DialogId, event: String, body: Option<String>, ) -> ApiResult<TransactionKey>

Send a NOTIFY request for event notification

Implements event notification according to RFC 6665.

§Arguments
  • dialog_id - The dialog to send NOTIFY within
  • event - Event type (Event header value)
  • body - Optional notification body
§Returns

Transaction key for tracking the NOTIFY request

Source

pub async fn send_update( &self, dialog_id: &DialogId, sdp: Option<String>, ) -> ApiResult<TransactionKey>

Send an UPDATE request for session modification

Implements session modification according to RFC 3311.

§Arguments
  • dialog_id - The dialog to send UPDATE within
  • sdp - Optional SDP for session modification
§Returns

Transaction key for tracking the UPDATE request

Source

pub async fn send_info( &self, dialog_id: &DialogId, info_body: String, ) -> ApiResult<TransactionKey>

Send an INFO request for application information

Implements application-level information exchange according to RFC 6086.

§Arguments
  • dialog_id - The dialog to send INFO within
  • info_body - Information payload
§Returns

Transaction key for tracking the INFO request

Trait Implementations§

Source§

impl DialogApi for DialogServer

Implementation of DialogApi trait

Source§

fn dialog_manager(&self) -> &Arc<DialogManager>

Get access to the underlying dialog manager Read more
Source§

async fn set_session_coordinator( &self, sender: Sender<SessionCoordinationEvent>, ) -> ApiResult<()>

Set session coordinator for communication with session-core Read more
Source§

async fn start(&self) -> ApiResult<()>

Start the dialog API Read more
Source§

async fn stop(&self) -> ApiResult<()>

Stop the dialog API Read more
Source§

async fn get_stats(&self) -> DialogStats

Get statistics for this API instance 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<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> 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, 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> ErasedDestructor for T
where T: 'static,