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.
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.
14 var PeerConnectionUpdateEntry = function(pid, lid, type, value) {
38 * Maintains the peer connection update log table.
40 var PeerConnectionUpdateTable = (function() {
46 function PeerConnectionUpdateTable() {
52 this.UPDATE_LOG_ID_SUFFIX_ = '-update-log';
59 this.UPDATE_LOG_CONTAINER_CLASS_ = 'update-log-container';
66 this.UPDATE_LOG_TABLE_CLASS = 'update-log-table';
69 PeerConnectionUpdateTable.prototype = {
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.
75 * @param {!Element} peerConnectionElement The root element.
76 * @param {!PeerConnectionUpdateEntry} update The update to add.
78 addPeerConnectionUpdate: function(peerConnectionElement, update) {
79 var tableElement = this.ensureUpdateContainer_(peerConnectionElement);
81 var row = document.createElement('tr');
82 tableElement.firstChild.appendChild(row);
84 var time = new Date(parseFloat(update.time));
85 row.innerHTML = '<td>' + time.toLocaleString() + '</td>';
87 if (update.value.length == 0) {
88 row.innerHTML += '<td>' + update.type + '</td>';
92 row.innerHTML += '<td><details><summary>' + update.type +
93 '</summary></details></td>';
95 var valueContainer = document.createElement('pre');
96 var details = row.cells[1].childNodes[0];
97 details.appendChild(valueContainer);
98 valueContainer.textContent = update.value;
102 * Makes sure the update log table of the peer connection is created.
104 * @param {!Element} peerConnectionElement The root element.
105 * @return {!Element} The log table element.
108 ensureUpdateContainer_: function(peerConnectionElement) {
109 var tableId = peerConnectionElement.id + this.UPDATE_LOG_ID_SUFFIX_;
110 var tableElement = $(tableId);
112 var tableContainer = document.createElement('div');
113 tableContainer.className = this.UPDATE_LOG_CONTAINER_CLASS_;
114 peerConnectionElement.appendChild(tableContainer);
116 tableElement = document.createElement('table');
117 tableElement.className = this.UPDATE_LOG_TABLE_CLASS;
118 tableElement.id = tableId;
119 tableElement.border = 1;
120 tableContainer.appendChild(tableElement);
121 tableElement.innerHTML = '<tr><th>Time</th>' +
122 '<th class="update-log-header-event">Event</th></tr>';
128 return PeerConnectionUpdateTable;