Skip to main content

gbp_core/
signal.rs

1//! GSP signal opcode registry.
2
3/// Signal opcode. Allocation:
4/// 1xx — membership, 2xx — media permissions, 3xx — stream, 4xx — config.
5#[repr(u16)]
6#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
7pub enum SignalType {
8    /// Member announces that it has joined the group.
9    Join = 100,
10    /// Member announces that it is leaving.
11    Leave = 101,
12    /// Member changes its role.
13    RoleChange = 102,
14    /// Mute request or notification.
15    Mute = 200,
16    /// Unmute request or notification.
17    Unmute = 201,
18    /// Start of a stream publication.
19    StreamStart = 300,
20    /// End of a stream publication.
21    StreamStop = 301,
22    /// Codec or SDP parameters update.
23    CodecUpdate = 400,
24}
25
26impl TryFrom<u32> for SignalType {
27    type Error = u32;
28    fn try_from(v: u32) -> Result<Self, u32> {
29        use SignalType::*;
30        Ok(match v {
31            100 => Join,
32            101 => Leave,
33            102 => RoleChange,
34            200 => Mute,
35            201 => Unmute,
36            300 => StreamStart,
37            301 => StreamStop,
38            400 => CodecUpdate,
39            other => return Err(other),
40        })
41    }
42}
43
44impl SignalType {
45    /// Stable human-readable name suitable for logs.
46    pub fn name(self) -> &'static str {
47        use SignalType::*;
48        match self {
49            Join => "JOIN",
50            Leave => "LEAVE",
51            RoleChange => "ROLE_CHANGE",
52            Mute => "MUTE",
53            Unmute => "UNMUTE",
54            StreamStart => "STREAM_START",
55            StreamStop => "STREAM_STOP",
56            CodecUpdate => "CODEC_UPDATE",
57        }
58    }
59}