From 80655a1d70ac56528bab4fbb7290a352ee9fe081 Mon Sep 17 00:00:00 2001
From: Yuval Adam <_@yuv.al>
Date: Tue, 17 Jul 2018 23:16:07 +0300
Subject: Second round of refactoring
---
src/main.rs | 25 ++++++++++++++++++++++++-
src/notify.rs | 29 ++++-------------------------
2 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 2b4826f..f536d94 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,7 +16,8 @@ use std::process;
use std::thread;
use std::sync::mpsc;
-use hyper::Server;
+use hyper::{Client, Server, Request};
+use hyper::body::Body;
use hyper::service::service_fn;
use tokio::runtime::Runtime;
use futures::Future;
@@ -69,6 +70,28 @@ fn main() {
let mut rt = Runtime::new().unwrap();
rt.spawn(server);
+ let client = Client::new();
+
+ let req = Request::builder()
+ .method("POST")
+ .uri("http://10.5.1.201:38400/serviceControl/AVTransport")
+ .header("Content-Type", "text/xml")
+ .header("SOAPACTION", notify::A_SET)
+ .body(Body::from(notify::BODY_SET_URI))
+ .unwrap();
+
+ rt.spawn(client.request(req).map(|res| {}).map_err(|err| {}));
+
+ let req = Request::builder()
+ .method("POST")
+ .uri("http://10.5.1.201:38400/serviceControl/AVTransport")
+ .header("Content-Type", "text/xml")
+ .header("SOAPACTION", notify::A_PLAY)
+ .body(Body::from(notify::BODY_PLAY))
+ .unwrap();
+
+ rt.spawn(client.request(req).map(|res| {}).map_err(|err| {}));
+
// let _udp = thread::spawn(move || {
// upnp::discover();
// });
diff --git a/src/notify.rs b/src/notify.rs
index 0d0877d..da34131 100644
--- a/src/notify.rs
+++ b/src/notify.rs
@@ -1,17 +1,10 @@
-extern crate hyper;
-extern crate futures;
-
-use self::hyper::{Method, Request, Uri};
-use self::hyper::header::HeaderValue;
-use self::hyper::body::Body;
-
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";
const ACTION_PAUSE: &'static str = "Pause";
const ACTION_STOP: &'static str = "Stop";
-const BODY_SET_URI: &'static str = r#"
+pub const BODY_SET_URI: &'static str = r#"
@@ -22,7 +15,7 @@ const BODY_SET_URI: &'static str = r#"
"#;
-const BODY_PLAY: &'static str = r#"
+pub const BODY_PLAY: &'static str = r#"
@@ -44,19 +37,5 @@ const BODY_STOP: &'static str = r#"
"#;
-pub fn build_request(body: &'static str, action: &str) {
- let uri: Uri = "http://10.5.1.201:38400/serviceControl/AVTransport".parse().unwrap();
- let mut req = Request::new(Body::from(body));
- *req.method_mut() = Method::POST;
- *req.uri_mut() = uri.clone();
- req.headers_mut().insert("content-type", HeaderValue::from_str("text/xml").unwrap());
- req.headers_mut().insert("SOAPACTION", HeaderValue::from_str(action).unwrap());
-}
-
-pub fn set_uri() {
- build_request(BODY_SET_URI, "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI")
-}
-
-pub fn play() {
- build_request(BODY_PLAY, "urn:schemas-upnp-org:service:AVTransport:1#Play")
-}
+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";
--
cgit v1.3.1