Trait ClientEventHandler

Source
pub trait ClientEventHandler: Send + Sync {
    // Required methods
    fn on_incoming_call<'life0, 'async_trait>(
        &'life0 self,
        call_info: IncomingCallInfo,
    ) -> Pin<Box<dyn Future<Output = CallAction> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_call_state_changed<'life0, 'async_trait>(
        &'life0 self,
        status_info: CallStatusInfo,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_registration_status_changed<'life0, 'async_trait>(
        &'life0 self,
        status_info: RegistrationStatusInfo,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_media_event<'life0, 'async_trait>(
        &'life0 self,
        _media_info: MediaEventInfo,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_client_error<'life0, 'async_trait>(
        &'life0 self,
        _error: ClientError,
        _call_id: Option<CallId>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_network_event<'life0, 'async_trait>(
        &'life0 self,
        _connected: bool,
        _reason: Option<String>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_client_event<'life0, 'async_trait>(
        &'life0 self,
        event: ClientEvent,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Enhanced event handler with filtering capabilities

Trait for handling VoIP client events. Implement this trait to receive and respond to various events that occur during client operation.

§Examples

use rvoip_client_core::events::{ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
 
struct LoggingEventHandler;
 
#[async_trait]
impl ClientEventHandler for LoggingEventHandler {
    async fn on_incoming_call(&self, call_info: IncomingCallInfo) -> CallAction {
        println!("Incoming call from: {}", call_info.caller_uri);
        CallAction::Accept
    }
 
    async fn on_call_state_changed(&self, status_info: CallStatusInfo) {
        println!("Call state changed: {:?}", status_info.new_state);
    }
 
    async fn on_registration_status_changed(&self, status_info: RegistrationStatusInfo) {
        println!("Registration status: {:?}", status_info.status);
    }
}

Required Methods§

Source

fn on_incoming_call<'life0, 'async_trait>( &'life0 self, call_info: IncomingCallInfo, ) -> Pin<Box<dyn Future<Output = CallAction> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle an incoming call with action decision

Called when a new call invitation is received. The implementation should return the desired action (Accept, Reject, or Ignore).

§Arguments
  • call_info - Information about the incoming call
§Returns

The action to take for this incoming call

Source

fn on_call_state_changed<'life0, 'async_trait>( &'life0 self, status_info: CallStatusInfo, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle call state changes

Called when a call’s state changes (e.g., from ringing to connected). This is useful for updating UI, logging, or triggering other actions.

§Arguments
  • status_info - Information about the call state change
Source

fn on_registration_status_changed<'life0, 'async_trait>( &'life0 self, status_info: RegistrationStatusInfo, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle registration status changes

Called when the SIP registration status changes with a server. This includes successful registrations, failures, and expirations.

§Arguments
  • status_info - Information about the registration status change

Provided Methods§

Source

fn on_media_event<'life0, 'async_trait>( &'life0 self, _media_info: MediaEventInfo, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle media events (optional - default implementation does nothing)

Called when media-related events occur during calls. Override this method to handle audio start/stop, quality changes, DTMF, etc.

§Arguments
  • media_info - Information about the media event
Source

fn on_client_error<'life0, 'async_trait>( &'life0 self, _error: ClientError, _call_id: Option<CallId>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle client errors (optional - default implementation logs)

Called when client errors occur. Override this method to implement custom error handling, logging, or recovery strategies.

§Arguments
  • error - The error that occurred
  • call_id - Call ID associated with the error (if any)
Source

fn on_network_event<'life0, 'async_trait>( &'life0 self, _connected: bool, _reason: Option<String>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle network events (optional - default implementation does nothing)

Called when network connectivity changes are detected. Override this method to handle connection state changes and implement reconnection logic.

§Arguments
  • connected - Whether the network is now connected
  • reason - Reason for the connectivity change (if known)
Source

fn on_client_event<'life0, 'async_trait>( &'life0 self, event: ClientEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle comprehensive client events with filtering

This is the unified event handler that dispatches to specific event handling methods. Generally, you don’t need to override this method unless you want custom event routing logic.

§Arguments
  • event - The client event to handle

Implementors§