rtc_ice/state/
mod.rs

1#[cfg(test)]
2mod state_test;
3
4use std::fmt;
5
6/// An enum showing the state of a ICE Connection List of supported States.
7#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
8pub enum ConnectionState {
9    #[default]
10    Unspecified,
11
12    /// ICE agent is gathering addresses.
13    New,
14
15    /// ICE agent has been given local and remote candidates, and is attempting to find a match.
16    Checking,
17
18    /// ICE agent has a pairing, but is still checking other pairs.
19    Connected,
20
21    /// ICE agent has finished.
22    Completed,
23
24    /// ICE agent never could successfully connect.
25    Failed,
26
27    /// ICE agent connected successfully, but has entered a failed state.
28    Disconnected,
29
30    /// ICE agent has finished and is no longer handling requests.
31    Closed,
32}
33
34impl fmt::Display for ConnectionState {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        let s = match *self {
37            Self::Unspecified => "Unspecified",
38            Self::New => "New",
39            Self::Checking => "Checking",
40            Self::Connected => "Connected",
41            Self::Completed => "Completed",
42            Self::Failed => "Failed",
43            Self::Disconnected => "Disconnected",
44            Self::Closed => "Closed",
45        };
46        write!(f, "{s}")
47    }
48}
49
50impl From<u8> for ConnectionState {
51    fn from(v: u8) -> Self {
52        match v {
53            1 => Self::New,
54            2 => Self::Checking,
55            3 => Self::Connected,
56            4 => Self::Completed,
57            5 => Self::Failed,
58            6 => Self::Disconnected,
59            7 => Self::Closed,
60            _ => Self::Unspecified,
61        }
62    }
63}
64
65/// Describes the state of the candidate gathering process.
66#[derive(Default, PartialEq, Eq, Copy, Clone)]
67pub enum GatheringState {
68    #[default]
69    Unspecified,
70
71    /// Indicates candidate gathering is not yet started.
72    New,
73
74    /// Indicates candidate gathering is ongoing.
75    Gathering,
76
77    /// Indicates candidate gathering has been completed.
78    Complete,
79}
80
81impl From<u8> for GatheringState {
82    fn from(v: u8) -> Self {
83        match v {
84            1 => Self::New,
85            2 => Self::Gathering,
86            3 => Self::Complete,
87            _ => Self::Unspecified,
88        }
89    }
90}
91
92impl fmt::Display for GatheringState {
93    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94        let s = match *self {
95            Self::New => "new",
96            Self::Gathering => "gathering",
97            Self::Complete => "complete",
98            Self::Unspecified => "unspecified",
99        };
100        write!(f, "{s}")
101    }
102}