// 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. /** * Maintains the stats table. * @param {SsrcInfoManager} ssrcInfoManager The source of the ssrc info. */ var StatsTable = (function(ssrcInfoManager) { 'use strict'; /** * @param {SsrcInfoManager} ssrcInfoManager The source of the ssrc info. * @constructor */ function StatsTable(ssrcInfoManager) { /** * @type {SsrcInfoManager} * @private */ this.ssrcInfoManager_ = ssrcInfoManager; } StatsTable.prototype = { /** * Adds |report| to the stats table of |peerConnectionElement|. * * @param {!Element} peerConnectionElement The root element. * @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. */ addStatsReport: function(peerConnectionElement, report) { var statsTable = this.ensureStatsTable_(peerConnectionElement, report); if (report.stats) { this.addStatsToTable_(statsTable, report.stats.timestamp, report.stats.values); } }, /** * Ensure the DIV container for the stats tables is created as a child of * |peerConnectionElement|. * * @param {!Element} peerConnectionElement The root element. * @return {!Element} The stats table container. * @private */ ensureStatsTableContainer_: function(peerConnectionElement) { var containerId = peerConnectionElement.id + '-table-container'; var container = $(containerId); if (!container) { container = document.createElement('div'); container.id = containerId; container.className = 'stats-table-container'; var head = document.createElement('div'); head.textContent = 'Stats Tables'; container.appendChild(head); peerConnectionElement.appendChild(container); } return container; }, /** * Ensure the stats table for track specified by |report| of PeerConnection * |peerConnectionElement| is created. * * @param {!Element} peerConnectionElement The root element. * @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. * @return {!Element} The stats table element. * @private */ ensureStatsTable_: function(peerConnectionElement, report) { var tableId = peerConnectionElement.id + '-table-' + report.id; var table = $(tableId); if (!table) { var container = this.ensureStatsTableContainer_(peerConnectionElement); var details = document.createElement('details'); container.appendChild(details); var summary = document.createElement('summary'); summary.textContent = report.id; details.appendChild(summary); table = document.createElement('table'); details.appendChild(table); table.id = tableId; table.border = 1; table.innerHTML = '