Skip to content

Commit 9b6ba49

Browse files
committed
Add "discovery" compat layer to "connect"
1 parent c49e132 commit 9b6ba49

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connect/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ version = "0.2.0"
2929
[dependencies.librespot-protocol]
3030
path = "../protocol"
3131
version = "0.2.0"
32+
33+
[dependencies.librespot-discovery]
34+
path = "../discovery"
35+
version = "0.2.0"
36+
37+
[features]
38+
with-dns-sd = ["librespot-discovery/with-dns-sd"]

connect/src/discovery.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use std::io;
2+
use std::pin::Pin;
3+
use std::task::{Context, Poll};
4+
5+
use futures_util::Stream;
6+
use librespot_core::authentication::Credentials;
7+
use librespot_core::config::ConnectConfig;
8+
9+
pub struct DiscoveryStream(librespot_discovery::Discovery);
10+
11+
impl Stream for DiscoveryStream {
12+
type Item = Credentials;
13+
14+
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
15+
Pin::new(&mut self.0).poll_next(cx)
16+
}
17+
}
18+
19+
pub fn discovery(
20+
config: ConnectConfig,
21+
device_id: String,
22+
port: u16,
23+
) -> io::Result<DiscoveryStream> {
24+
librespot_discovery::Discovery::builder(device_id)
25+
.device_type(config.device_type)
26+
.port(port)
27+
.name(config.name)
28+
.launch()
29+
.map(DiscoveryStream)
30+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
31+
}

connect/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ use librespot_playback as playback;
66
use librespot_protocol as protocol;
77

88
pub mod context;
9+
#[deprecated(
10+
since = "0.2.1",
11+
note = "Please use the crate `librespot_discovery` instead."
12+
)]
13+
pub mod discovery;
914
pub mod spirc;

0 commit comments

Comments
 (0)