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