OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 function $(id) { | |
6 return document.getElementById(id); | |
7 } | |
8 | |
9 | |
10 function success(stream) { | |
11 track = stream.getVideoTracks()[0]; | |
12 var video = $('video') | |
13 video.src = URL.createObjectURL(stream); | |
14 video.track = track; | |
15 video.play(); | |
16 | |
17 var list = $('profileList'); | |
18 var profile = (list.length < 1) ? 'vp8' | |
19 : list.options[list.selectedIndex].value; | |
20 | |
21 common.naclModule.postMessage({ | |
22 command: 'start', | |
23 track: track, | |
24 profile: profile, | |
25 width: 640, | |
26 height: 480 | |
27 }); | |
28 } | |
29 | |
30 function failure(e) { | |
31 console.log("Error: ", e); | |
32 } | |
33 | |
34 function startRecord() { | |
35 $('length').innerHTML = ' Size: ' + window.dataArray.byteLength + ' bytes'; | |
binji
2015/03/31 17:41:19
please define global variables at the top of the f
llandwerlin-old
2015/04/02 09:59:01
Done.
| |
36 navigator.webkitGetUserMedia({audio: false, video: true}, | |
37 success, failure); | |
38 } | |
binji
2015/03/31 17:41:19
disable the start button and enable the stop butto
llandwerlin-old
2015/04/02 09:59:01
Done.
| |
39 | |
40 function stopRecord() { | |
41 common.naclModule.postMessage({ | |
42 command: "stop" | |
43 }); | |
44 var video = $('video'); | |
45 video.pause(); | |
46 video.track.stop(); | |
47 video.track = null; | |
48 } | |
binji
2015/03/31 17:41:19
disable the stop button and enable the start butto
llandwerlin-old
2015/04/02 09:59:00
Done.
| |
49 | |
50 function saveBlob(blob) { | |
51 var blobUrl = URL.createObjectURL(blob); | |
binji
2015/03/31 17:41:19
Use the html5 download attribute instead. That way
llandwerlin-old
2015/04/02 09:59:00
Done.
| |
52 window.location = blobUrl; | |
53 } | |
54 | |
55 function handleMessage(msg) { | |
56 if (msg.data.name == 'started') { | |
binji
2015/03/31 17:41:19
this message never fires on my machine -- I get an
llandwerlin-old
2015/04/02 09:59:01
You must have tested before https://codereview.chr
| |
57 console.log('recording!'); | |
binji
2015/03/31 17:41:19
display this to the user, not just the javascript
llandwerlin-old
2015/04/02 09:59:01
Done.
| |
58 } else if (msg.data.name == 'data') { | |
59 appendData(msg.data.data); | |
60 } else if (msg.data.name == 'stopped') { | |
61 console.log('done recording! bytes: ' + window.dataArray.byteLength); | |
binji
2015/03/31 17:41:19
common.logMessage
llandwerlin-old
2015/04/02 09:59:00
Done.
| |
62 } else if (msg.data.name == 'supportedProfiles') { | |
binji
2015/03/31 17:41:19
I tested this on my linux box and this message has
llandwerlin-old
2015/04/02 09:59:01
https://codereview.chromium.org/956893002 added su
| |
63 console.log('profiles: ', msg.data); | |
64 var profileList = $('profileList'); | |
65 for (var node in profileList.childNodes) | |
66 profileList.remove(node); | |
67 for (var i = 0; i < msg.data.profiles.length; i++) { | |
68 var item = document.createElement('option'); | |
69 item.label = item.value = msg.data.profiles[i]; | |
70 profileList.appendChild(item); | |
71 } | |
72 } | |
73 } | |
74 | |
75 function resetData() { | |
76 window.dataArray = new ArrayBuffer(0); | |
77 } | |
78 | |
79 function appendData(data) { | |
80 var tmp = new Uint8Array(window.dataArray.byteLength + data.byteLength); | |
81 tmp.set(new Uint8Array(window.dataArray), 0 ); | |
82 tmp.set(new Uint8Array(data), window.dataArray.byteLength); | |
83 window.dataArray = tmp.buffer; | |
84 $('length').innerHTML = ' Size: ' + window.dataArray.byteLength + ' bytes'; | |
binji
2015/03/31 17:41:19
use textContent instead of innerHTML
llandwerlin-old
2015/04/02 09:59:00
Done.
| |
85 } | |
86 | |
87 function attachListeners() { | |
88 $('start').addEventListener('click', function (e) { | |
89 resetData(); | |
90 startRecord(); | |
91 }); | |
92 $('stop').addEventListener('click', function (e) { | |
93 stopRecord(); | |
94 }); | |
95 $('download').addEventListener('click', function (e) { | |
96 saveBlob(new Blob([dataArray], { type: "application/octet-stream" })); | |
97 }); | |
98 } | |
99 | |
100 // Called by the common.js module. | |
101 function moduleDidLoad() { | |
102 // The module is not hidden by default so we can easily see if the plugin | |
103 // failed to load. | |
104 common.hideModule(); | |
105 common.naclModule.addEventListener('message', handleMessage, false); | |
106 } | |
OLD | NEW |