scuffle_rtmp/messages/mod.rs
1//! Message types and definitions.
2
3use bytes::Bytes;
4
5use crate::command_messages::Command;
6use crate::protocol_control_messages::{
7 ProtocolControlMessageSetChunkSize, ProtocolControlMessageWindowAcknowledgementSize,
8};
9
10pub mod reader;
11
12/// Different types of messages that can be sent or received.
13///
14/// Defined by:
15/// - Legacy RTMP spec, 5.4
16#[derive(Debug)]
17pub enum MessageData<'a> {
18 // Protocol Control Messages
19 /// Set Chunk Size message
20 SetChunkSize(ProtocolControlMessageSetChunkSize),
21 /// Abort message
22 ///
23 /// Not implemented.
24 Abort,
25 /// Acknowledgement message
26 ///
27 /// Read not implemented.
28 Acknowledgement,
29 /// User Control Event message
30 ///
31 /// Not implemented.
32 UserControlEvent,
33 /// Set Acknowledgement Window Size message
34 SetAcknowledgementWindowSize(ProtocolControlMessageWindowAcknowledgementSize),
35 /// Set Peer Bandwidth message
36 ///
37 /// Read not implemented.
38 SetPeerBandwidth,
39
40 // RTMP Command Messages
41 /// Audio message
42 ///
43 /// > The client or the server sends this message to send audio data to the peer.
44 ///
45 /// Usually contains FLV AUDIODATA.
46 AudioData {
47 /// The audio data.
48 data: Bytes,
49 },
50 /// Video message
51 ///
52 /// > The client or the server sends this message to send video data to the peer.
53 ///
54 /// Usually contains FLV VIDEODATA.
55 VideoData {
56 /// The video data.
57 data: Bytes,
58 },
59 /// Amf3 metadata message
60 ///
61 /// Not implemented.
62 DataAmf3,
63 /// Amf3 shared object message
64 ///
65 /// Not implemented.
66 SharedObjAmf3,
67 /// Amf3 command message
68 ///
69 /// Not implemented.
70 CommandAmf3,
71 /// Amf0 metadata message
72 ///
73 /// > The client or the server sends this message to send Metadata or any
74 /// > user data to the peer. Metadata includes details about the
75 /// > data(audio, video etc.) like creation time, duration, theme and so on.
76 DataAmf0 {
77 /// The metadata.
78 data: Bytes,
79 },
80 /// Amf0 shared object message
81 ///
82 /// Not implemented.
83 SharedObjAmf0,
84 /// Amf0 command message
85 ///
86 /// > Command messages carry the AMF-encoded commands between the client and the server.
87 Amf0Command(Command<'a>),
88 /// Aggregate message
89 ///
90 /// Not implemented.
91 Aggregate,
92 /// Any other undefined messages.
93 Unknown(UnknownMessage),
94}
95
96/// Any undefined message.
97#[derive(Debug)]
98pub struct UnknownMessage {
99 /// The message type ID.
100 pub msg_type_id: MessageType,
101 /// The message data.
102 pub data: Bytes,
103}
104
105nutype_enum::nutype_enum! {
106 /// One byte field to represent the message type.
107 ///
108 /// A range of type IDs (1-6) are reserved for protocol control messages.
109 pub enum MessageType(u8) {
110 // Protocol Control Messages
111 /// Set Chunk Size
112 SetChunkSize = 1,
113 /// Abort
114 Abort = 2,
115 /// Acknowledgement
116 Acknowledgement = 3,
117 /// User Control Messages
118 UserControlEvent = 4,
119 /// Window Acknowledgement Size
120 WindowAcknowledgementSize = 5,
121 /// Set Peer Bandwidth
122 SetPeerBandwidth = 6,
123 // RTMP Command Messages
124 /// Audio Data
125 Audio = 8,
126 /// Video Data
127 Video = 9,
128 /// Amf3-encoded Metadata
129 DataAMF3 = 15,
130 /// Amf3-encoded Shared Object
131 SharedObjAMF3 = 16,
132 /// Amf3-encoded Command
133 CommandAMF3 = 17,
134 /// Amf0-encoded Metadata
135 DataAMF0 = 18,
136 /// Amf0-encoded Shared Object
137 SharedObjAMF0 = 19,
138 /// Amf0-encoded Command
139 CommandAMF0 = 20,
140 /// Aggregate Message
141 Aggregate = 22,
142 }
143}