config.rs 2.0 KB

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