mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Move DeviceType
to core
This commit is contained in:
parent
4ca1f661d5
commit
c1965198fc
7 changed files with 112 additions and 116 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1369,7 +1369,6 @@ dependencies = [
|
|||
"hmac",
|
||||
"hyper",
|
||||
"libmdns",
|
||||
"librespot-connect",
|
||||
"librespot-core",
|
||||
"log",
|
||||
"rand",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{fmt, str::FromStr};
|
||||
use crate::core::config::DeviceType;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ConnectConfig {
|
||||
|
@ -18,98 +18,3 @@ impl Default for ConnectConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
GameConsole = 9,
|
||||
CastAudio = 10,
|
||||
CastVideo = 11,
|
||||
Automobile = 12,
|
||||
Smartwatch = 13,
|
||||
Chromebook = 14,
|
||||
UnknownSpotify = 100,
|
||||
CarThing = 101,
|
||||
Observer = 102,
|
||||
HomeThing = 103,
|
||||
}
|
||||
|
||||
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),
|
||||
"gameconsole" => Ok(GameConsole),
|
||||
"castaudio" => Ok(CastAudio),
|
||||
"castvideo" => Ok(CastVideo),
|
||||
"automobile" => Ok(Automobile),
|
||||
"smartwatch" => Ok(Smartwatch),
|
||||
"chromebook" => Ok(Chromebook),
|
||||
"carthing" => Ok(CarThing),
|
||||
"homething" => Ok(HomeThing),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DeviceType> for &str {
|
||||
fn from(d: &DeviceType) -> &'static str {
|
||||
use self::DeviceType::*;
|
||||
match d {
|
||||
Unknown => "Unknown",
|
||||
Computer => "Computer",
|
||||
Tablet => "Tablet",
|
||||
Smartphone => "Smartphone",
|
||||
Speaker => "Speaker",
|
||||
Tv => "TV",
|
||||
Avr => "AVR",
|
||||
Stb => "STB",
|
||||
AudioDongle => "AudioDongle",
|
||||
GameConsole => "GameConsole",
|
||||
CastAudio => "CastAudio",
|
||||
CastVideo => "CastVideo",
|
||||
Automobile => "Automobile",
|
||||
Smartwatch => "Smartwatch",
|
||||
Chromebook => "Chromebook",
|
||||
UnknownSpotify => "UnknownSpotify",
|
||||
CarThing => "CarThing",
|
||||
Observer => "Observer",
|
||||
HomeThing => "HomeThing",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DeviceType> for &str {
|
||||
fn from(d: DeviceType) -> &'static str {
|
||||
(&d).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DeviceType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let str: &str = self.into();
|
||||
f.write_str(str)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DeviceType {
|
||||
fn default() -> DeviceType {
|
||||
DeviceType::Speaker
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::{fmt, path::PathBuf, str::FromStr};
|
||||
|
||||
use url::Url;
|
||||
|
||||
|
@ -21,3 +21,98 @@ impl Default for SessionConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
GameConsole = 9,
|
||||
CastAudio = 10,
|
||||
CastVideo = 11,
|
||||
Automobile = 12,
|
||||
Smartwatch = 13,
|
||||
Chromebook = 14,
|
||||
UnknownSpotify = 100,
|
||||
CarThing = 101,
|
||||
Observer = 102,
|
||||
HomeThing = 103,
|
||||
}
|
||||
|
||||
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),
|
||||
"gameconsole" => Ok(GameConsole),
|
||||
"castaudio" => Ok(CastAudio),
|
||||
"castvideo" => Ok(CastVideo),
|
||||
"automobile" => Ok(Automobile),
|
||||
"smartwatch" => Ok(Smartwatch),
|
||||
"chromebook" => Ok(Chromebook),
|
||||
"carthing" => Ok(CarThing),
|
||||
"homething" => Ok(HomeThing),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&DeviceType> for &str {
|
||||
fn from(d: &DeviceType) -> &'static str {
|
||||
use self::DeviceType::*;
|
||||
match d {
|
||||
Unknown => "Unknown",
|
||||
Computer => "Computer",
|
||||
Tablet => "Tablet",
|
||||
Smartphone => "Smartphone",
|
||||
Speaker => "Speaker",
|
||||
Tv => "TV",
|
||||
Avr => "AVR",
|
||||
Stb => "STB",
|
||||
AudioDongle => "AudioDongle",
|
||||
GameConsole => "GameConsole",
|
||||
CastAudio => "CastAudio",
|
||||
CastVideo => "CastVideo",
|
||||
Automobile => "Automobile",
|
||||
Smartwatch => "Smartwatch",
|
||||
Chromebook => "Chromebook",
|
||||
UnknownSpotify => "UnknownSpotify",
|
||||
CarThing => "CarThing",
|
||||
Observer => "Observer",
|
||||
HomeThing => "HomeThing",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DeviceType> for &str {
|
||||
fn from(d: DeviceType) -> &'static str {
|
||||
(&d).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DeviceType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let str: &str = self.into();
|
||||
f.write_str(str)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DeviceType {
|
||||
fn default() -> DeviceType {
|
||||
DeviceType::Speaker
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,6 @@ sha-1 = "0.9"
|
|||
thiserror = "1.0"
|
||||
tokio = { version = "1.0", features = ["parking_lot", "sync", "rt"] }
|
||||
|
||||
[dependencies.librespot-connect]
|
||||
path = "../connect"
|
||||
version = "0.3.1"
|
||||
|
||||
[dependencies.librespot-core]
|
||||
path = "../core"
|
||||
version = "0.3.1"
|
||||
|
|
|
@ -9,26 +9,27 @@
|
|||
|
||||
mod server;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
io,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use futures_core::Stream;
|
||||
use librespot_connect as connect;
|
||||
use librespot_core as core;
|
||||
use thiserror::Error;
|
||||
|
||||
use self::server::DiscoveryServer;
|
||||
|
||||
pub use crate::core::Error;
|
||||
use librespot_core as core;
|
||||
|
||||
/// Credentials to be used in [`librespot`](`librespot_core`).
|
||||
pub use crate::core::authentication::Credentials;
|
||||
|
||||
/// Determining the icon in the list of available devices.
|
||||
pub use crate::connect::config::DeviceType;
|
||||
|
||||
pub use crate::core::Error;
|
||||
pub use crate::core::config::DeviceType;
|
||||
|
||||
/// Makes this device visible to Spotify clients in the local network.
|
||||
///
|
||||
|
|
|
@ -28,7 +28,7 @@ use tokio::sync::{mpsc, oneshot};
|
|||
use super::DiscoveryError;
|
||||
|
||||
use crate::{
|
||||
connect::config::DeviceType,
|
||||
core::config::DeviceType,
|
||||
core::{authentication::Credentials, diffie_hellman::DhLocalKeys, Error},
|
||||
};
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ use tokio::sync::mpsc::UnboundedReceiver;
|
|||
use url::Url;
|
||||
|
||||
use librespot::{
|
||||
connect::{
|
||||
config::{ConnectConfig, DeviceType},
|
||||
spirc::Spirc,
|
||||
connect::{config::ConnectConfig, spirc::Spirc},
|
||||
core::{
|
||||
authentication::Credentials, cache::Cache, config::DeviceType, version, Session,
|
||||
SessionConfig,
|
||||
},
|
||||
core::{authentication::Credentials, cache::Cache, version, Session, SessionConfig},
|
||||
playback::{
|
||||
audio_backend::{self, SinkBuilder, BACKENDS},
|
||||
config::{
|
||||
|
|
Loading…
Reference in a new issue