Home | History | Annotate | Download | only in media
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      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 /**
      7  * The data of a peer connection update.
      8  * @param {number} pid The id of the renderer.
      9  * @param {number} lid The id of the peer conneciton inside a renderer.
     10  * @param {string} type The type of the update.
     11  * @param {string} value The details of the update.
     12  * @constructor
     13  */
     14 var PeerConnectionUpdateEntry = function(pid, lid, type, value) {
     15   /**
     16    * @type {number}
     17    */
     18   this.pid = pid;
     19 
     20   /**
     21    * @type {number}
     22    */
     23   this.lid = lid;
     24 
     25   /**
     26    * @type {string}
     27    */
     28   this.type = type;
     29 
     30   /**
     31    * @type {string}
     32    */
     33   this.value = value;
     34 };
     35 
     36 
     37 /**
     38  * Maintains the peer connection update log table.
     39  */
     40 var PeerConnectionUpdateTable = (function() {
     41   'use strict';
     42 
     43   /**
     44    * @constructor
     45    */
     46   function PeerConnectionUpdateTable() {
     47     /**
     48      * @type {string}
     49      * @const
     50      * @private
     51      */
     52     this.UPDATE_LOG_ID_SUFFIX_ = '-update-log';
     53 
     54     /**
     55      * @type {string}
     56      * @const
     57      * @private
     58      */
     59     this.UPDATE_LOG_CONTAINER_CLASS_ = 'update-log-container';
     60 
     61     /**
     62      * @type {string}
     63      * @const
     64      * @private
     65      */
     66     this.UPDATE_LOG_TABLE_CLASS = 'update-log-table';
     67   }
     68 
     69   PeerConnectionUpdateTable.prototype = {
     70     /**
     71      * Adds the update to the update table as a new row. The type of the update
     72      * is set to the summary of the cell; clicking the cell will reveal or hide
     73      * the details as the content of a TextArea element.
     74      *
     75      * @param {!Element} peerConnectionElement The root element.
     76      * @param {!PeerConnectionUpdateEntry} update The update to add.
     77      */
     78     addPeerConnectionUpdate: function(peerConnectionElement, update) {
     79       var tableElement = this.ensureUpdateContainer_(peerConnectionElement);
     80 
     81       var row = document.createElement('tr');
     82       tableElement.firstChild.appendChild(row);
     83 
     84       row.innerHTML = '<td>' + (new Date()).toLocaleString() + '</td>';
     85 
     86       if (update.value.length == 0) {
     87         row.innerHTML += '<td>' + update.type + '</td>';
     88         return;
     89       }
     90 
     91       row.innerHTML += '<td><details><summary>' + update.type +
     92           '</summary></details></td>';
     93 
     94       var valueContainer = document.createElement('pre');
     95       var details = row.cells[1].childNodes[0];
     96       details.appendChild(valueContainer);
     97       valueContainer.textContent = update.value;
     98     },
     99 
    100     /**
    101      * Makes sure the update log table of the peer connection is created.
    102      *
    103      * @param {!Element} peerConnectionElement The root element.
    104      * @return {!Element} The log table element.
    105      * @private
    106      */
    107     ensureUpdateContainer_: function(peerConnectionElement) {
    108       var tableId = peerConnectionElement.id + this.UPDATE_LOG_ID_SUFFIX_;
    109       var tableElement = $(tableId);
    110       if (!tableElement) {
    111         var tableContainer = document.createElement('div');
    112         tableContainer.className = this.UPDATE_LOG_CONTAINER_CLASS_;
    113         peerConnectionElement.appendChild(tableContainer);
    114 
    115         tableElement = document.createElement('table');
    116         tableElement.className = this.UPDATE_LOG_TABLE_CLASS;
    117         tableElement.id = tableId;
    118         tableElement.border = 1;
    119         tableContainer.appendChild(tableElement);
    120         tableElement.innerHTML = '<tr><th>Time</th>' +
    121             '<th class="update-log-header-event">Event</th></tr>';
    122       }
    123       return tableElement;
    124     }
    125   };
    126 
    127   return PeerConnectionUpdateTable;
    128 })();
    129