4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <title>Enumerate Devices Example
</title>
10 <script type=
"text/javascript">
11 var device_array
= [];
12 var enumerating
= false;
14 function HandleMessage(message_event
) {
15 if (message_event
.data
) {
16 var status
= document
.getElementById('status');
17 if (message_event
.data
== 'EnumerationFailed') {
18 status
.innerText
= 'Device enumeration failed!';
21 message_event
.data
.substring('EnumerationSuccess'.length
);
22 if (devices_data
.length
> 0)
23 device_array
= devices_data
.split('#__#');
27 var list
= document
.getElementById('device_list');
28 if (device_array
.length
== 0)
29 list
.innerHTML
= 'No devices.';
30 for (var i
= 0; i
< device_array
.length
; ++i
) {
31 var list_item
= document
.createElement('li');
32 var span
= document
.createElement('span');
33 span
.innerText
= device_array
[i
];
34 list_item
.appendChild(span
);
35 list
.appendChild(list_item
);
37 status
.innerText
= 'Device enumeration success!';
43 function EnumerateDevices(sync
) {
47 var status
= document
.getElementById('status');
48 var plugin
= document
.getElementById('plugin');
50 status
.innerText
= 'Enumerating devices sync...'
51 plugin
.postMessage('EnumerateDevicesSync');
53 status
.innerText
= 'Enumerating devices async...'
54 plugin
.postMessage('EnumerateDevicesAsync');
58 function Initialize() {
59 var plugin
= document
.getElementById('plugin');
60 plugin
.addEventListener('message', HandleMessage
, false);
61 EnumerateDevices(true);
64 document
.addEventListener('DOMContentLoaded', Initialize
, false);
69 <embed id=
"plugin" type=
"application/x-ppapi-example-enumerate-devices"
72 Press a link to enumerate video devices:
74 <li><a href=
"javascript:EnumerateDevices(true)">Enumerate devices sync
</a>
75 (only implemented for out-of-process)
</li>
76 <li><a href=
"javascript:EnumerateDevices(false)">Enumerate devices async
</a></li>
79 <div id=
"available_devices">
81 <ul id=
"device_list">No devices.
</ul>
84 Status:
<span id=
"status"></span>