From 9b6ba4902665ea9a908a7f14121f3c7ef3cb7216 Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Sun, 9 May 2021 10:50:15 +0200 Subject: [PATCH] Add "discovery" compat layer to "connect" --- Cargo.lock | 1 + connect/Cargo.toml | 7 +++++++ connect/src/discovery.rs | 31 +++++++++++++++++++++++++++++++ connect/src/lib.rs | 5 +++++ 4 files changed, 44 insertions(+) create mode 100644 connect/src/discovery.rs diff --git a/Cargo.lock b/Cargo.lock index 23eb4485..78f9237e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1187,6 +1187,7 @@ dependencies = [ "form_urlencoded", "futures-util", "librespot-core", + "librespot-discovery", "librespot-playback", "librespot-protocol", "log", diff --git a/connect/Cargo.toml b/connect/Cargo.toml index a46b70e4..89d185ab 100644 --- a/connect/Cargo.toml +++ b/connect/Cargo.toml @@ -29,3 +29,10 @@ version = "0.2.0" [dependencies.librespot-protocol] path = "../protocol" version = "0.2.0" + +[dependencies.librespot-discovery] +path = "../discovery" +version = "0.2.0" + +[features] +with-dns-sd = ["librespot-discovery/with-dns-sd"] diff --git a/connect/src/discovery.rs b/connect/src/discovery.rs new file mode 100644 index 00000000..8ce3f4f0 --- /dev/null +++ b/connect/src/discovery.rs @@ -0,0 +1,31 @@ +use std::io; +use std::pin::Pin; +use std::task::{Context, Poll}; + +use futures_util::Stream; +use librespot_core::authentication::Credentials; +use librespot_core::config::ConnectConfig; + +pub struct DiscoveryStream(librespot_discovery::Discovery); + +impl Stream for DiscoveryStream { + type Item = Credentials; + + fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + Pin::new(&mut self.0).poll_next(cx) + } +} + +pub fn discovery( + config: ConnectConfig, + device_id: String, + port: u16, +) -> io::Result { + librespot_discovery::Discovery::builder(device_id) + .device_type(config.device_type) + .port(port) + .name(config.name) + .launch() + .map(DiscoveryStream) + .map_err(|e| io::Error::new(io::ErrorKind::Other, e)) +} diff --git a/connect/src/lib.rs b/connect/src/lib.rs index 5ddfeba9..267bf1b8 100644 --- a/connect/src/lib.rs +++ b/connect/src/lib.rs @@ -6,4 +6,9 @@ use librespot_playback as playback; use librespot_protocol as protocol; pub mod context; +#[deprecated( + since = "0.2.1", + note = "Please use the crate `librespot_discovery` instead." +)] +pub mod discovery; pub mod spirc;