blob: f1e3fece66fdf6d89cf171fabd143bb5a710d5ea [file] [log] [blame]
Philipp Hanckef91ac402022-10-17 11:05:061// Copyright 2022 The Chromium Authors
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 * @param {!Object} statsValues The object containing stats, an
7 * array [key1, val1, key2, val2, ...] so searching a certain
8 * key needs to ensure it does not collide with a value.
9 */
10function generateLabel(key, statsValues) {
11 let label = '';
12 const statIndex = statsValues.findIndex((value, index) => {
13 return value === key && index % 2 === 0;
14 });
15 if (statIndex !== -1) {
16 label += key + '=' + statsValues[statIndex + 1];
17 }
18 return label;
19}
20
21/**
22 * Formats the display text used for a stats type that is shown
23 * in the stats table or the stats graph.
24 *
25 * @param {!Object} report The object containing stats, which is the object
26 * containing timestamp and values, which is an array of strings, whose
27 * even index entry is the name of the stat, and the odd index entry is
28 * the value.
29 */
30export function generateStatsLabel(report) {
31 let label = report.type + ' (';
32 let labels = [];
Philipp Hancke7118bbf2023-01-09 16:15:5933 if (['outbound-rtp', 'remote-outbound-rtp', 'inbound-rtp',
34 'remote-inbound-rtp'].includes(report.type) && report.stats.values) {
[email protected]4dbb0032023-08-07 12:48:4035 labels = ['kind', 'mid', 'rid', 'ssrc', 'rtxSsrc', 'fecSsrc',
Philipp Hancke18f99862025-04-05 22:27:1036 'frameHeight', 'contentType',
[email protected]4dbb0032023-08-07 12:48:4037 'scalabilityMode',
Philipp Hanckeb6fb26f2023-06-09 14:17:3538 'encoderImplementation', 'decoderImplementation',
39 'powerEfficientEncoder', 'powerEfficientDecoder',
40 '[codec]'];
Philipp Hanckef91ac402022-10-17 11:05:0641 } else if (['local-candidate', 'remote-candidate'].includes(report.type)) {
Philipp Hancke61d227a2023-03-06 11:58:2842 labels = ['candidateType', 'tcpType', 'relayProtocol'];
Philipp Hanckef91ac402022-10-17 11:05:0643 } else if (report.type === 'codec') {
Philipp Hancke61d227a2023-03-06 11:58:2844 labels = ['mimeType', 'payloadType'];
Philipp Hancke9b386ff72023-02-15 10:03:0945 } else if (['media-playout', 'media-source'].includes(report.type)) {
Philipp Hancke61d227a2023-03-06 11:58:2846 labels = ['kind'];
Philipp Hanckef91ac402022-10-17 11:05:0647 } else if (report.type === 'candidate-pair') {
Philipp Hancke61d227a2023-03-06 11:58:2848 labels = ['state'];
49 } else if (report.type === 'transport') {
50 labels = ['iceState', 'dtlsState'];
Philipp Hanckeada4cb22025-06-18 06:28:3551 } else if (report.type === 'data-channel') {
52 labels = ['label', 'state'];
Philipp Hanckef91ac402022-10-17 11:05:0653 }
Philipp Hancke61d227a2023-03-06 11:58:2854 labels = labels
55 .map(stat => generateLabel(stat, report.stats.values))
56 .filter(label => !!label);
Philipp Hanckef91ac402022-10-17 11:05:0657 if (labels.length) {
58 label += labels.join(', ') + ', ';
59 }
60 label += 'id=' + report.id + ')';
61 return label;
62}