config.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. use std::fmt;
  2. use std::str::FromStr;
  3. use url::Url;
  4. use uuid::Uuid;
  5. use crate::version;
  6. #[derive(Clone, Debug)]
  7. pub struct SessionConfig {
  8. pub user_agent: String,
  9. pub device_id: String,
  10. pub proxy: Option<Url>,
  11. pub ap_port: Option<u16>,
  12. }
  13. impl Default for SessionConfig {
  14. fn default() -> SessionConfig {
  15. let device_id = Uuid::new_v4().to_hyphenated().to_string();
  16. SessionConfig {
  17. user_agent: version::version_string(),
  18. device_id: device_id,
  19. proxy: None,
  20. ap_port: None,
  21. }
  22. }
  23. }
  24. #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
  25. pub enum DeviceType {
  26. Unknown = 0,
  27. Computer = 1,
  28. Tablet = 2,
  29. Smartphone = 3,
  30. Speaker = 4,
  31. TV = 5,
  32. AVR = 6,
  33. STB = 7,
  34. AudioDongle = 8,
  35. }
  36. impl FromStr for DeviceType {
  37. type Err = ();
  38. fn from_str(s: &str) -> Result<Self, Self::Err> {
  39. use self::DeviceType::*;
  40. match s.to_lowercase().as_ref() {
  41. "computer" => Ok(Computer),
  42. "tablet" => Ok(Tablet),
  43. "smartphone" => Ok(Smartphone),
  44. "speaker" => Ok(Speaker),
  45. "tv" => Ok(TV),
  46. "avr" => Ok(AVR),
  47. "stb" => Ok(STB),
  48. "audiodongle" => Ok(AudioDongle),
  49. _ => Err(()),
  50. }
  51. }
  52. }
  53. impl fmt::Display for DeviceType {
  54. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  55. use self::DeviceType::*;
  56. match *self {
  57. Unknown => f.write_str("Unknown"),
  58. Computer => f.write_str("Computer"),
  59. Tablet => f.write_str("Tablet"),
  60. Smartphone => f.write_str("Smartphone"),
  61. Speaker => f.write_str("Speaker"),
  62. TV => f.write_str("TV"),
  63. AVR => f.write_str("AVR"),
  64. STB => f.write_str("STB"),
  65. AudioDongle => f.write_str("AudioDongle"),
  66. }
  67. }
  68. }
  69. impl Default for DeviceType {
  70. fn default() -> DeviceType {
  71. DeviceType::Speaker
  72. }
  73. }
  74. #[derive(Clone, Debug)]
  75. pub struct ConnectConfig {
  76. pub name: String,
  77. pub device_type: DeviceType,
  78. pub volume: u16,
  79. pub linear_volume: bool,
  80. pub autoplay: bool,
  81. }