pub struct EventSubscription { /* private fields */ }Expand description
Enhanced event subscription with filtering capabilities
Represents a subscription to client events with optional filtering. Subscriptions determine which events are delivered to which handlers.
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct TestHandler;
#[async_trait]
impl ClientEventHandler for TestHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(TestHandler);
let subscription = EventSubscription::all_events(handler);Implementations§
Source§impl EventSubscription
impl EventSubscription
Sourcepub fn new(handler: Arc<dyn ClientEventHandler>, filter: EventFilter) -> Self
pub fn new(handler: Arc<dyn ClientEventHandler>, filter: EventFilter) -> Self
Create a new event subscription with filtering
Creates a subscription that will deliver events matching the specified filter criteria to the provided handler.
§Arguments
handler- The event handler that will receive matching eventsfilter- Filter criteria to determine which events to receive
§Examples
use rvoip_client_core::events::{EventSubscription, EventFilter, EventPriority, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct TestHandler;
#[async_trait]
impl ClientEventHandler for TestHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(TestHandler);
let filter = EventFilter {
min_priority: Some(EventPriority::High),
call_ids: None,
call_states: None,
media_event_types: None,
registration_ids: None,
};
let subscription = EventSubscription::new(handler, filter);Sourcepub fn all_events(handler: Arc<dyn ClientEventHandler>) -> Self
pub fn all_events(handler: Arc<dyn ClientEventHandler>) -> Self
Create a subscription that receives all events
Creates a subscription with no filtering - all events will be delivered to the handler.
§Arguments
handler- The event handler that will receive all events
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct AllEventsHandler;
#[async_trait]
impl ClientEventHandler for AllEventsHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(AllEventsHandler);
let subscription = EventSubscription::all_events(handler);Sourcepub fn call_events(
handler: Arc<dyn ClientEventHandler>,
call_id: CallId,
) -> Self
pub fn call_events( handler: Arc<dyn ClientEventHandler>, call_id: CallId, ) -> Self
Create a subscription for specific call events only
Creates a subscription that only receives events related to a specific call ID.
§Arguments
handler- The event handler that will receive call eventscall_id- The specific call ID to monitor
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use rvoip_client_core::call::CallId;
use async_trait::async_trait;
use std::sync::Arc;
struct CallSpecificHandler;
#[async_trait]
impl ClientEventHandler for CallSpecificHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(CallSpecificHandler);
let call_id = uuid::Uuid::new_v4();
let subscription = EventSubscription::call_events(handler, call_id);Sourcepub fn high_priority_events(handler: Arc<dyn ClientEventHandler>) -> Self
pub fn high_priority_events(handler: Arc<dyn ClientEventHandler>) -> Self
Create a subscription for high priority events only
Creates a subscription that only receives high and critical priority events, filtering out normal and low priority events.
§Arguments
handler- The event handler that will receive high priority events
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct HighPriorityHandler;
#[async_trait]
impl ClientEventHandler for HighPriorityHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(HighPriorityHandler);
let subscription = EventSubscription::high_priority_events(handler);Sourcepub fn id(&self) -> Uuid
pub fn id(&self) -> Uuid
Get the subscription ID
Returns the unique identifier for this subscription, which can be used to unsubscribe later.
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct TestHandler;
#[async_trait]
impl ClientEventHandler for TestHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(TestHandler);
let subscription = EventSubscription::all_events(handler);
let id = subscription.id();
println!("Subscription ID: {}", id);Sourcepub fn should_receive(&self, event: &ClientEvent) -> bool
pub fn should_receive(&self, event: &ClientEvent) -> bool
Check if this subscription should receive the given event
Tests whether the event matches this subscription’s filter criteria.
§Arguments
event- The event to test against the filter
§Returns
true if the event should be delivered to this subscription’s handler
§Examples
use rvoip_client_core::events::{EventSubscription, ClientEvent, EventPriority, ClientEventHandler, IncomingCallInfo, CallAction, CallStatusInfo, RegistrationStatusInfo};
use async_trait::async_trait;
use std::sync::Arc;
struct TestHandler;
#[async_trait]
impl ClientEventHandler for TestHandler {
async fn on_incoming_call(&self, _call_info: IncomingCallInfo) -> CallAction {
CallAction::Accept
}
async fn on_call_state_changed(&self, _status_info: CallStatusInfo) {}
async fn on_registration_status_changed(&self, _status_info: RegistrationStatusInfo) {}
}
let handler = Arc::new(TestHandler);
let subscription = EventSubscription::high_priority_events(handler);
let high_priority_event = ClientEvent::NetworkEvent {
connected: false,
reason: Some("Connection lost".to_string()),
priority: EventPriority::High,
};
assert!(subscription.should_receive(&high_priority_event));Sourcepub async fn deliver_event(&self, event: ClientEvent)
pub async fn deliver_event(&self, event: ClientEvent)
Deliver an event to this subscription’s handler
Delivers the event to the handler if it passes the subscription’s filter.
§Arguments
event- The event to potentially deliver