forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenumerate_devices.html
87 lines (81 loc) · 2.7 KB
/
enumerate_devices.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
<!DOCTYPE html>
<html>
<!--
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Enumerate Devices Example</title>
<script type="text/javascript">
var device_array = [];
var enumerating = false;
function HandleMessage(message_event) {
if (message_event.data) {
var status = document.getElementById('status');
if (message_event.data == 'EnumerationFailed') {
status.innerText = 'Device enumeration failed!';
} else {
devices_data =
message_event.data.substring('EnumerationSuccess'.length);
if (devices_data.length > 0)
device_array = devices_data.split('#__#');
else
device_array = [];
var list = document.getElementById('device_list');
if (device_array.length == 0)
list.innerHTML = 'No devices.';
for (var i = 0; i < device_array.length; ++i) {
var list_item = document.createElement('li');
var span = document.createElement('span');
span.innerText = device_array[i];
list_item.appendChild(span);
list.appendChild(list_item);
}
status.innerText = 'Device enumeration success!';
}
enumerating = false;
}
}
function EnumerateDevices(sync) {
if (enumerating)
return;
enumerating = true;
var status = document.getElementById('status');
var plugin = document.getElementById('plugin');
if (sync) {
status.innerText = 'Enumerating devices sync...'
plugin.postMessage('EnumerateDevicesSync');
} else {
status.innerText = 'Enumerating devices async...'
plugin.postMessage('EnumerateDevicesAsync');
}
}
function Initialize() {
var plugin = document.getElementById('plugin');
plugin.addEventListener('message', HandleMessage, false);
EnumerateDevices(true);
}
document.addEventListener('DOMContentLoaded', Initialize, false);
</script>
</head>
<body>
<embed id="plugin" type="application/x-ppapi-example-enumerate-devices"
width=0 height=0 />
<div>
Press a link to enumerate video devices:
<ul>
<li><a href="javascript:EnumerateDevices(true)">Enumerate devices sync</a>
(only implemented for out-of-process)</li>
<li><a href="javascript:EnumerateDevices(false)">Enumerate devices async</a></li>
</ul>
</div>
<div id="available_devices">
Available device(s):
<ul id="device_list">No devices.</ul>
</div>
<div>
Status: <span id="status"></span>
</div>
</body>
</html>