Skip to main content

moqtap_client/draft11/
event.rs

1//! Client event types emitted by a draft-11 MoQT connection.
2
3use moqtap_codec::dispatch::{
4    AnyControlMessage, AnyDatagramHeader, AnyFetchHeader, AnySubgroupHeader,
5};
6use moqtap_codec::draft11::data_stream::{FetchObjectHeader, ObjectHeader};
7
8/// Direction of a message or stream relative to this endpoint.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Direction {
11    /// Sent (outgoing).
12    Send,
13    /// Received (incoming).
14    Receive,
15}
16
17/// Data stream type.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum StreamKind {
20    /// Subgroup data stream.
21    Subgroup,
22    /// Fetch data stream.
23    Fetch,
24    /// Datagram.
25    Datagram,
26}
27
28/// A decoded subgroup object: the object header followed by its payload.
29///
30/// Draft-11 subgroup objects may carry per-object extension headers; the
31/// payload captured here is the object body that follows the header.
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct SubgroupObject {
34    /// The parsed object header.
35    pub header: ObjectHeader,
36    /// The object payload (empty when `header.payload_length == 0`).
37    pub payload: Vec<u8>,
38}
39
40/// A decoded fetch stream object: the object header followed by its payload.
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub struct FetchObject {
43    /// The parsed fetch object header.
44    pub header: FetchObjectHeader,
45    /// The object payload (empty when `header.payload_length == 0`).
46    pub payload: Vec<u8>,
47}
48
49/// Events emitted by a draft-11 MoQT connection.
50///
51/// This enum is `#[non_exhaustive]` — new variants may be added in minor
52/// releases. Downstream `match` arms should include a wildcard `_ =>` branch.
53#[non_exhaustive]
54#[derive(Debug, Clone)]
55pub enum ClientEvent {
56    /// MoQT setup handshake completed.
57    SetupComplete {
58        /// The negotiated MoQT version.
59        negotiated_version: u64,
60    },
61
62    /// A control message was sent or received.
63    ControlMessage {
64        /// Whether the message was sent or received.
65        direction: Direction,
66        /// The decoded control message.
67        message: AnyControlMessage,
68        /// The raw wire bytes of the framed message (type + length + payload).
69        /// `None` if raw capture is not available.
70        raw: Option<Vec<u8>>,
71    },
72
73    /// A data stream was opened.
74    StreamOpened {
75        /// Whether we opened (Send) or accepted (Receive) the stream.
76        direction: Direction,
77        /// The type of data stream.
78        stream_kind: StreamKind,
79        /// Transport-level stream identifier.
80        stream_id: u64,
81    },
82
83    /// A subgroup stream header was decoded after the stream opened.
84    DataStreamHeader {
85        /// Transport-level stream identifier.
86        stream_id: u64,
87        /// Whether we opened (Send) or accepted (Receive) the stream.
88        direction: Direction,
89        /// The parsed subgroup header.
90        header: AnySubgroupHeader,
91    },
92
93    /// A fetch response stream header was decoded.
94    FetchStreamHeader {
95        /// Transport-level stream identifier.
96        stream_id: u64,
97        /// Whether we opened (Send) or accepted (Receive) the stream.
98        direction: Direction,
99        /// The parsed fetch header.
100        header: AnyFetchHeader,
101    },
102
103    /// A subgroup object (header + payload) was decoded on a subgroup stream.
104    SubgroupObjectReceived {
105        /// Transport-level stream identifier.
106        stream_id: u64,
107        /// Direction (Send when emitted from a writer, Receive from a reader).
108        direction: Direction,
109        /// The decoded subgroup object.
110        object: SubgroupObject,
111    },
112
113    /// A fetch object (self-contained) was decoded on a fetch stream.
114    FetchObjectReceived {
115        /// Transport-level stream identifier.
116        stream_id: u64,
117        /// Direction (Send when emitted from a writer, Receive from a reader).
118        direction: Direction,
119        /// The decoded fetch object.
120        object: FetchObject,
121    },
122
123    /// A datagram was sent or received.
124    DatagramReceived {
125        /// Whether sent or received.
126        direction: Direction,
127        /// The parsed datagram header.
128        header: AnyDatagramHeader,
129        /// Size of the payload in bytes.
130        payload_len: usize,
131    },
132
133    /// A data stream was closed.
134    StreamClosed {
135        /// Transport-level stream identifier.
136        stream_id: u64,
137        /// Error code (0 = clean close).
138        error_code: u64,
139    },
140
141    /// Session entered draining state (GOAWAY received).
142    Draining {
143        /// The new session URI from the GOAWAY message.
144        new_session_uri: Vec<u8>,
145    },
146
147    /// Connection was closed.
148    Closed {
149        /// Application error code.
150        code: u32,
151        /// Human-readable reason.
152        reason: Vec<u8>,
153    },
154
155    /// A transport or protocol error occurred.
156    Error {
157        /// Error description.
158        error: String,
159    },
160}