1 #[cfg(test)] 2 mod state_test; 3 4 use std::fmt; 5 6 /// An enum showing the state of a ICE Connection List of supported States. 7 #[derive(Debug, Copy, Clone, PartialEq, Eq)] 8 pub 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 33 impl Default for ConnectionState { default() -> Self34 fn default() -> Self { 35 Self::Unspecified 36 } 37 } 38 39 impl fmt::Display for ConnectionState { fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result40 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 55 impl From<u8> for ConnectionState { from(v: u8) -> Self56 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)] 72 pub 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 85 impl From<u8> for GatheringState { from(v: u8) -> Self86 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 96 impl Default for GatheringState { default() -> Self97 fn default() -> Self { 98 Self::Unspecified 99 } 100 } 101 102 impl fmt::Display for GatheringState { fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result103 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 } 113