1// Copyright (c) 2013 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 6/** 7 * Provides the UI for dump creation. 8 */ 9var DumpCreator = (function() { 10 /** 11 * @param {Element} containerElement The parent element of the dump creation 12 * UI. 13 * @constructor 14 */ 15 function DumpCreator(containerElement) { 16 /** 17 * The root element of the dump creation UI. 18 * @type {Element} 19 * @private 20 */ 21 this.root_ = document.createElement('details'); 22 23 this.root_.className = 'peer-connection-dump-root'; 24 containerElement.appendChild(this.root_); 25 var summary = document.createElement('summary'); 26 this.root_.appendChild(summary); 27 summary.textContent = 'Create Dump'; 28 var content = document.createElement('div'); 29 this.root_.appendChild(content); 30 31 content.innerHTML = '<div><a><button>' + 32 'Download the PeerConnection updates and stats data' + 33 '</button></a></div>' + 34 '<p><label><input type=checkbox>' + 35 'Enable diagnostic audio recordings.</label></p>' + 36 '<p>A diagnostic audio recording is used for analyzing audio' + 37 ' problems. It contains the audio played out from the speaker and' + 38 ' recorded from the microphone and is saved to the local disk.' + 39 ' Checking this box will enable the recording for ongoing WebRTC' + 40 ' calls and for future WebRTC calls. When the box is unchecked or' + 41 ' this page is closed, all ongoing recordings will be stopped and' + 42 ' this recording functionality will be disabled for future WebRTC' + 43 ' calls. Recordings in multiple tabs are supported as well as' + 44 ' multiple recordings in the same tab. When enabling, you select a' + 45 ' base filename to save the dump(s) to. The base filename will have a' + 46 ' suffix appended to it as <base filename>.<render process' + 47 ' ID>.<recording ID>. If recordings are' + 48 ' disabled and then enabled using the same base filename, the' + 49 ' file(s) will be appended to and may become invalid. It is' + 50 ' recommended to choose a new base filename each time or move' + 51 ' the resulting files before enabling again. If track processing is' + 52 ' disabled (--disable-audio-track-processing): (1) Only one recording' + 53 ' per render process is supported. (2) When the box is unchecked or' + 54 ' this page is closed, ongoing recordings will continue until the' + 55 ' call ends or the page with the recording is closed.</p>'; 56 57 content.getElementsByTagName('a')[0].addEventListener( 58 'click', this.onDownloadData_.bind(this)); 59 content.getElementsByTagName('input')[0].addEventListener( 60 'click', this.onAecRecordingChanged_.bind(this)); 61 } 62 63 DumpCreator.prototype = { 64 // Mark the AEC recording checkbox checked. 65 enableAecRecording: function() { 66 this.root_.getElementsByTagName('input')[0].checked = true; 67 }, 68 69 // Mark the AEC recording checkbox unchecked. 70 disableAecRecording: function() { 71 this.root_.getElementsByTagName('input')[0].checked = false; 72 }, 73 74 /** 75 * Downloads the PeerConnection updates and stats data as a file. 76 * 77 * @private 78 */ 79 onDownloadData_: function() { 80 var dump_object = 81 { 82 'getUserMedia': userMediaRequests, 83 'PeerConnections': peerConnectionDataStore, 84 }; 85 var textBlob = new Blob([JSON.stringify(dump_object, null, ' ')], 86 {type: 'octet/stream'}); 87 var URL = window.URL.createObjectURL(textBlob); 88 89 var anchor = this.root_.getElementsByTagName('a')[0]; 90 anchor.href = URL; 91 anchor.download = 'webrtc_internals_dump.txt'; 92 // The default action of the anchor will download the URL. 93 }, 94 95 /** 96 * Handles the event of toggling the AEC recording state. 97 * 98 * @private 99 */ 100 onAecRecordingChanged_: function() { 101 var enabled = this.root_.getElementsByTagName('input')[0].checked; 102 if (enabled) { 103 chrome.send('enableAecRecording'); 104 } else { 105 chrome.send('disableAecRecording'); 106 } 107 }, 108 }; 109 return DumpCreator; 110})(); 111