mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Add "discovery" compat layer to "connect"
This commit is contained in:
parent
c49e1320d4
commit
9b6ba49026
4 changed files with 44 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -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",
|
||||||
|
|
|
@ -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
31
connect/src/discovery.rs
Normal 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))
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue