diff --git a/Cargo.lock b/Cargo.lock index 1b65127d..dddd26a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1369,7 +1369,6 @@ dependencies = [ "hmac", "hyper", "libmdns", - "librespot-connect", "librespot-core", "log", "rand", diff --git a/connect/src/config.rs b/connect/src/config.rs index 4d751fcf..473fa173 100644 --- a/connect/src/config.rs +++ b/connect/src/config.rs @@ -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 { - 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 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 - } -} diff --git a/core/src/config.rs b/core/src/config.rs index 87c1637f..4c1b1dd8 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -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 { + 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 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 + } +} diff --git a/discovery/Cargo.toml b/discovery/Cargo.toml index cafa6870..0225ab68 100644 --- a/discovery/Cargo.toml +++ b/discovery/Cargo.toml @@ -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" diff --git a/discovery/src/lib.rs b/discovery/src/lib.rs index a4e124c5..b4e95737 100644 --- a/discovery/src/lib.rs +++ b/discovery/src/lib.rs @@ -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. /// diff --git a/discovery/src/server.rs b/discovery/src/server.rs index b02c0e64..9cf6837b 100644 --- a/discovery/src/server.rs +++ b/discovery/src/server.rs @@ -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}, }; diff --git a/src/main.rs b/src/main.rs index ff7c79da..2d0337cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::{