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