mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Add discovery example
This commit is contained in:
parent
ebea5397b9
commit
1ec5dd21fa
3 changed files with 58 additions and 0 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -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"
|
||||||
|
|
|
@ -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"]
|
||||||
|
|
25
discovery/examples/discovery.rs
Normal file
25
discovery/examples/discovery.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue