OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 var peerConnectionsListElem = null; |
| 6 |
5 function initialize() { | 7 function initialize() { |
| 8 peerConnectionsListElem = $('peer-connections-list'); |
| 9 } |
| 10 |
| 11 function getPeerConnectionId(data) { |
| 12 return data.pid + ':' + data.lid; |
| 13 } |
| 14 |
| 15 // Makes sure a LI element representing a PeerConnection is created |
| 16 // and appended to peerConnectionListElem. |
| 17 function ensurePeerConnectionElement(id) { |
| 18 var element = $(id); |
| 19 if (!element) { |
| 20 element = document.createElement('li'); |
| 21 peerConnectionsListElem.appendChild(element); |
| 22 element.id = id; |
| 23 } |
| 24 return element; |
| 25 } |
| 26 |
| 27 // |
| 28 // Browser message handlers |
| 29 // |
| 30 |
| 31 function removePeerConnection(data) { |
| 32 var element = $(getPeerConnectionId(data)); |
| 33 if (element) |
| 34 peerConnectionsListElem.removeChild(element); |
| 35 } |
| 36 |
| 37 function addPeerConnection(data) { |
| 38 var peerConnectionElement = ensurePeerConnectionElement( |
| 39 getPeerConnectionId(data)); |
| 40 peerConnectionElement.innerHTML = 'PeerConnection ' + |
| 41 peerConnectionElement.id + '<br>' + |
| 42 data.url + ', ' + |
| 43 data.servers + ', ' + |
| 44 data.constraints + '<br>'; |
6 } | 45 } |
7 | 46 |
8 document.addEventListener('DOMContentLoaded', initialize); | 47 document.addEventListener('DOMContentLoaded', initialize); |
OLD | NEW |