#upnp #protocols #networking #media-server #async #specification

rupnp

An asynchronous library for finding UPnP control points, performing actions on them and reading their service descriptions

11 releases (3 stable)

2.0.0 Sep 16, 2023
1.1.1 Feb 21, 2022
1.0.0 Dec 23, 2020
0.1.7 Nov 11, 2020
0.1.5 Apr 27, 2020

#1511 in Network programming

Download history 8663/week @ 2024-06-13 6237/week @ 2024-06-20 7341/week @ 2024-06-27 7977/week @ 2024-07-04 8377/week @ 2024-07-11 7165/week @ 2024-07-18 6627/week @ 2024-07-25 6753/week @ 2024-08-01 948/week @ 2024-08-08 715/week @ 2024-08-15 692/week @ 2024-08-22 597/week @ 2024-08-29 596/week @ 2024-09-05 877/week @ 2024-09-12 3373/week @ 2024-09-19 3381/week @ 2024-09-26

8,287 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

52KB
1K SLoC

GitHub last commit Crates.io

rupnp

An asynchronous library for finding UPnP control points, performing actions on them and reading their service descriptions. UPnP stand for Universal Plug and Play and is widely used for routers, WiFi-enabled speakers and media servers.

Spec: http://rupnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v2.0.pdf

Example usage:

The following code searches for devices that have a RenderingControl service and print their names along with their current volume.

use futures::prelude::*;
use std::time::Duration;
use rupnp::ssdp::{SearchTarget, URN};

const RENDERING_CONTROL: URN = URN::service("schemas-upnp-org", "RenderingControl", 1);

#[tokio::main]
async fn main() -> Result<(), rupnp::Error> {
    let search_target = SearchTarget::URN(RENDERING_CONTROL);
    let devices = rupnp::discover(&search_target, Duration::from_secs(3)).await?;
    pin_utils::pin_mut!(devices);

    while let Some(device) = devices.try_next().await? {
        let service = device
            .find_service(&RENDERING_CONTROL)
            .expect("searched for RenderingControl, got something else");

        let args = "<InstanceID>0</InstanceID><Channel>Master</Channel>";
        let response = service.action(device.url(), "GetVolume", args).await?;

        let volume = response.get("CurrentVolume").unwrap();

        println!("'{}' is at volume {}", device.friendly_name(), volume);
    }

    Ok(())
}

License

Licensed under either of

at your option.

Contribution

Please use rustfmt before any pull requests.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~5–13MB
~149K SLoC