Add discovery example

This commit is contained in:
johannesd3 2021-03-12 16:39:58 +01:00
parent ebea5397b9
commit 1ec5dd21fa
No known key found for this signature in database
GPG key ID: 8C2739E91D410F75
3 changed files with 58 additions and 0 deletions

27
Cargo.lock generated
View file

@ -237,6 +237,17 @@ dependencies = [
"libloading 0.7.0", "libloading 0.7.0",
] ]
[[package]]
name = "colored"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]] [[package]]
name = "combine" name = "combine"
version = "4.5.2" version = "4.5.2"
@ -1236,7 +1247,9 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"dns-sd", "dns-sd",
"form_urlencoded", "form_urlencoded",
"futures",
"futures-core", "futures-core",
"hex",
"hmac", "hmac",
"hyper", "hyper",
"libmdns", "libmdns",
@ -1245,6 +1258,7 @@ dependencies = [
"rand", "rand",
"serde_json", "serde_json",
"sha-1", "sha-1",
"simple_logger",
"tokio", "tokio",
] ]
@ -2094,6 +2108,19 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "simple_logger"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd57f17c093ead1d4a1499dc9acaafdd71240908d64775465543b8d9a9f1d198"
dependencies = [
"atty",
"chrono",
"colored",
"log",
"winapi",
]
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.3" version = "0.4.3"

View file

@ -29,5 +29,11 @@ path = "../core"
default_features = false default_features = false
version = "0.2.0" version = "0.2.0"
[dev-dependencies]
futures = "0.3"
hex = "0.4"
simple_logger = "1.11"
tokio = { version = "1.0", features = ["macros", "rt"] }
[features] [features]
with-dns-sd = ["dns-sd"] with-dns-sd = ["dns-sd"]

View file

@ -0,0 +1,25 @@
use futures::StreamExt;
use librespot_discovery::DeviceType;
use sha1::{Digest, Sha1};
use simple_logger::SimpleLogger;
#[tokio::main(flavor = "current_thread")]
async fn main() {
SimpleLogger::new()
.with_level(log::LevelFilter::Debug)
.init()
.unwrap();
let name = "Librespot".to_string();
let device_id = hex::encode(Sha1::digest(name.as_bytes()));
let mut server = librespot_discovery::Discovery::builder(device_id)
.name(name)
.device_type(DeviceType::Computer)
.launch()
.unwrap();
while let Some(x) = server.next().await {
println!("Received {:?}", x);
}
}