1 use std::fmt; 2 use std::str::FromStr; 3 use url::Url; 4 5 #[derive(Clone, Debug)] 6 pub struct SessionConfig { 7 pub user_agent: String, 8 pub device_id: String, 9 pub proxy: Option<Url>, 10 pub ap_port: Option<u16>, 11 } 12 13 impl Default for SessionConfig { default() -> SessionConfig14 fn default() -> SessionConfig { 15 let device_id = uuid::Uuid::new_v4().to_hyphenated().to_string(); 16 SessionConfig { 17 user_agent: crate::version::VERSION_STRING.to_string(), 18 device_id, 19 proxy: None, 20 ap_port: None, 21 } 22 } 23 } 24 25 #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)] 26 pub enum DeviceType { 27 Unknown = 0, 28 Computer = 1, 29 Tablet = 2, 30 Smartphone = 3, 31 Speaker = 4, 32 Tv = 5, 33 Avr = 6, 34 Stb = 7, 35 AudioDongle = 8, 36 GameConsole = 9, 37 CastAudio = 10, 38 CastVideo = 11, 39 Automobile = 12, 40 Smartwatch = 13, 41 Chromebook = 14, 42 UnknownSpotify = 100, 43 CarThing = 101, 44 Observer = 102, 45 HomeThing = 103, 46 } 47 48 impl FromStr for DeviceType { 49 type Err = (); from_str(s: &str) -> Result<Self, Self::Err>50 fn from_str(s: &str) -> Result<Self, Self::Err> { 51 use self::DeviceType::*; 52 match s.to_lowercase().as_ref() { 53 "computer" => Ok(Computer), 54 "tablet" => Ok(Tablet), 55 "smartphone" => Ok(Smartphone), 56 "speaker" => Ok(Speaker), 57 "tv" => Ok(Tv), 58 "avr" => Ok(Avr), 59 "stb" => Ok(Stb), 60 "audiodongle" => Ok(AudioDongle), 61 "gameconsole" => Ok(GameConsole), 62 "castaudio" => Ok(CastAudio), 63 "castvideo" => Ok(CastVideo), 64 "automobile" => Ok(Automobile), 65 "smartwatch" => Ok(Smartwatch), 66 "chromebook" => Ok(Chromebook), 67 "carthing" => Ok(CarThing), 68 "homething" => Ok(HomeThing), 69 _ => Err(()), 70 } 71 } 72 } 73 74 impl From<&DeviceType> for &str { from(d: &DeviceType) -> &'static str75 fn from(d: &DeviceType) -> &'static str { 76 use self::DeviceType::*; 77 match d { 78 Unknown => "Unknown", 79 Computer => "Computer", 80 Tablet => "Tablet", 81 Smartphone => "Smartphone", 82 Speaker => "Speaker", 83 Tv => "TV", 84 Avr => "AVR", 85 Stb => "STB", 86 AudioDongle => "AudioDongle", 87 GameConsole => "GameConsole", 88 CastAudio => "CastAudio", 89 CastVideo => "CastVideo", 90 Automobile => "Automobile", 91 Smartwatch => "Smartwatch", 92 Chromebook => "Chromebook", 93 UnknownSpotify => "UnknownSpotify", 94 CarThing => "CarThing", 95 Observer => "Observer", 96 HomeThing => "HomeThing", 97 } 98 } 99 } 100 101 impl From<DeviceType> for &str { from(d: DeviceType) -> &'static str102 fn from(d: DeviceType) -> &'static str { 103 (&d).into() 104 } 105 } 106 107 impl fmt::Display for DeviceType { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result108 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 109 let str: &str = self.into(); 110 f.write_str(str) 111 } 112 } 113 114 impl Default for DeviceType { default() -> DeviceType115 fn default() -> DeviceType { 116 DeviceType::Speaker 117 } 118 } 119 120 #[derive(Clone, Debug)] 121 pub struct ConnectConfig { 122 pub name: String, 123 pub device_type: DeviceType, 124 pub initial_volume: Option<u16>, 125 pub has_volume_ctrl: bool, 126 pub autoplay: bool, 127 } 128