-
Notifications
You must be signed in to change notification settings - Fork 43
/
bwe.html
179 lines (171 loc) · 6.27 KB
/
bwe.html
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<html>
<head>
<meta charset="utf-8">
<title>Import webrtc-internals dumps -- just BWE</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<!-- highcharts is used under the terms of
http://shop.highsoft.com/faq/non-commercial
-->
<script src="https://code.highcharts.com/highcharts.js"></script>
<style>
body, body svg text {
font-family: monospace;
}
</style>
<script src="mangle.js"></script>
<script>
function decompress(baseStats, newStats) {
Object.keys(newStats).forEach(function(id) {
if (!baseStats[id]) {
baseStats[id] = newStats[id];
} else {
var report = newStats[id];
Object.keys(report).forEach(function(name) {
baseStats[id][name] = report[name];
});
}
});
return baseStats;
}
function doImport(evt) {
evt.target.disabled = 'disabled';
var files = evt.target.files;
var reader = new FileReader();
reader.onload = (function(file) {
return function(e) {
if (e.target.result.indexOf('\n') === -1) {
// old format
thelog = JSON.parse(e.target.result);
} else {
// new format, multiple lines
var baseStats = {};
var lines = e.target.result.split('\n');
var client = JSON.parse(lines.shift());
client.peerConnections = {};
client.getUserMedia = [];
lines.forEach(function(line) {
if (line.length) {
var data = JSON.parse(line);
var time = new Date(data.time || data[data.length - 1]);
delete data.time;
switch(data[0]) {
case 'getUserMedia':
case 'getUserMediaOnSuccess':
case 'getUserMediaOnFailure':
case 'navigator.mediaDevices.getUserMedia':
case 'navigator.mediaDevices.getUserMediaOnSuccess':
case 'navigator.mediaDevices.getUserMediaOnFailure':
client.getUserMedia.push({
time: time,
type: data[0],
value: data[2]
});
break;
default:
if (!client.peerConnections[data[1]]) {
client.peerConnections[data[1]] = [];
baseStats[data[1]] = {};
}
if (data[0] === 'getstats') { // delta-compressed
data[2] = decompress(baseStats[data[1]], data[2]);
baseStats[data[1]] = JSON.parse(JSON.stringify(data[2]));
}
if (data[0] === 'getStats' || data[0] === 'getstats') {
data[2] = mangle(data[2]);
data[0] = 'getStats';
}
client.peerConnections[data[1]].push({
time: time,
type: data[0],
value: data[2]
});
break;
}
}
});
thelog = client;
}
importUpdatesAndStats(thelog);
};
})(files[0]);
reader.readAsText(files[0]);
}
function processConnections(connectionIds, data) {
var connid = connectionIds.shift();
if (!connid) return;
window.setTimeout(processConnections, 0, connectionIds, data);
var reportname, statname;
var connection = data.peerConnections[connid];
// then, update the stats displays
var series = {};
var connectedOrCompleted = false;
var firstStats;
var lastStats;
for (var i = 0; i < connection.length; i++) {
if (connection[i].type === 'oniceconnectionstatechange' && (connection[i].value === 'connected' || connection[i].value === 'completed')) {
connectedOrCompleted = true;
}
if (connection[i].type === 'getStats' || connection[i].type === 'getstats') {
var stats = connection[i].value;
Object.keys(stats).forEach(function(id) {
if (stats[id].type !== 'VideoBwe') return;
if (stats[id].type === 'localcandidate' || stats[id].type === 'remotecandidate') return;
Object.keys(stats[id]).forEach(function(name) {
if (name === 'timestamp') return;
if (name !== 'availableIncomingBitrate') return;
//if (name === 'googMinPlayoutDelayMs') stats[id][name] = parseInt(stats[id][name], 10);
if (stats[id].type === 'ssrc' && !isNaN(parseInt(stats[id][name], 10))) {
stats[id][name] = parseInt(stats[id][name], 10);
}
if (stats[id].type === 'ssrc' && name === 'ssrc') return; // ignore ssrc on ssrc reports.
if (typeof stats[id][name] === 'number') {
if (!series[id]) series[id] = {};
if (!series[id][name]) series[id][name] = [];
series[id][name].push([new Date(connection[i].time).getTime(), stats[id][name]]);
}
});
});
}
}
graph.addSeries({
name: connid,
data: series['bweforvideo']['availableIncomingBitrate'],
});
}
var graph;
function importUpdatesAndStats(data) {
document.getElementById('userAgent').innerText = data.userAgent;
var d = document.createElement('div');
d.id = 'chart_' + Date.now();
document.getElementById('container').appendChild(d);
graph = new Highcharts.Chart({
title: {
text: 'available incoming bitrate'
},
xAxis: {
type: 'datetime'
},
/*
yAxis: {
min: 0
},
*/
chart: {
zoomType: 'x',
renderTo : d.id
},
series: []
});
window.setTimeout(processConnections, 0, Object.keys(data.peerConnections), data);
}
</script>
</head>
<body>
<form><input type="file" onchange="doImport(event)"></form>
<div><b>User Agent:</b><span id="userAgent"></span></div>
<div id="tables">
</div>
<div id="container" style="min-width: 95%; height: 400px; margin: 0 auto">
</div>
</body>
</html>