rupnp/lib.rs
1#![warn(
2 nonstandard_style,
3 rust_2018_idioms,
4 future_incompatible,
5 missing_debug_implementations
6)]
7
8//! An asynchronous library for finding UPnP control points, performing actions on them
9//! and reading their service descriptions.
10//! UPnP stand for `Universal Plug and Play` and is widely used for routers, WiFi-enabled speakers
11//! and media servers.
12//!
13//! Specification:
14//! [http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v2.0.pdf](http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v2.0.pdf)
15//!
16//! # Example usage:
17//! The following code searches for devices that have a `RenderingControl` service
18//! and prints their names along with their current volume.
19//!
20//! ```rust,no_run
21//! use futures::prelude::*;
22//! use std::time::Duration;
23//! use rupnp::ssdp::{SearchTarget, URN};
24//!
25//! const RENDERING_CONTROL: URN = URN::service("schemas-upnp-org", "RenderingControl", 1);
26//!
27//! #[tokio::main]
28//! async fn main() -> Result<(), rupnp::Error> {
29//! let search_target = SearchTarget::URN(RENDERING_CONTROL);
30//! let devices = rupnp::discover(&search_target, Duration::from_secs(3), None).await?;
31//! let mut devices = std::pin::pin!(devices);
32//!
33//! while let Some(device) = devices.try_next().await? {
34//! let service = device
35//! .find_service(&RENDERING_CONTROL)
36//! .expect("searched for RenderingControl, got something else");
37//!
38//! let args = "<InstanceID>0</InstanceID><Channel>Master</Channel>";
39//! let response = service.action(device.url(), "GetVolume", args).await?;
40//!
41//! let volume = response.get("CurrentVolume").unwrap();
42//!
43//! println!("'{}' is at volume {}", device.friendly_name(), volume);
44//! }
45//!
46//! Ok(())
47//! }
48//! ```
49// TODO: doc include when it gets stable
50
51mod device;
52mod discovery;
53mod error;
54/// Service Control Protocol Description.
55pub mod scpd;
56mod service;
57pub mod utils;
58
59pub use device::{Device, DeviceSpec};
60pub use discovery::{discover, discover_with_properties};
61pub use error::Error;
62pub use service::Service;
63
64pub use http;
65pub use ssdp_client as ssdp;
66
67pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;