Skip to main content

Module events

Module events 

Source
Expand description

Event handling framework for Sonos UPnP services

This module provides a comprehensive event handling system that consolidates event processing logic from across the Sonos SDK. Each service handles its own event types and parsing logic, while this framework provides common infrastructure for event processing, routing, and management.

§Architecture

  • Service-specific events: Each service module (av_transport, rendering_control, etc.) defines its own event types and parsing logic in an events submodule
  • Common framework: This module provides generic event processing infrastructure
  • Type safety: Events are strongly typed per service while maintaining flexibility

§Usage

§Service-specific event handling

use sonos_api::services::av_transport;
use sonos_api::events::EventSource;

// Parse an AVTransport event
let parser = av_transport::events::AVTransportEventParser;
let event_data = parser.parse_upnp_event(xml_content)?;

// Create enriched event
let enriched = av_transport::events::create_enriched_event(
    speaker_ip,
    EventSource::UPnPNotification { subscription_id: "uuid:123".to_string() },
    event_data
);

§Generic event processing

use sonos_api::events::{EventParserRegistry, EventProcessor};

// Register parsers for all services
let mut registry = EventParserRegistry::new();
registry.register(av_transport::events::AVTransportEventParser);
registry.register(rendering_control::events::RenderingControlEventParser);

// Process events generically
let processor = EventProcessor::new(registry);
processor.process_event(service, xml_content, event_source)?;

Re-exports§

pub use processor::EventProcessor;
pub use types::extract_xml_value;
pub use types::EnrichedEvent;
pub use types::EventParser;
pub use types::EventParserDyn;
pub use types::EventParserRegistry;
pub use types::EventSource;
pub use xml_utils::deserialize_nested;
pub use xml_utils::parse;
pub use xml_utils::strip_namespaces;
pub use xml_utils::DidlItem;
pub use xml_utils::DidlLite;
pub use xml_utils::DidlResource;
pub use xml_utils::NestedAttribute;
pub use xml_utils::ValueAttribute;

Modules§

processor
Generic event processor for handling UPnP events across all services
types
Common event types and framework for Sonos UPnP events
xml_utils
XML parsing utilities for Sonos UPnP event processing.