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