summaryrefslogtreecommitdiffstats
path: root/content/browser/resources/media/dump_creator.js
blob: 15d708b3daf3b1af00f431ed5096da458f8a1803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


/**
 * Provides the UI for dump creation.
 */
var DumpCreator = (function() {
  /**
   * @param {Element} containerElement The parent element of the dump creation
   *     UI.
   * @constructor
   */
  function DumpCreator(containerElement) {
    /**
     * The root element of the dump creation UI.
     * @type {Element}
     * @private
     */
    this.root_ = document.createElement('details');

    this.root_.className = 'peer-connection-dump-root';
    containerElement.appendChild(this.root_);
    var summary = document.createElement('summary');
    this.root_.appendChild(summary);
    summary.textContent = 'Create Dump';
    var content = document.createElement('div');
    this.root_.appendChild(content);

    content.innerHTML = '<div><a><button>' +
        'Download the PeerConnection updates and stats data' +
        '</button></a></div>' +
        '<p><label><input type=checkbox>' +
        'Enable diagnostic audio recordings.</label></p>' +
        '<p>A diagnostic audio recording is used for analyzing audio' +
        ' problems. It contains the audio played out from the speaker and' +
        ' recorded from the microphone and is saved to the local disk.' +
        ' Checking this box will enable the recording for ongoing WebRTC' +
        ' calls and for future WebRTC calls. When the box is unchecked or' +
        ' this page is closed, all ongoing recordings will be stopped and' +
        ' this recording functionality will be disabled for future WebRTC' +
        ' calls. Recordings in multiple tabs are supported as well as' +
        ' multiple recordings in the same tab. When enabling, you select a' +
        ' base filename to save the dump(s) to. The base filename will have a' +
        ' suffix appended to it as &lt;base filename&gt;.&lt;render process' +
        ' ID&gt;.&lt;recording ID&gt;. If recordings are' +
        ' disabled and then enabled using the same base filename, the' +
        ' file(s) will be appended to and may become invalid. It is' +
        ' recommended to choose a new base filename each time or move' +
        ' the resulting files before enabling again. If track processing is' +
        ' disabled (--disable-audio-track-processing): (1) Only one recording' +
        ' per render process is supported. (2) When the box is unchecked or' +
        ' this page is closed, ongoing recordings will continue until the' +
        ' call ends or the page with the recording is closed.</p>';

    content.getElementsByTagName('a')[0].addEventListener(
        'click', this.onDownloadData_.bind(this));
    content.getElementsByTagName('input')[0].addEventListener(
        'click', this.onAecRecordingChanged_.bind(this));
  }

  DumpCreator.prototype = {
    // Mark the AEC recording checkbox checked.
    enableAecRecording: function() {
      this.root_.getElementsByTagName('input')[0].checked = true;
    },

    // Mark the AEC recording checkbox unchecked.
    disableAecRecording: function() {
      this.root_.getElementsByTagName('input')[0].checked = false;
    },

    /**
     * Downloads the PeerConnection updates and stats data as a file.
     *
     * @private
     */
    onDownloadData_: function() {
      var dump_object =
      {
        'getUserMedia': userMediaRequests,
        'PeerConnections': peerConnectionDataStore,
      };
      var textBlob = new Blob([JSON.stringify(dump_object, null, ' ')],
                              {type: 'octet/stream'});
      var URL = window.URL.createObjectURL(textBlob);

      var anchor = this.root_.getElementsByTagName('a')[0];
      anchor.href = URL;
      anchor.download = 'webrtc_internals_dump.txt';
      // The default action of the anchor will download the URL.
    },

    /**
     * Handles the event of toggling the AEC recording state.
     *
     * @private
     */
    onAecRecordingChanged_: function() {
      var enabled = this.root_.getElementsByTagName('input')[0].checked;
      if (enabled) {
        chrome.send('enableAecRecording');
      } else {
        chrome.send('disableAecRecording');
      }
    },
  };
  return DumpCreator;
})();