moqtap_client/draft13/observer.rs
1//! Connection observer trait for receiving structured events.
2
3use crate::draft13::event::ClientEvent;
4
5/// Trait for receiving events from a MoQT connection.
6///
7/// Implementations must be `Send + Sync` because the connection may emit
8/// events from async tasks. The `on_event` method takes `&self` (not
9/// `&mut self`) -- implementations that need mutation should use interior
10/// mutability (e.g., `Mutex`, `mpsc::Sender`).
11///
12/// The callback is synchronous to keep the hot path simple. Implementations
13/// that need async processing should send to an internal channel.
14pub trait ConnectionObserver: Send + Sync {
15 /// Called when a connection event occurs.
16 fn on_event(&self, event: &ClientEvent);
17
18 /// Called with an owned event. Default implementation forwards to
19 /// `on_event(&event)`. Override to consume the event without cloning --
20 /// used by the cross-draft dispatch adapter to move the event directly
21 /// into its `AnyClientEvent` variant.
22 fn on_event_owned(&self, event: ClientEvent) {
23 self.on_event(&event);
24 }
25}
26
27/// A no-op observer that discards all events.
28pub struct NoOpObserver;
29
30impl ConnectionObserver for NoOpObserver {
31 fn on_event(&self, _event: &ClientEvent) {}
32}