From dc1ef790eca27340b1864a6dd951055752a23a86 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Wed, 18 Jul 2018 00:32:10 +0300 Subject: Refactor out notification calls --- src/notify.rs | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'src/notify.rs') diff --git a/src/notify.rs b/src/notify.rs index f946fd0..7a32d40 100644 --- a/src/notify.rs +++ b/src/notify.rs @@ -1,3 +1,8 @@ +use hyper::{Client, Request}; +use hyper::body::Body; +use tokio::runtime::Runtime; +use futures::Future; + const SOAP_ACTION_PREFIX: &'static str = "urn:schemas-upnp-org:service:AVTransport:1#"; const ACTION_SET_URI: &'static str = "SetAVTransportURI"; const ACTION_PLAY: &'static str = "Play"; @@ -25,6 +30,15 @@ pub const BODY_PLAY: &'static str = r#" "#; +pub const BODY_PAUSE: &'static str = r#" + + + + 0 + + +"#; + pub const BODY_STOP: &'static str = r#" @@ -38,3 +52,93 @@ pub const BODY_STOP: &'static str = r#" pub const A_SET: &'static str = "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"; pub const A_PLAY: &'static str = "urn:schemas-upnp-org:service:AVTransport:1#Play"; pub const A_STOP: &'static str = "urn:schemas-upnp-org:service:AVTransport:1#Stop"; +pub const A_PAUSE: &'static str = "urn:schemas-upnp-org:service:AVTransport:1#Pause"; + + +pub fn set_uri(rt: &mut Runtime) { + let req = Request::builder() + .method("POST") + .uri("http://10.5.1.201:38400/serviceControl/AVTransport") + .header("Content-Type", "text/xml") + .header("SOAPACTION", A_SET) + .body(Body::from(BODY_SET_URI)) + .unwrap(); + + let client = Client::new(); + let f = client + .request(req) + .map(|_res| { + println!("Request good") + }) + .map_err(|_err| { + println!("Request error"); + }); + + rt.spawn(f); +} + +pub fn play(rt: &mut Runtime) { + let req = Request::builder() + .method("POST") + .uri("http://10.5.1.201:38400/serviceControl/AVTransport") + .header("Content-Type", "text/xml") + .header("SOAPACTION", A_PLAY) + .body(Body::from(BODY_PLAY)) + .unwrap(); + + let client = Client::new(); + let f = client + .request(req) + .map(|_res| { + println!("Request good") + }) + .map_err(|_err| { + println!("Request error"); + }); + + rt.spawn(f); +} + +pub fn pause(rt: &mut Runtime) { + let req = Request::builder() + .method("POST") + .uri("http://10.5.1.201:38400/serviceControl/AVTransport") + .header("Content-Type", "text/xml") + .header("SOAPACTION", A_PAUSE) + .body(Body::from(BODY_PAUSE)) + .unwrap(); + + let client = Client::new(); + let f = client + .request(req) + .map(|_res| { + println!("Request good") + }) + .map_err(|_err| { + println!("Request error"); + }); + + rt.spawn(f); +} + +pub fn stop(rt: &mut Runtime) { + let req = Request::builder() + .method("POST") + .uri("http://10.5.1.201:38400/serviceControl/AVTransport") + .header("Content-Type", "text/xml") + .header("SOAPACTION", A_STOP) + .body(Body::from(BODY_STOP)) + .unwrap(); + + let client = Client::new(); + let f = client + .request(req) + .map(|_res| { + println!("Request good") + }) + .map_err(|_err| { + println!("Request error"); + }); + + rt.spawn(f); +} -- cgit v1.3.1