Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | d4655fa | 2013-01-11 05:41:39 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Rebekah Potter | 952290e | 2022-11-18 09:07:28 | [diff] [blame] | 5 | import {addWebUiListener, sendWithPromise} from 'chrome://resources/js/cr.js'; |
dpapad | 303c9281 | 2023-10-31 02:08:35 | [diff] [blame] | 6 | import {$} from 'chrome://resources/js/util.js'; |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 7 | |
dpapad | 303c9281 | 2023-10-31 02:08:35 | [diff] [blame] | 8 | import {createIceCandidateGrid, updateIceCandidateGrid} from './candidate_grid.js'; |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 9 | import {MAX_STATS_DATA_POINT_BUFFER_SIZE} from './data_series.js'; |
| 10 | import {DumpCreator, peerConnectionDataStore, userMediaRequests} from './dump_creator.js'; |
| 11 | import {PeerConnectionUpdateTable} from './peer_connection_update_table.js'; |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 12 | import {drawSingleReport, removeStatsReportGraphs} from './stats_graph_helper.js'; |
| 13 | import {StatsRatesCalculator, StatsReport} from './stats_rates_calculator.js'; |
| 14 | import {StatsTable} from './stats_table.js'; |
| 15 | import {TabView} from './tab_view.js'; |
Philipp Hancke | 6f8193b3 | 2023-09-19 08:05:37 | [diff] [blame] | 16 | import {UserMediaTable} from './user_media_table.js'; |
[email protected] | 8cb570c | 2014-07-22 00:07:32 | [diff] [blame] | 17 | |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 18 | let tabView = null; |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 19 | let peerConnectionUpdateTable = null; |
| 20 | let statsTable = null; |
[email protected] | deb232b | 2022-11-28 11:22:16 | [diff] [blame] | 21 | let userMediaTable = null; |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 22 | let dumpCreator = null; |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 23 | |
Philipp Hancke | 78815014 | 2023-09-21 07:19:54 | [diff] [blame] | 24 | const searchParameters = new URLSearchParams(window.location.search); |
| 25 | |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 26 | /** Maps from id (see getPeerConnectionId) to StatsRatesCalculator. */ |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 27 | const statsRatesCalculatorById = new Map(); |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 28 | |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 29 | /** A simple class to store the updates and stats data for a peer connection. */ |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 30 | /** @constructor */ |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 31 | class PeerConnectionRecord { |
| 32 | constructor() { |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 33 | /** @private */ |
| 34 | this.record_ = { |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 35 | pid: -1, |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 36 | constraints: {}, |
[email protected] | c13db2d | 2014-07-25 20:24:54 | [diff] [blame] | 37 | rtcConfiguration: [], |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 38 | stats: {}, |
| 39 | updateLog: [], |
| 40 | url: '', |
| 41 | }; |
Philipp Hancke | 949b72f | 2018-05-07 18:11:35 | [diff] [blame] | 42 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 43 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 44 | /** @override */ |
| 45 | toJSON() { |
| 46 | return this.record_; |
| 47 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 48 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 49 | /** |
| 50 | * Adds the initialization info of the peer connection. |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 51 | * @param {number} pid The pid of the process hosting the peer connection. |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 52 | * @param {string} url The URL of the web page owning the peer connection. |
| 53 | * @param {Array} rtcConfiguration |
| 54 | * @param {!Object} constraints Media constraints. |
| 55 | */ |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 56 | initialize(pid, url, rtcConfiguration, constraints) { |
| 57 | this.record_.pid = pid; |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 58 | this.record_.url = url; |
| 59 | this.record_.rtcConfiguration = rtcConfiguration; |
| 60 | this.record_.constraints = constraints; |
| 61 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 62 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 63 | resetStats() { |
| 64 | this.record_.stats = {}; |
| 65 | } |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 66 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 67 | /** |
| 68 | * @param {string} dataSeriesId The TimelineDataSeries identifier. |
| 69 | * @return {!TimelineDataSeries} |
| 70 | */ |
| 71 | getDataSeries(dataSeriesId) { |
| 72 | return this.record_.stats[dataSeriesId]; |
| 73 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 74 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 75 | /** |
| 76 | * @param {string} dataSeriesId The TimelineDataSeries identifier. |
| 77 | * @param {!TimelineDataSeries} dataSeries The TimelineDataSeries to set to. |
| 78 | */ |
| 79 | setDataSeries(dataSeriesId, dataSeries) { |
| 80 | this.record_.stats[dataSeriesId] = dataSeries; |
| 81 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 82 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 83 | /** |
| 84 | * @param {!Object} update The object contains keys "time", "type", and |
| 85 | * "value". |
| 86 | */ |
| 87 | addUpdate(update) { |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 88 | const time = new Date(parseFloat(update.time)); |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 89 | this.record_.updateLog.push({ |
Philipp Hancke | 59d6e9a5 | 2025-07-22 12:09:01 | [diff] [blame] | 90 | timestamp: parseFloat(update.time), |
| 91 | time: time.toLocaleString(), // deprecated, prefer timestamp. |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 92 | type: update.type, |
| 93 | value: update.value, |
| 94 | }); |
| 95 | } |
| 96 | } |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 97 | |
[email protected] | d4655fa | 2013-01-11 05:41:39 | [diff] [blame] | 98 | function initialize() { |
[email protected] | 31e9184 | 2013-11-08 19:06:15 | [diff] [blame] | 99 | dumpCreator = new DumpCreator($('content-root')); |
Philipp Hancke | 015dac8 | 2023-04-14 07:47:50 | [diff] [blame] | 100 | |
[email protected] | 31e9184 | 2013-11-08 19:06:15 | [diff] [blame] | 101 | tabView = new TabView($('content-root')); |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 102 | peerConnectionUpdateTable = new PeerConnectionUpdateTable(); |
Philipp Hancke | ba4adef | 2023-12-20 14:43:13 | [diff] [blame] | 103 | statsTable = new StatsTable(); |
[email protected] | deb232b | 2022-11-28 11:22:16 | [diff] [blame] | 104 | userMediaTable = new UserMediaTable(tabView, userMediaRequests); |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 105 | |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 106 | // Add listeners for all the updates that get sent from webrtc_internals.cc. |
Rebekah Potter | 952290e | 2022-11-18 09:07:28 | [diff] [blame] | 107 | addWebUiListener('add-peer-connection', addPeerConnection); |
| 108 | addWebUiListener('update-peer-connection', updatePeerConnection); |
| 109 | addWebUiListener('update-all-peer-connections', updateAllPeerConnections); |
| 110 | addWebUiListener('remove-peer-connection', removePeerConnection); |
| 111 | addWebUiListener('add-standard-stats', addStandardStats); |
[email protected] | deb232b | 2022-11-28 11:22:16 | [diff] [blame] | 112 | addWebUiListener('add-media', (data) => { |
| 113 | userMediaRequests.push(data); |
| 114 | userMediaTable.addMedia(data) |
| 115 | }); |
| 116 | addWebUiListener('update-media', (data) => { |
| 117 | userMediaRequests.push(data); |
| 118 | userMediaTable.updateMedia(data); |
| 119 | }); |
| 120 | addWebUiListener('remove-media-for-renderer', (data) => { |
| 121 | for (let i = userMediaRequests.length - 1; i >= 0; --i) { |
| 122 | if (userMediaRequests[i].rid === data.rid) { |
| 123 | userMediaRequests.splice(i, 1); |
| 124 | } |
| 125 | } |
| 126 | userMediaTable.removeMediaForRenderer(data); |
| 127 | }); |
Rebekah Potter | 952290e | 2022-11-18 09:07:28 | [diff] [blame] | 128 | addWebUiListener( |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 129 | 'event-log-recordings-file-selection-cancelled', |
| 130 | eventLogRecordingsFileSelectionCancelled); |
Rebekah Potter | 952290e | 2022-11-18 09:07:28 | [diff] [blame] | 131 | addWebUiListener( |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 132 | 'audio-debug-recordings-file-selection-cancelled', |
| 133 | audioDebugRecordingsFileSelectionCancelled); |
Philip Eliasson | 9b5072d4 | 2025-05-13 13:13:49 | [diff] [blame] | 134 | addWebUiListener( |
| 135 | 'data-channel-recordings-file-selection-cancelled', |
| 136 | dataChannelRecordingsFileSelectionCancelled); |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 137 | |
| 138 | // Request initial startup parameters. |
| 139 | sendWithPromise('finishedDOMLoad').then(params => { |
| 140 | if (params.audioDebugRecordingsEnabled) { |
| 141 | dumpCreator.setAudioDebugRecordingsCheckbox(); |
| 142 | } |
| 143 | if (params.eventLogRecordingsEnabled) { |
| 144 | dumpCreator.setEventLogRecordingsCheckbox(); |
| 145 | } |
Philip Eliasson | 9b5072d4 | 2025-05-13 13:13:49 | [diff] [blame] | 146 | if (params.dataChannelRecordingsEnabled) { |
| 147 | dumpCreator.setDataChannelRecordingsCheckbox(); |
| 148 | } |
rbpotter | 5796b00 | 2021-03-10 18:49:21 | [diff] [blame] | 149 | dumpCreator.setEventLogRecordingsCheckboxMutability( |
| 150 | params.eventLogRecordingsToggleable); |
| 151 | }); |
[email protected] | 6efd5f2 | 2013-02-06 19:20:37 | [diff] [blame] | 152 | |
Philipp Hancke | f212a84 | 2022-08-19 08:03:03 | [diff] [blame] | 153 | // Requests stats from all peer connections every second unless specified via |
| 154 | // ?statsInterval=(milliseconds >= 100ms) |
Philipp Hancke | f212a84 | 2022-08-19 08:03:03 | [diff] [blame] | 155 | let statsInterval = 1000; |
| 156 | if (searchParameters.has('statsInterval')) { |
| 157 | statsInterval = Math.max( |
| 158 | parseInt(searchParameters.get('statsInterval'), 10), |
| 159 | 100); |
| 160 | if (!isFinite(statsInterval)) { |
| 161 | statsInterval = 1000; |
| 162 | } |
| 163 | } |
| 164 | window.setInterval(requestStats, statsInterval); |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 165 | } |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 166 | document.addEventListener('DOMContentLoaded', initialize); |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 167 | |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 168 | /** |
| 169 | * Sends a request to the browser to get peer connection statistics from the |
| 170 | * standard getStats() API (promise-based). |
| 171 | */ |
Henrik Boström | 80fb1ff3 | 2023-12-07 18:58:22 | [diff] [blame] | 172 | function requestStats() { |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 173 | if (Object.keys(peerConnectionDataStore).length > 0) { |
| 174 | chrome.send('getStandardStats'); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 179 | * A helper function for getting a peer connection element id. |
| 180 | * |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 181 | * @param {!Object<number>} data The object containing the rid and lid of the |
thestig | 7779e7d | 2015-05-30 07:48:30 | [diff] [blame] | 182 | * peer connection. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 183 | * @return {string} The peer connection element id. |
| 184 | */ |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 185 | function getPeerConnectionId(data) { |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 186 | return data.rid + '-' + data.lid; |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 189 | /** |
[email protected] | 8cb570c | 2014-07-22 00:07:32 | [diff] [blame] | 190 | * A helper function for appending a child element to |parent|. |
| 191 | * |
| 192 | * @param {!Element} parent The parent element. |
| 193 | * @param {string} tag The child element tag. |
| 194 | * @param {string} text The textContent of the new DIV. |
| 195 | * @return {!Element} the new DIV element. |
| 196 | */ |
| 197 | function appendChildWithText(parent, tag, text) { |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 198 | const child = document.createElement(tag); |
[email protected] | 8cb570c | 2014-07-22 00:07:32 | [diff] [blame] | 199 | child.textContent = text; |
| 200 | parent.appendChild(child); |
| 201 | return child; |
| 202 | } |
| 203 | |
| 204 | /** |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 205 | * Helper for adding a peer connection update. |
| 206 | * |
| 207 | * @param {Element} peerConnectionElement |
| 208 | * @param {!PeerConnectionUpdateEntry} update The peer connection update data. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 209 | */ |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 210 | function addPeerConnectionUpdate(peerConnectionElement, update) { |
Nasko Oskov | 9303a066 | 2018-10-15 18:03:44 | [diff] [blame] | 211 | peerConnectionUpdateTable.addPeerConnectionUpdate( |
| 212 | peerConnectionElement, update); |
[email protected] | 84e83b3 | 2014-07-01 23:10:15 | [diff] [blame] | 213 | peerConnectionDataStore[peerConnectionElement.id].addUpdate(update); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | /** Browser message handlers. */ |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 218 | |
| 219 | |
| 220 | /** |
| 221 | * Removes all information about a peer connection. |
Philipp Hancke | 78815014 | 2023-09-21 07:19:54 | [diff] [blame] | 222 | * Use ?keepRemovedConnections url parameter to prevent the removal. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 223 | * |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 224 | * @param {!Object<number>} data The object containing the rid and lid of a peer |
thestig | 7779e7d | 2015-05-30 07:48:30 | [diff] [blame] | 225 | * connection. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 226 | */ |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 227 | function removePeerConnection(data) { |
Rebekah Potter | 8148f85 | 2022-11-29 18:04:37 | [diff] [blame] | 228 | // Disable getElementById restriction here, since |getPeerConnectionId| does |
| 229 | // not return valid selectors. |
| 230 | // eslint-disable-next-line no-restricted-properties |
Philipp Hancke | 78815014 | 2023-09-21 07:19:54 | [diff] [blame] | 231 | |
Rebekah Potter | 8148f85 | 2022-11-29 18:04:37 | [diff] [blame] | 232 | const element = document.getElementById(getPeerConnectionId(data)); |
Philipp Hancke | 78815014 | 2023-09-21 07:19:54 | [diff] [blame] | 233 | if (element && !searchParameters.has('keepRemovedConnections')) { |
Philipp Hancke | 43e64b17 | 2024-04-17 13:41:58 | [diff] [blame] | 234 | removeStatsReportGraphs(element); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 235 | delete peerConnectionDataStore[element.id]; |
fserb | 3c1769f | 2017-03-09 16:27:03 | [diff] [blame] | 236 | tabView.removeTab(element.id); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 237 | } |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 240 | /** |
| 241 | * Adds a peer connection. |
| 242 | * |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 243 | * @param {!Object} data The object containing the rid, lid, pid, url, |
[email protected] | c13db2d | 2014-07-25 20:24:54 | [diff] [blame] | 244 | * rtcConfiguration, and constraints of a peer connection. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 245 | */ |
[email protected] | 94fb510 | 2013-01-23 09:00:47 | [diff] [blame] | 246 | function addPeerConnection(data) { |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 247 | const id = getPeerConnectionId(data); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 248 | |
| 249 | if (!peerConnectionDataStore[id]) { |
| 250 | peerConnectionDataStore[id] = new PeerConnectionRecord(); |
| 251 | } |
| 252 | peerConnectionDataStore[id].initialize( |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 253 | data.pid, data.url, data.rtcConfiguration, data.constraints); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 254 | |
Rebekah Potter | 8148f85 | 2022-11-29 18:04:37 | [diff] [blame] | 255 | // Disable getElementById restriction here, since |id| is not always |
| 256 | // a valid selector. |
| 257 | // eslint-disable-next-line no-restricted-properties |
| 258 | let peerConnectionElement = document.getElementById(id); |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 259 | if (!peerConnectionElement) { |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 260 | const details = `[ rid: ${data.rid}, lid: ${data.lid}, pid: ${data.pid} ]`; |
| 261 | peerConnectionElement = tabView.addTab(id, data.url + " " + details); |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 262 | } |
jiayl | 857722c8 | 2015-02-24 18:27:39 | [diff] [blame] | 263 | |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 264 | const p = document.createElement('p'); |
Philipp Hancke | 3398097 | 2021-03-25 07:48:12 | [diff] [blame] | 265 | appendChildWithText(p, 'span', data.url); |
| 266 | appendChildWithText(p, 'span', ', '); |
| 267 | appendChildWithText(p, 'span', data.rtcConfiguration); |
| 268 | if (data.constraints !== '') { |
| 269 | appendChildWithText(p, 'span', ', '); |
| 270 | appendChildWithText(p, 'span', data.constraints); |
| 271 | } |
jiayl | 857722c8 | 2015-02-24 18:27:39 | [diff] [blame] | 272 | peerConnectionElement.appendChild(p); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 273 | |
Philipp Hancke | 6cd4079 | 2021-04-29 07:55:52 | [diff] [blame] | 274 | // Show deprecation notices as a list. |
| 275 | // Note: data.rtcConfiguration is not in JSON format and may |
| 276 | // not be defined in tests. |
Philipp Hancke | b20fd03 | 2021-09-08 07:32:43 | [diff] [blame] | 277 | const deprecationNotices = document.createElement('ul'); |
Philipp Hancke | 6cd4079 | 2021-04-29 07:55:52 | [diff] [blame] | 278 | if (data.rtcConfiguration) { |
Philipp Hancke | 6cd4079 | 2021-04-29 07:55:52 | [diff] [blame] | 279 | deprecationNotices.className = 'peerconnection-deprecations'; |
Philipp Hancke | 6cd4079 | 2021-04-29 07:55:52 | [diff] [blame] | 280 | } |
Philipp Hancke | b20fd03 | 2021-09-08 07:32:43 | [diff] [blame] | 281 | peerConnectionElement.appendChild(deprecationNotices); |
Philipp Hancke | 6cd4079 | 2021-04-29 07:55:52 | [diff] [blame] | 282 | |
Philipp Hancke | 9b812b5d | 2021-10-12 18:06:16 | [diff] [blame] | 283 | const iceConnectionStates = document.createElement('div'); |
| 284 | iceConnectionStates.textContent = 'ICE connection state: new'; |
| 285 | iceConnectionStates.className = 'iceconnectionstate'; |
| 286 | peerConnectionElement.appendChild(iceConnectionStates); |
| 287 | |
| 288 | const connectionStates = document.createElement('div'); |
| 289 | connectionStates.textContent = 'Connection state: new'; |
| 290 | connectionStates.className = 'connectionstate'; |
| 291 | peerConnectionElement.appendChild(connectionStates); |
| 292 | |
| 293 | const signalingStates = document.createElement('div'); |
| 294 | signalingStates.textContent = 'Signaling state: new'; |
| 295 | signalingStates.className = 'signalingstate'; |
| 296 | peerConnectionElement.appendChild(signalingStates); |
| 297 | |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 298 | const candidatePair = document.createElement('div'); |
| 299 | candidatePair.textContent = 'ICE Candidate pair: '; |
| 300 | candidatePair.className = 'candidatepair'; |
| 301 | candidatePair.appendChild(document.createElement('span')); |
| 302 | peerConnectionElement.appendChild(candidatePair); |
| 303 | |
Philipp Hancke | cd79cbf | 2021-11-17 14:11:52 | [diff] [blame] | 304 | createIceCandidateGrid(peerConnectionElement); |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 305 | return peerConnectionElement; |
| 306 | } |
| 307 | |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 308 | |
| 309 | /** |
| 310 | * Adds a peer connection update. |
| 311 | * |
| 312 | * @param {!PeerConnectionUpdateEntry} data The peer connection update data. |
| 313 | */ |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 314 | function updatePeerConnection(data) { |
Rebekah Potter | 8148f85 | 2022-11-29 18:04:37 | [diff] [blame] | 315 | // Disable getElementById restriction here, since |getPeerConnectionId| does |
| 316 | // not return valid selectors. |
| 317 | const peerConnectionElement = |
| 318 | // eslint-disable-next-line no-restricted-properties |
| 319 | document.getElementById(getPeerConnectionId(data)); |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 320 | addPeerConnectionUpdate(peerConnectionElement, data); |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 321 | } |
| 322 | |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 323 | |
| 324 | /** |
| 325 | * Adds the information of all peer connections created so far. |
| 326 | * |
Dan Beam | b9749f41 | 2015-02-14 02:42:50 | [diff] [blame] | 327 | * @param {Array<!Object>} data An array of the information of all peer |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 328 | * connections. Each array item contains rid, lid, pid, url, |
| 329 | * rtcConfiguration, constraints, and an array of updates as the log. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 330 | */ |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 331 | function updateAllPeerConnections(data) { |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 332 | for (let i = 0; i < data.length; ++i) { |
| 333 | const peerConnection = addPeerConnection(data[i]); |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 334 | |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 335 | const log = data[i].log; |
Dan Beam | bdd7d82 | 2019-01-05 00:59:42 | [diff] [blame] | 336 | if (!log) { |
[email protected] | 2138463 | 2013-09-20 21:18:15 | [diff] [blame] | 337 | continue; |
Dan Beam | bdd7d82 | 2019-01-05 00:59:42 | [diff] [blame] | 338 | } |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 339 | for (let j = 0; j < log.length; ++j) { |
[email protected] | 4d41b80 | 2013-05-15 18:38:23 | [diff] [blame] | 340 | addPeerConnectionUpdate(peerConnection, log[j]); |
[email protected] | c054f09 | 2013-01-27 08:12:49 | [diff] [blame] | 341 | } |
| 342 | } |
[email protected] | 0a681b4 | 2014-02-19 01:56:32 | [diff] [blame] | 343 | requestStats(); |
[email protected] | d4655fa | 2013-01-11 05:41:39 | [diff] [blame] | 344 | } |
| 345 | |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 346 | /** |
Henrik Boström | 33ece3e9 | 2019-04-23 10:08:53 | [diff] [blame] | 347 | * Handles the report of stats originating from the standard getStats() API. |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 348 | * |
Patrick Monette | ce1ee72 | 2021-03-30 18:41:05 | [diff] [blame] | 349 | * @param {!Object} data The object containing rid, lid, and reports, where |
[email protected] | 2746df9 | 2013-04-26 23:42:32 | [diff] [blame] | 350 | * reports is an array of stats reports. Each report contains id, type, |
| 351 | * and stats, where stats is the object containing timestamp and values, |
| 352 | * which is an array of strings, whose even index entry is the name of the |
| 353 | * stat, and the odd index entry is the value. |
| 354 | */ |
Henrik Boström | 33ece3e9 | 2019-04-23 10:08:53 | [diff] [blame] | 355 | function addStandardStats(data) { |
Rebekah Potter | 8148f85 | 2022-11-29 18:04:37 | [diff] [blame] | 356 | // Disable getElementById restriction here, since |getPeerConnectionId| does |
| 357 | // not return valid selectors. |
| 358 | // eslint-disable-next-line no-restricted-properties |
| 359 | const peerConnectionElement = |
| 360 | // eslint-disable-next-line no-restricted-properties |
| 361 | document.getElementById(getPeerConnectionId(data)); |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 362 | if (!peerConnectionElement) { |
| 363 | return; |
| 364 | } |
| 365 | const pcId = getPeerConnectionId(data); |
| 366 | let statsRatesCalculator = statsRatesCalculatorById.get(pcId); |
| 367 | if (!statsRatesCalculator) { |
| 368 | statsRatesCalculator = new StatsRatesCalculator(); |
| 369 | statsRatesCalculatorById.set(pcId, statsRatesCalculator); |
| 370 | } |
| 371 | const r = StatsReport.fromInternalsReportList(data.reports); |
| 372 | statsRatesCalculator.addStatsReport(r); |
| 373 | data.reports = statsRatesCalculator.currentReport.toInternalsReportList(); |
Philipp Hancke | 0635d314 | 2021-03-16 20:02:09 | [diff] [blame] | 374 | for (let i = 0; i < data.reports.length; ++i) { |
| 375 | const report = data.reports[i]; |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 376 | statsTable.addStatsReport(peerConnectionElement, report); |
Philipp Hancke | ba4adef | 2023-12-20 14:43:13 | [diff] [blame] | 377 | drawSingleReport(peerConnectionElement, report); |
Henrik Boström | b6d732af | 2019-04-23 11:32:29 | [diff] [blame] | 378 | } |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 379 | // Determine currently connected candidate pair. |
| 380 | const stats = r.statsById; |
| 381 | |
Philipp Hancke | 9edd62d3 | 2025-07-25 15:04:42 | [diff] [blame] | 382 | let ids = []; |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 383 | stats.forEach(report => { |
Philipp Hancke | 9edd62d3 | 2025-07-25 15:04:42 | [diff] [blame] | 384 | if (!(report.type === 'transport' && report.selectedCandidatePairId)) { |
| 385 | return; |
| 386 | } |
| 387 | const activeCandidatePair = stats.get(report.selectedCandidatePairId); |
| 388 | const remoteCandidate = stats.get(activeCandidatePair.remoteCandidateId); |
| 389 | const localCandidate = stats.get(activeCandidatePair.localCandidateId); |
| 390 | |
| 391 | const candidateElement = peerConnectionElement |
| 392 | .getElementsByClassName('candidatepair')[0].firstElementChild; |
| 393 | candidateElement.innerText = ''; |
| 394 | if (!(localCandidate && remoteCandidate)) { |
| 395 | return; |
| 396 | candidateElement.innerText = '(not connected)'; |
| 397 | } |
| 398 | |
| 399 | if (localCandidate.address && |
| 400 | localCandidate.address.indexOf(':') !== -1) { |
| 401 | // Show IPv6 in [] |
| 402 | candidateElement.innerText +='[' + localCandidate.address + ']'; |
| 403 | } else { |
| 404 | candidateElement.innerText += localCandidate.address || '(not set)'; |
| 405 | } |
| 406 | candidateElement.innerText += ':' + localCandidate.port + ' <=> '; |
| 407 | |
| 408 | if (remoteCandidate.address && |
| 409 | remoteCandidate.address.indexOf(':') !== -1) { |
| 410 | // Show IPv6 in [] |
| 411 | candidateElement.innerText +='[' + remoteCandidate.address + ']'; |
| 412 | } else { |
| 413 | candidateElement.innerText += remoteCandidate.address || '(not set)'; |
| 414 | } |
| 415 | candidateElement.innerText += ':' + remoteCandidate.port; |
| 416 | ids = ids.concat([ |
| 417 | peerConnectionElement.id + '-table-' + activeCandidatePair.id, |
| 418 | peerConnectionElement.id + '-table-' + localCandidate.id, |
| 419 | peerConnectionElement.id + '-table-' + remoteCandidate.id, |
| 420 | ]); |
| 421 | }); |
| 422 | console.log('IDS', ids); |
| 423 | // Mark active local-candidate, remote candidate and candidate pair |
| 424 | // bold in the table. |
| 425 | // Disable getElementById restriction here, since |peerConnectionElement| |
| 426 | // doesn't always have a valid selector ID. |
| 427 | // First remove bold from each, then re-add for each active pair.. |
| 428 | const statsContainer = |
| 429 | // eslint-disable-next-line no-restricted-properties |
| 430 | document.getElementById(peerConnectionElement.id + '-table-container'); |
| 431 | const activeConnectionClass = 'stats-table-active-connection'; |
| 432 | statsContainer.childNodes.forEach(node => { |
| 433 | if (node.nodeName !== 'DETAILS' || !node.children[1]) { |
| 434 | return; |
| 435 | } |
| 436 | if (ids.includes(node.children[1].id)) { |
| 437 | node.firstElementChild.classList.add(activeConnectionClass); |
| 438 | } else { |
| 439 | node.firstElementChild.classList.remove(activeConnectionClass); |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 440 | } |
| 441 | }); |
| 442 | |
Philipp Hancke | 9edd62d3 | 2025-07-25 15:04:42 | [diff] [blame] | 443 | // Mark active candidate-pair graph bold. |
| 444 | const statsGraphContainers = peerConnectionElement |
| 445 | .getElementsByClassName('stats-graph-container'); |
| 446 | for (let i = 0; i < statsGraphContainers.length; i++) { |
| 447 | const node = statsGraphContainers[i]; |
| 448 | if (node.nodeName !== 'DETAILS') { |
| 449 | continue; |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 450 | } |
Philipp Hancke | 9edd62d3 | 2025-07-25 15:04:42 | [diff] [blame] | 451 | if (ids.includes(node.children[1].id)) { |
| 452 | node.firstElementChild.classList.add(activeConnectionClass); |
| 453 | } else { |
| 454 | node.firstElementChild.classList.remove(activeConnectionClass); |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 455 | } |
Philipp Hancke | 1d84f9c | 2021-10-27 08:55:22 | [diff] [blame] | 456 | } |
Philipp Hancke | cd79cbf | 2021-11-17 14:11:52 | [diff] [blame] | 457 | |
| 458 | updateIceCandidateGrid(peerConnectionElement, r.statsById); |
Henrik Boström | 33ece3e9 | 2019-04-23 10:08:53 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
grunell | 7566ffc | 2015-09-07 07:39:44 | [diff] [blame] | 462 | * Notification that the audio debug recordings file selection dialog was |
| 463 | * cancelled, i.e. recordings have not been enabled. |
[email protected] | 09f12a0 | 2014-03-28 16:54:08 | [diff] [blame] | 464 | */ |
grunell | 7566ffc | 2015-09-07 07:39:44 | [diff] [blame] | 465 | function audioDebugRecordingsFileSelectionCancelled() { |
Henrik Grunell | 878f9427 | 2017-08-24 13:08:57 | [diff] [blame] | 466 | dumpCreator.clearAudioDebugRecordingsCheckbox(); |
[email protected] | 09f12a0 | 2014-03-28 16:54:08 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | |
[email protected] | bf3657b | 2013-12-17 12:36:17 | [diff] [blame] | 470 | /** |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 471 | * Notification that the event log recordings file selection dialog was |
| 472 | * cancelled, i.e. recordings have not been enabled. |
| 473 | */ |
| 474 | function eventLogRecordingsFileSelectionCancelled() { |
Henrik Grunell | 878f9427 | 2017-08-24 13:08:57 | [diff] [blame] | 475 | dumpCreator.clearEventLogRecordingsCheckbox(); |
ivoc | add54f0d | 2015-12-18 23:17:05 | [diff] [blame] | 476 | } |
Philip Eliasson | 9b5072d4 | 2025-05-13 13:13:49 | [diff] [blame] | 477 | |
| 478 | |
| 479 | function dataChannelRecordingsFileSelectionCancelled() { |
| 480 | dumpCreator.clearDataChannelRecordingsCheckbox(); |
| 481 | } |