Skip to main content

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