2017-08-03 18:31:15 +00:00
|
|
|
use std::fmt;
|
2018-02-11 11:37:08 +00:00
|
|
|
use std::str::FromStr;
|
2018-03-24 08:00:38 +00:00
|
|
|
use url::Url;
|
2017-08-03 18:31:15 +00:00
|
|
|
|
2018-02-11 11:37:08 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2017-08-03 18:58:44 +00:00
|
|
|
pub struct SessionConfig {
|
|
|
|
pub user_agent: String,
|
|
|
|
pub device_id: String,
|
2018-03-24 08:00:38 +00:00
|
|
|
pub proxy: Option<Url>,
|
2018-07-03 11:09:22 +00:00
|
|
|
pub ap_port: Option<u16>,
|
2017-08-03 18:58:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:31:15 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
|
|
|
|
pub enum DeviceType {
|
|
|
|
Unknown = 0,
|
|
|
|
Computer = 1,
|
|
|
|
Tablet = 2,
|
|
|
|
Smartphone = 3,
|
|
|
|
Speaker = 4,
|
|
|
|
TV = 5,
|
|
|
|
AVR = 6,
|
|
|
|
STB = 7,
|
|
|
|
AudioDongle = 8,
|
2021-02-09 03:16:40 +00:00
|
|
|
GameConsole = 9,
|
|
|
|
CastAudio = 10,
|
|
|
|
CastVideo = 11,
|
|
|
|
Automobile = 12,
|
|
|
|
Smartwatch = 13,
|
|
|
|
Chromebook = 14,
|
|
|
|
UnknownSpotify = 100,
|
|
|
|
CarThing = 101,
|
|
|
|
Observer = 102,
|
|
|
|
HomeThing = 103,
|
2017-08-03 18:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for DeviceType {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
use self::DeviceType::*;
|
|
|
|
match s.to_lowercase().as_ref() {
|
|
|
|
"computer" => Ok(Computer),
|
|
|
|
"tablet" => Ok(Tablet),
|
|
|
|
"smartphone" => Ok(Smartphone),
|
|
|
|
"speaker" => Ok(Speaker),
|
|
|
|
"tv" => Ok(TV),
|
|
|
|
"avr" => Ok(AVR),
|
|
|
|
"stb" => Ok(STB),
|
|
|
|
"audiodongle" => Ok(AudioDongle),
|
2021-02-09 03:16:40 +00:00
|
|
|
"gameconsole" => Ok(GameConsole),
|
|
|
|
"castaudio" => Ok(CastAudio),
|
|
|
|
"castvideo" => Ok(CastVideo),
|
|
|
|
"automobile" => Ok(Automobile),
|
|
|
|
"smartwatch" => Ok(Smartwatch),
|
|
|
|
"chromebook" => Ok(Chromebook),
|
|
|
|
"carthing" => Ok(CarThing),
|
|
|
|
"homething" => Ok(HomeThing),
|
2017-08-03 18:31:15 +00:00
|
|
|
_ => Err(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for DeviceType {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::DeviceType::*;
|
|
|
|
match *self {
|
|
|
|
Unknown => f.write_str("Unknown"),
|
|
|
|
Computer => f.write_str("Computer"),
|
|
|
|
Tablet => f.write_str("Tablet"),
|
|
|
|
Smartphone => f.write_str("Smartphone"),
|
|
|
|
Speaker => f.write_str("Speaker"),
|
|
|
|
TV => f.write_str("TV"),
|
|
|
|
AVR => f.write_str("AVR"),
|
|
|
|
STB => f.write_str("STB"),
|
|
|
|
AudioDongle => f.write_str("AudioDongle"),
|
2021-02-09 03:16:40 +00:00
|
|
|
GameConsole => f.write_str("GameConsole"),
|
|
|
|
CastAudio => f.write_str("CastAudio"),
|
|
|
|
CastVideo => f.write_str("CastVideo"),
|
|
|
|
Automobile => f.write_str("Automobile"),
|
|
|
|
Smartwatch => f.write_str("Smartwatch"),
|
|
|
|
Chromebook => f.write_str("Chromebook"),
|
|
|
|
UnknownSpotify => f.write_str("UnknownSpotify"),
|
|
|
|
CarThing => f.write_str("CarThing"),
|
|
|
|
Observer => f.write_str("Observer"),
|
|
|
|
HomeThing => f.write_str("HomeThing"),
|
2017-08-03 18:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for DeviceType {
|
|
|
|
fn default() -> DeviceType {
|
|
|
|
DeviceType::Speaker
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 11:37:08 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2017-08-03 18:31:15 +00:00
|
|
|
pub struct ConnectConfig {
|
|
|
|
pub name: String,
|
|
|
|
pub device_type: DeviceType,
|
2018-05-17 01:15:17 +00:00
|
|
|
pub volume: u16,
|
2020-07-25 07:38:08 +00:00
|
|
|
pub volume_ctrl: VolumeCtrl,
|
2019-11-05 19:34:43 +00:00
|
|
|
pub autoplay: bool,
|
2017-08-03 18:31:15 +00:00
|
|
|
}
|
2020-07-25 07:38:08 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum VolumeCtrl {
|
|
|
|
Linear,
|
|
|
|
Log,
|
|
|
|
Fixed,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for VolumeCtrl {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
use self::VolumeCtrl::*;
|
|
|
|
match s.to_lowercase().as_ref() {
|
|
|
|
"linear" => Ok(Linear),
|
|
|
|
"log" => Ok(Log),
|
|
|
|
"fixed" => Ok(Fixed),
|
|
|
|
_ => Err(()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for VolumeCtrl {
|
|
|
|
fn default() -> VolumeCtrl {
|
2020-07-25 07:44:10 +00:00
|
|
|
VolumeCtrl::Log
|
2020-07-25 07:38:08 +00:00
|
|
|
}
|
|
|
|
}
|