scuffle_rtmp/command_messages/mod.rs
1//! Command messages.
2
3use netconnection::NetConnectionCommand;
4use netstream::NetStreamCommand;
5use on_status::OnStatus;
6use scuffle_amf0::Amf0Value;
7use scuffle_bytes_util::StringCow;
8use serde_derive::Serialize;
9
10pub mod error;
11pub mod netconnection;
12pub mod netstream;
13pub mod on_status;
14pub mod reader;
15pub mod writer;
16
17/// Command message.
18///
19/// > The client and the server exchange commands which are AMF encoded.
20/// > The sender sends a command message that consists of command name,
21/// > transaction ID, and command object that contains related parameters.
22///
23/// Defined by:
24/// - Legacy RTMP spec, section 7.1.1
25/// - Legacy RTMP spec, section 7.2
26#[derive(Debug, Clone)]
27pub struct Command<'a> {
28 /// Transaction ID.
29 ///
30 /// > The receiver processes the command and sends back the response with the
31 /// > same transaction ID.
32 pub transaction_id: f64,
33 /// Command type.
34 pub command_type: CommandType<'a>,
35}
36
37/// This enum wraps the [`NetConnectionCommand`], [`NetStreamCommand`] and [`OnStatus`] enums.
38#[derive(Debug, Clone)]
39pub enum CommandType<'a> {
40 /// NetConnection command
41 NetConnection(NetConnectionCommand<'a>),
42 /// NetStream command
43 NetStream(NetStreamCommand<'a>),
44 /// onStatus command
45 OnStatus(OnStatus<'a>),
46 /// Any unknown command
47 ///
48 /// e.g. FFmpeg sends some commands that don't appear in any spec, so we need to handle them.
49 Unknown(UnknownCommand<'a>),
50}
51
52/// Any unknown command
53///
54/// e.g. FFmpeg sends some commands that don't appear in any spec, so we need to handle them.
55#[derive(Debug, Clone)]
56pub struct UnknownCommand<'a> {
57 /// Name of the unknown command.
58 pub command_name: StringCow<'a>,
59 /// All other values of the command including the command object.
60 pub values: Vec<Amf0Value<'static>>,
61}
62
63/// NetStream onStatus level (7.2.2.) and NetConnection connect result level (7.2.1.1.)
64#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
65#[serde(rename_all = "camelCase")]
66pub enum CommandResultLevel {
67 /// Warning level.
68 ///
69 /// Not further explained in any spec.
70 Warning,
71 /// Status level.
72 ///
73 /// Used by [`OnStatus`] commands.
74 Status,
75 /// Error level.
76 ///
77 /// Not further explained in any spec.
78 Error,
79 /// Any other level.
80 #[serde(untagged)]
81 Unknown(String),
82}