pub struct EventRouter { /* private fields */ }Expand description
Routes events from HTTP callbacks to a channel.
The EventRouter maintains a set of active subscription IDs. When an event
is received via HTTP callback, the router checks if the subscription is
registered and sends the notification payload to the configured channel.
Implementations§
Source§impl EventRouter
impl EventRouter
Sourcepub fn new(event_sender: UnboundedSender<NotificationPayload>) -> Self
pub fn new(event_sender: UnboundedSender<NotificationPayload>) -> Self
Sourcepub async fn register(&self, subscription_id: String)
pub async fn register(&self, subscription_id: String)
Register a subscription ID for event routing.
This adds the subscription ID to the set of active subscriptions, allowing incoming events for this subscription to be routed.
§Arguments
subscription_id- The UPnP subscription ID to register
§Example
router.register("uuid:subscription-123".to_string()).await;Sourcepub async fn unregister(&self, subscription_id: &str)
pub async fn unregister(&self, subscription_id: &str)
Sourcepub async fn route_event(
&self,
subscription_id: String,
event_xml: String,
) -> bool
pub async fn route_event( &self, subscription_id: String, event_xml: String, ) -> bool
Route an incoming event to the unified event stream.
This method is the core of the unified event stream processing pattern.
It checks if the subscription ID is registered and sends a NotificationPayload
to the configured channel for further processing by the event stream processor.
The unified approach means that all events from all speakers and services flow through this single routing point, enabling efficient aggregation and processing.
§Arguments
subscription_id- The subscription ID from the UPnP SID headerevent_xml- The raw XML event body from the UPnP notification
§Returns
Returns true if the event was successfully routed to the unified stream,
false if the subscription ID was not registered.
§Unified Event Processing
This method enables the unified event stream processor pattern by:
- Validating that the subscription is registered and active
- Creating a generic notification payload with subscription context
- Forwarding to the unified event stream for service-specific processing
- Allowing downstream components to add speaker and service context
§Example
let routed = router.route_event(
"uuid:subscription-123".to_string(),
"<event>data</event>".to_string()
).await;
assert!(routed);Trait Implementations§
Source§impl Clone for EventRouter
impl Clone for EventRouter
Source§fn clone(&self) -> EventRouter
fn clone(&self) -> EventRouter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more