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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// 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 to start and stop RTP recording, forwards the start/stop
* commands to Chrome, and updates the UI based on dump updates. Also provides
* creating a file containing all PeerConnection updates and stats.
*/
var DumpCreator = (function() {
/**
* @param {Element} containerElement The parent element of the dump creation
* UI.
* @constructor
*/
function DumpCreator(containerElement) {
/**
* True if the RTP packets are being recorded.
* @type {bool}
* @private
*/
this.recording_ = false;
/**
* @type {!Object.<string>}
* @private
* @const
*/
this.StatusStrings_ = {
NOT_STARTED: 'not started.',
RECORDING: 'recording...',
},
/**
* The status of dump creation.
* @type {string}
* @private
*/
this.status_ = this.StatusStrings_.NOT_STARTED;
/**
* 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('pre');
this.root_.appendChild(content);
content.innerHTML = '<button disabled></button> Status: <span></span>' +
'<div><a><button>' +
'Download the PeerConnection updates and stats data' +
'</button></a></div>';
content.getElementsByTagName('button')[0].addEventListener(
'click', this.onRtpToggled_.bind(this));
content.getElementsByTagName('a')[0].addEventListener(
'click', this.onDownloadData_.bind(this));
this.updateDisplay_();
}
DumpCreator.prototype = {
/**
* Downloads the PeerConnection updates and stats data as a file.
*
* @private
*/
onDownloadData_: function() {
var textBlob =
new Blob([JSON.stringify(peerConnectionDataStore, null, ' ')],
{type: 'octet/stream'});
var URL = window.webkitURL.createObjectURL(textBlob);
this.root_.getElementsByTagName('a')[0].href = URL;
// The default action of the anchor will download the URL.
},
/**
* Handles the event of toggling the rtp recording state.
*
* @private
*/
onRtpToggled_: function() {
if (this.recording_) {
this.recording_ = false;
this.status_ = this.StatusStrings_.NOT_STARTED;
chrome.send('stopRtpRecording');
} else {
this.recording_ = true;
this.status_ = this.StatusStrings_.RECORDING;
chrome.send('startRtpRecording');
}
this.updateDisplay_();
},
/**
* Updates the UI based on the recording status.
*
* @private
*/
updateDisplay_: function() {
if (this.recording_) {
this.root_.getElementsByTagName('button')[0].textContent =
'Stop Recording RTP Packets';
} else {
this.root_.getElementsByTagName('button')[0].textContent =
'Start Recording RTP Packets';
}
this.root_.getElementsByTagName('span')[0].textContent = this.status_;
},
/**
* Set the status to the content of the update.
* @param {!Object} update
*/
onUpdate: function(update) {
if (this.recording_) {
this.status_ = JSON.stringify(update);
this.updateDisplay_();
}
},
};
return DumpCreator;
})();
|