// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+var USER_MEDIA_TAB_ID = 'user-media-tab-id';
+
var tabView = null;
var ssrcInfoManager = null;
var peerConnectionUpdateTable = null;
/** @private */
this.record_ = {
constraints: {},
- servers: [],
+ rtcConfiguration: [],
stats: {},
updateLog: [],
url: '',
/**
* Adds the initilization info of the peer connection.
* @param {string} url The URL of the web page owning the peer connection.
- * @param {Array} servers STUN servers used by the peer connection.
+ * @param {Array} rtcConfiguration
* @param {!Object} constraints Media constraints.
*/
- initialize: function(url, servers, constraints) {
+ initialize: function(url, rtcConfiguration, constraints) {
this.record_.url = url;
- this.record_.servers = servers;
+ this.record_.rtcConfiguration = rtcConfiguration;
this.record_.constraints = constraints;
},
},
/**
- * @param {string} type The type of the update.
- * @param {string} value The value of the update.
+ * @param {!Object} update The object contains keys "time", "type", and
+ * "value".
*/
- addUpdate: function(type, value) {
+ addUpdate: function(update) {
+ var time = new Date(parseFloat(update.time));
this.record_.updateLog.push({
- time: (new Date()).toLocaleString(),
- type: type,
- value: value,
+ time: time.toLocaleString(),
+ type: update.type,
+ value: update.value,
});
},
};
/**
+ * A helper function for appending a child element to |parent|.
+ *
+ * @param {!Element} parent The parent element.
+ * @param {string} tag The child element tag.
+ * @param {string} text The textContent of the new DIV.
+ * @return {!Element} the new DIV element.
+ */
+function appendChildWithText(parent, tag, text) {
+ var child = document.createElement(tag);
+ child.textContent = text;
+ parent.appendChild(child);
+ return child;
+}
+
+/**
* Helper for adding a peer connection update.
*
* @param {Element} peerConnectionElement
peerConnectionUpdateTable.addPeerConnectionUpdate(peerConnectionElement,
update);
extractSsrcInfo(update);
- peerConnectionDataStore[peerConnectionElement.id].addUpdate(
- update.type, update.value);
+ peerConnectionDataStore[peerConnectionElement.id].addUpdate(update);
}
/**
* Adds a peer connection.
*
- * @param {!Object} data The object containing the pid, lid, url, servers, and
- * constraints of a peer connection.
+ * @param {!Object} data The object containing the pid, lid, url,
+ * rtcConfiguration, and constraints of a peer connection.
*/
function addPeerConnection(data) {
var id = getPeerConnectionId(data);
peerConnectionDataStore[id] = new PeerConnectionRecord();
}
peerConnectionDataStore[id].initialize(
- data.url, data.servers, data.constraints);
+ data.url, data.rtcConfiguration, data.constraints);
var peerConnectionElement = $(id);
if (!peerConnectionElement) {
- peerConnectionElement = tabView.addTab(id, data.url);
+ peerConnectionElement = tabView.addTab(id, data.url + ' [' + id + ']');
}
peerConnectionElement.innerHTML =
- '<p>' + data.url + ' ' + data.servers + ' ' + data.constraints +
+ '<p>' + data.url + ' ' + data.rtcConfiguration + ' ' + data.constraints +
'</p>';
return peerConnectionElement;
* Adds the information of all peer connections created so far.
*
* @param {Array.<!Object>} data An array of the information of all peer
- * connections. Each array item contains pid, lid, url, servers,
+ * connections. Each array item contains pid, lid, url, rtcConfiguration,
* constraints, and an array of updates as the log.
*/
function updateAllPeerConnections(data) {
* origin {string}, audio {string}, video {string}.
*/
function addGetUserMedia(data) {
- // TODO(jiayl): add the getUserMedia info to the tabbed UI.
userMediaRequests.push(data);
+
+ if (!$(USER_MEDIA_TAB_ID)) {
+ tabView.addTab(USER_MEDIA_TAB_ID, 'GetUserMedia Requests');
+ }
+
+ var requestDiv = document.createElement('div');
+ requestDiv.className = 'user-media-request-div-class';
+ requestDiv.rid = data.rid;
+ $(USER_MEDIA_TAB_ID).appendChild(requestDiv);
+
+ appendChildWithText(requestDiv, 'div', 'Caller origin: ' + data.origin);
+ appendChildWithText(requestDiv, 'div', 'Caller process id: ' + data.pid);
+ appendChildWithText(requestDiv, 'span', 'Audio Constraints').style.fontWeight
+ = 'bold';
+ appendChildWithText(requestDiv, 'div', data.audio);
+
+ appendChildWithText(requestDiv, 'span', 'Video Constraints').style.fontWeight
+ = 'bold';
+ appendChildWithText(requestDiv, 'div', data.video);
}
* @param {!Object} data The object containing rid {number}, the render id.
*/
function removeGetUserMediaForRenderer(data) {
- // TODO(jiayl): remove the getUserMedia info from the tabbed UI.
for (var i = userMediaRequests.length - 1; i >= 0; --i) {
if (userMediaRequests[i].rid == data.rid)
userMediaRequests.splice(i, 1);
}
+
+ var requests = $(USER_MEDIA_TAB_ID).childNodes;
+ for (var i = 0; i < requests.length; ++i) {
+ if (requests[i].rid == data.rid)
+ $(USER_MEDIA_TAB_ID).removeChild(requests[i]);
+
+ }
+ if ($(USER_MEDIA_TAB_ID).childNodes.length == 0)
+ tabView.removeTab(USER_MEDIA_TAB_ID);
}