-
Notifications
You must be signed in to change notification settings - Fork 12
/
example.html
134 lines (96 loc) · 2.9 KB
/
example.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<script type="text/javascript" src="./lib/plug.upnp.js"></script>
<style>
#debug {
padding: 0.5em;
border: thin inset;
font: small monospace;
color: black;
}
</style>
<h1>Plug.UPnP Example: Muting a Media Renderer</h1>
<div id="debug"></div>
<script>
var debugEl = document.getElementById('debug');
function debugLog(msg) {
var logEl = document.createElement('div');
logEl.textContent = msg;
debugEl.appendChild( logEl );
}
function onServices( services ) {
debugLog( services.length + ' service'
+ ( services.length !== 1 ? 's' : '' ) +
' found in the current network' );
if( services.length === 0 ) {
return;
}
// Get the mute status for all services
for(var i = 0, l = services.length; i < l; i++ ) {
var service = services[ i ];
service._index = i;
var upnpService = new Plug.UPnP( service, { debug: false } );
// Let's mute the provided service (w/o API parameter type checking)
upnpService.action('GetMute', {
request: {
InstanceId: 0,
Channel: 'Master'
},
response: {
CurrentMute: {
type: upnpService.types.boolean
}
}
})
.then( function( response ) {
// Note: we don't need to check for '== "1"' below because
// response.data.CurrentMute is now a native JS boolean as we
// defined in our <actionParameters> above:
debugLog("Service[" + this.svc._index + "] is reporting MUTE=[" +
(response.data.CurrentMute ? 'on' : 'off') +
"]");
return this.action('SetMute', {
request: {
InstanceId: 0,
Channel: 'Master',
DesiredMute: response.data.CurrentMute ? 0 : 1
}
});
})
.then( function( response ) {
return this.action('GetMute', {
request: {
InstanceId: 0,
Channel: 'Master'
},
response: {
CurrentMute: {
type: upnpService.types.boolean
}
}
})
})
.then( function( response ) {
// Note: we don't need to check for '== "1"' below because
// response.data.CurrentMute is now a native JS boolean as we
// defined in our <actionParameters> above:
debugLog("Service[" + this.svc._index + "] is reporting MUTE=[" +
(response.data.CurrentMute ? 'on' : 'off') +
"]");
})
.then( null, function( error ) { // Handle any errors
debugLog( "An error occurred: " + error.description );
});
}
}
if( navigator.getNetworkServices ) {
debugLog('Searching for UPnP services in the current network...');
navigator.getNetworkServices(
['upnp:urn:schemas-upnp-org:service:RenderingControl:1'],
onServices,
function(e) {
debugLog( 'An error occurred obtaining UPnP Services [CODE: ' + error.code + ']');
});
} else {
debugLog('navigator.getNetworkServices API is not supported in this browser');
}
</script>