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

content / browser / webrtc / resources / stats_helper.js [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @param {!Object} statsValues The object containing stats, an
 *     array [key1, val1, key2, val2, ...] so searching a certain
 *     key needs to ensure it does not collide with a value.
 */
function generateLabel(key, statsValues) {
  let label = '';
  const statIndex = statsValues.findIndex((value, index) => {
    return value === key && index % 2 === 0;
  });
  if (statIndex !== -1) {
    label += key + '=' + statsValues[statIndex + 1];
  }
  return label;
}

/**
 * Formats the display text used for a stats type that is shown
 * in the stats table or the stats graph.
 *
 * @param {!Object} report The object containing stats, which is the object
 *     containing timestamp and values, which is an array of strings, whose
 *     even index entry is the name of the stat, and the odd index entry is
 *     the value.
 */
export function generateStatsLabel(report) {
  let label = report.type + ' (';
  let labels = [];
  if (['outbound-rtp', 'remote-outbound-rtp', 'inbound-rtp',
      'remote-inbound-rtp'].includes(report.type) && report.stats.values) {
    labels = ['kind', 'mid', 'rid', 'ssrc', 'rtxSsrc', 'fecSsrc',
      'scalabilityMode',
      'encoderImplementation', 'decoderImplementation',
      'powerEfficientEncoder', 'powerEfficientDecoder',
      '[codec]'];
  } else if (['local-candidate', 'remote-candidate'].includes(report.type)) {
    labels = ['candidateType', 'tcpType', 'relayProtocol'];
  } else if (report.type === 'codec') {
    labels = ['mimeType', 'payloadType'];
  } else if (['media-playout', 'media-source'].includes(report.type)) {
    labels = ['kind'];
  } else if (report.type === 'candidate-pair') {
    labels = ['state'];
  } else if (report.type === 'transport') {
    labels = ['iceState', 'dtlsState'];
  }
  labels = labels
    .map(stat => generateLabel(stat, report.stats.values))
    .filter(label => !!label);
  if (labels.length) {
    label += labels.join(', ') + ', ';
  }
  label += 'id=' + report.id + ')';
  return label;
}