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.
6 const MIME_TYPE = "application/octet-stream";
9 return document.getElementById(id);
13 function success(stream) {
14 track = stream.getVideoTracks()[0];
15 var video = $('video')
16 video.src = URL.createObjectURL(stream);
20 var list = $('profileList');
21 var profile = (list.length < 1) ? 'vp8'
22 : list.options[list.selectedIndex].value;
24 common.naclModule.postMessage({
34 common.logMessage("Error: " + e);
37 function cleanupDownload() {
38 var download = $('download');
41 download.parentNode.removeChild(download);
44 function appendDownload(parent, blob, filename) {
45 var a = document.createElement('a');
47 a.download = filename;
48 a.href = window.URL.createObjectURL(blob);
49 a.textContent = 'Download';
50 a.dataset.downloadurl = [MIME_TYPE, a.download, a.href].join(':');
51 parent.appendChild(a);
54 function startRecord() {
55 $('length').innerHTML = ' Size: ' + dataArray.byteLength + ' bytes';
56 navigator.webkitGetUserMedia({audio: false, video: true},
59 $('start').disabled = true;
60 $('stop').disabled = false;
64 function stopRecord() {
65 common.naclModule.postMessage({
68 var video = $('video');
73 $('start').disabled = false;
74 $('stop').disabled = true;
75 appendDownload($('download-box'),
76 new Blob([dataArray], { type: MIME_TYPE }),
80 function handleMessage(msg) {
81 if (msg.data.name == 'data') {
82 appendData(msg.data.data);
83 } else if (msg.data.name == 'supportedProfiles') {
84 common.logMessage('profiles: ' + JSON.stringify(msg.data.profiles));
85 var profileList = $('profileList');
86 for (var node in profileList.childNodes)
87 profileList.remove(node);
88 for (var i = 0; i < msg.data.profiles.length; i++) {
89 var item = document.createElement('option');
90 item.label = item.value = msg.data.profiles[i];
91 profileList.appendChild(item);
93 $('start').disabled = !(msg.data.profiles.length > 0);
94 } else if (msg.data.name == 'log') {
95 common.logMessage(msg.data.message);
99 function resetData() {
100 dataArray = new ArrayBuffer(0);
103 function appendData(data) {
104 var tmp = new Uint8Array(dataArray.byteLength + data.byteLength);
105 tmp.set(new Uint8Array(dataArray), 0 );
106 tmp.set(new Uint8Array(data), dataArray.byteLength);
107 dataArray = tmp.buffer;
108 $('length').textContent = ' Size: ' + dataArray.byteLength + ' bytes';
111 function attachListeners() {
112 $('start').addEventListener('click', function (e) {
116 $('stop').addEventListener('click', function (e) {
121 // Called by the common.js module.
122 function moduleDidLoad() {
123 // The module is not hidden by default so we can easily see if the plugin