Add "discovery" compat layer to "connect"

This commit is contained in:
johannesd3 2021-05-09 10:50:15 +02:00
parent c49e1320d4
commit 9b6ba49026
No known key found for this signature in database
GPG key ID: 8C2739E91D410F75
4 changed files with 44 additions and 0 deletions

1
Cargo.lock generated
View file

@ -1187,6 +1187,7 @@ dependencies = [
"form_urlencoded", "form_urlencoded",
"futures-util", "futures-util",
"librespot-core", "librespot-core",
"librespot-discovery",
"librespot-playback", "librespot-playback",
"librespot-protocol", "librespot-protocol",
"log", "log",

View file

@ -29,3 +29,10 @@ version = "0.2.0"
[dependencies.librespot-protocol] [dependencies.librespot-protocol]
path = "../protocol" path = "../protocol"
version = "0.2.0" version = "0.2.0"
[dependencies.librespot-discovery]
path = "../discovery"
version = "0.2.0"
[features]
with-dns-sd = ["librespot-discovery/with-dns-sd"]

31
connect/src/discovery.rs Normal file
View file

@ -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<Option<Self::Item>> {
Pin::new(&mut self.0).poll_next(cx)
}
}
pub fn discovery(
config: ConnectConfig,
device_id: String,
port: u16,
) -> io::Result<DiscoveryStream> {
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))
}

View file

@ -6,4 +6,9 @@ use librespot_playback as playback;
use librespot_protocol as protocol; use librespot_protocol as protocol;
pub mod context; pub mod context;
#[deprecated(
since = "0.2.1",
note = "Please use the crate `librespot_discovery` instead."
)]
pub mod discovery;
pub mod spirc; pub mod spirc;