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>Video Capture Example
</title>
10 <script type=
"text/javascript">
11 var monitor_device_array
= [];
12 var enumerate_device_array
= [];
13 var monitor_notification_count
= 0;
15 function HandleMessage(message_event
) {
16 if (message_event
.data
) {
17 var status
= document
.getElementById('status');
18 if (message_event
.data
== 'EnumerationFailed') {
19 status
.innerText
= 'Device enumeration failed!';
20 } else if (message_event
.data
== 'MonitorDeviceChangeFailed') {
21 status
.innerText
= 'Monitor device change failed!';
22 } else if (message_event
.data
== 'OpenFailed') {
23 status
.innerText
= 'Open device failed!';
24 } else if (message_event
.data
== 'StartFailed') {
25 status
.innerText
= 'Start capturing failed!';
26 } else if (message_event
.data
== 'StopFailed') {
27 status
.innerText
= 'Stop capturing failed!';
29 AddDevices(message_event
.data
);
34 function AddDevices(command
) {
35 var serialized_names
= '';
36 var is_monitor
= false;
37 if (command
.search('Monitor:') == 0) {
38 serialized_names
= command
.substr(8);
40 monitor_notification_count
++;
41 var counter
= document
.getElementById('notification_counter');
42 counter
.innerText
= monitor_notification_count
;
43 } else if (command
.search('Enumerate:') == 0) {
44 serialized_names
= command
.substr(10);
46 status
.innerText
= 'Unrecognized command!';
50 var storage
= serialized_names
.length
!= 0 ?
51 serialized_names
.split('#__#') : [];
53 monitor_device_array
= storage
;
55 enumerate_device_array
= storage
;
57 var list
= document
.getElementById(
58 is_monitor
? 'monitor_list' : 'enumerate_list');
60 while (list
.firstChild
)
61 list
.removeChild(list
.firstChild
);
63 for (var i
= 0; i
< storage
.length
; ++i
) {
66 'javascript:UseDesignatedDevice(' + is_monitor
+ ',' + i
+ ');');
71 function AppendDevice(list
, text
, href
) {
72 var list_item
= document
.createElement('li');
73 var link
= document
.createElement('a');
75 link
.innerText
= text
;
76 list_item
.appendChild(link
);
77 list
.appendChild(list_item
);
80 function UseDesignatedDevice(is_monitor
, index
) {
82 UseDevice(monitor_device_array
[index
], 'Monitor:' + index
);
84 UseDevice(enumerate_device_array
[index
], 'Enumerate:' + index
);
87 function UseDefaultDevice() {
88 UseDevice('Default', 'UseDefault');
91 function UseDevice(display_text
, command
) {
92 var in_use_device
= document
.getElementById('in_use_device');
93 in_use_device
.innerText
= display_text
;
94 var plugin
= document
.getElementById('plugin');
95 plugin
.postMessage(command
);
97 var available_devices
= document
.getElementById('available_devices');
98 available_devices
.parentNode
.removeChild(available_devices
);
100 var control_panel
= document
.getElementById('control_panel');
101 control_panel
.style
.display
= '';
105 var plugin
= document
.getElementById('plugin');
106 plugin
.postMessage('Stop');
110 var plugin
= document
.getElementById('plugin');
111 plugin
.postMessage('Start');
114 function Initialize() {
115 var plugin
= document
.getElementById('plugin');
116 plugin
.addEventListener('message', HandleMessage
, false);
117 plugin
.postMessage('PageInitialized');
120 document
.addEventListener('DOMContentLoaded', Initialize
, false);
125 <embed id=
"plugin" type=
"application/x-ppapi-example-video-capture"
126 width=
"320" height=
"240"/>
127 <div style=
"margin-bottom:10px">In-use device:
128 <span id=
"in_use_device" style=
"font-weight:bold">None
</span>
130 <div id=
"available_devices">
131 Available device(s), choose one to open:
133 <li><a href=
"javascript:UseDefaultDevice();">
134 Default - use NULL device ref
</a></li>
137 <ul>List retrieved by MonitorDeviceChange(), will change when
138 pluging/unpluging devices: (Notifications received:
139 <span style=
"font-weight:bold" id=
"notification_counter">0</span>
141 <ul id=
"monitor_list"/>
144 <ul>List retrieved by EnumerateDevices(), never updated after the page is
146 <ul id=
"enumerate_list"/>
149 <div id=
"control_panel" style=
"display:none">
150 <a href=
"javascript:Stop();">Stop
</a>
151 <a href=
"javascript:Start();">Start
</a>
153 <div id=
"status"></div>