OLD | NEW |
1 /** | 1 /** |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /** | 7 /** |
8 * We need a STUN server for some API calls. | |
9 * @private | |
10 */ | |
11 var STUN_SERVER = 'stun.l.google.com:19302'; | |
12 | |
13 /** | |
14 * The one and only peer connection in this page. | 8 * The one and only peer connection in this page. |
15 * @private | 9 * @private |
16 */ | 10 */ |
17 var gPeerConnection = null; | 11 var gPeerConnection = null; |
18 | 12 |
19 /** | 13 /** |
20 * This stores ICE candidates generated on this side. | 14 * This stores ICE candidates generated on this side. |
21 * @private | 15 * @private |
22 */ | 16 */ |
23 var gIceCandidates = []; | 17 var gIceCandidates = []; |
24 | 18 |
25 /** | 19 /** |
26 * Keeps track of whether we have seen crypto information in the SDP. | 20 * Keeps track of whether we have seen crypto information in the SDP. |
27 * @private | 21 * @private |
28 */ | 22 */ |
29 var gHasSeenCryptoInSdp = 'no-crypto-seen'; | 23 var gHasSeenCryptoInSdp = 'no-crypto-seen'; |
30 | 24 |
31 // Public interface to tests. These are expected to be called with | 25 // Public interface to tests. These are expected to be called with |
32 // ExecuteJavascript invocations from the browser tests and will return answers | 26 // ExecuteJavascript invocations from the browser tests and will return answers |
33 // through the DOM automation controller. | 27 // through the DOM automation controller. |
34 | 28 |
35 /** | 29 /** |
36 * Creates a peer connection. Must be called before most other public functions | 30 * Creates a peer connection. Must be called before most other public functions |
37 * in this file. | 31 * in this file. |
38 */ | 32 */ |
39 function preparePeerConnection() { | 33 function preparePeerConnection() { |
40 if (gPeerConnection != null) | 34 if (gPeerConnection != null) |
41 throw failTest('creating peer connection, but we already have one.'); | 35 throw failTest('creating peer connection, but we already have one.'); |
42 | 36 |
43 gPeerConnection = createPeerConnection_(STUN_SERVER); | 37 gPeerConnection = createPeerConnection_(); |
44 returnToTest('ok-peerconnection-created'); | 38 returnToTest('ok-peerconnection-created'); |
45 } | 39 } |
46 | 40 |
47 /** | 41 /** |
48 * Asks this page to create a local offer. | 42 * Asks this page to create a local offer. |
49 * | 43 * |
50 * Returns a string on the format ok-(JSON encoded session description). | 44 * Returns a string on the format ok-(JSON encoded session description). |
51 * | 45 * |
52 * @param {!Object} constraints Any createOffer constraints. | 46 * @param {!Object} constraints Any createOffer constraints. |
53 */ | 47 */ |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 /** | 221 /** |
228 * Returns | 222 * Returns |
229 */ | 223 */ |
230 function hasSeenCryptoInSdp() { | 224 function hasSeenCryptoInSdp() { |
231 returnToTest(gHasSeenCryptoInSdp); | 225 returnToTest(gHasSeenCryptoInSdp); |
232 } | 226 } |
233 | 227 |
234 // Internals. | 228 // Internals. |
235 | 229 |
236 /** @private */ | 230 /** @private */ |
237 function createPeerConnection_(stun_server) { | 231 function createPeerConnection_() { |
238 servers = {iceServers: [{url: 'stun:' + stun_server}]}; | |
239 try { | 232 try { |
240 peerConnection = new RTCPeerConnection(servers, {}); | 233 peerConnection = new RTCPeerConnection(null, {}); |
241 } catch (exception) { | 234 } catch (exception) { |
242 throw failTest('Failed to create peer connection: ' + exception); | 235 throw failTest('Failed to create peer connection: ' + exception); |
243 } | 236 } |
244 peerConnection.onaddstream = addStreamCallback_; | 237 peerConnection.onaddstream = addStreamCallback_; |
245 peerConnection.onremovestream = removeStreamCallback_; | 238 peerConnection.onremovestream = removeStreamCallback_; |
246 peerConnection.onicecandidate = iceCallback_; | 239 peerConnection.onicecandidate = iceCallback_; |
247 return peerConnection; | 240 return peerConnection; |
248 } | 241 } |
249 | 242 |
250 /** @private */ | 243 /** @private */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 function parseJson_(json) { | 295 function parseJson_(json) { |
303 // Escape since the \r\n in the SDP tend to get unescaped. | 296 // Escape since the \r\n in the SDP tend to get unescaped. |
304 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 297 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
305 try { | 298 try { |
306 return JSON.parse(jsonWithEscapedLineBreaks); | 299 return JSON.parse(jsonWithEscapedLineBreaks); |
307 } catch (exception) { | 300 } catch (exception) { |
308 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 301 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
309 exception); | 302 exception); |
310 } | 303 } |
311 } | 304 } |
OLD | NEW |