blob: 0d0877d94b4abda77dcacffa08359bea1c76ef36 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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#"<?xml version='1.0' encoding='utf-8'?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<CurrentURI>http://10.5.1.243:51497/0</CurrentURI>
<CurrentURIMetaData><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sec="http://www.sec.co.kr/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item id="0" parentID="-1" restricted="false"><upnp:class>object.item.videoItem.movie</upnp:class><dc:title>dlnanow</dc:title><res protocolInfo="http-get:*:video/mp4:*">http://10.5.1.243:51497/0</res></item></DIDL-Lite></CurrentURIMetaData>
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>"#;
const BODY_PLAY: &'static str = r#"
<?xml version='1.0' encoding='utf-8'?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<Speed>1</Speed>
</u:Play>
</s:Body>
</s:Envelope>"#;
const BODY_STOP: &'static str = r#"
<?xml version='1.0' encoding='utf-8'?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
</u:Stop>
</s:Body>
</s:Envelope>"#;
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")
}
|