| 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 * The one and only peer connection in this page. | 8 * The one and only peer connection in this page. |
| 9 * @private | 9 * @private |
| 10 */ | 10 */ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * 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 |
| 31 * in this file. | 31 * in this file. |
| 32 * @param {Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as | 32 * @param {Object} keygenAlgorithm An |AlgorithmIdentifier| to be used as |
| 33 * parameter to |RTCPeerConnection.generateCertificate|. The resulting | 33 * parameter to |RTCPeerConnection.generateCertificate|. The resulting |
| 34 * certificate will be used by the peer connection. | 34 * certificate will be used by the peer connection. |
| 35 */ | 35 */ |
| 36 function preparePeerConnection(keygenAlgorithm = null) { | 36 function preparePeerConnection(keygenAlgorithm = null) { |
| 37 if (gPeerConnection !== null) | 37 if (gPeerConnection !== null) |
| 38 throw failTest('creating peer connection, but we already have one.'); | 38 throw failTest('Creating peer connection, but we already have one.'); |
| 39 | 39 |
| 40 if (keygenAlgorithm === null) { | 40 if (keygenAlgorithm === null) { |
| 41 gPeerConnection = createPeerConnection_(null); | 41 gPeerConnection = createPeerConnection_(null); |
| 42 returnToTest('ok-peerconnection-created'); | 42 returnToTest('ok-peerconnection-created'); |
| 43 } else { | 43 } else { |
| 44 webkitRTCPeerConnection.generateCertificate(keygenAlgorithm).then( | 44 RTCPeerConnection.generateCertificate(keygenAlgorithm).then( |
| 45 function(certificate) { | 45 function(certificate) { |
| 46 if (gPeerConnection !== null) { | 46 preparePeerConnectionWithCertificate(certificate); |
| 47 throw failTest('peer connection already set during certificate ' + | |
| 48 + 'generation.'); | |
| 49 } | |
| 50 gPeerConnection = createPeerConnection_( | |
| 51 {iceServers:[], certificates:[certificate]}); | |
| 52 returnToTest('ok-peerconnection-created'); | |
| 53 }, | 47 }, |
| 54 function() { | 48 function() { |
| 55 failTest('Certificate generation failed. keygenAlgorithm: ' + | 49 failTest('Certificate generation failed. keygenAlgorithm: ' + |
| 56 JSON.stringify(keygenAlgorithm)); | 50 JSON.stringify(keygenAlgorithm)); |
| 57 }); | 51 }); |
| 58 } | 52 } |
| 59 } | 53 } |
| 60 | 54 |
| 55 function preparePeerConnectionWithCertificate(certificate) { |
| 56 if (gPeerConnection !== null) |
| 57 throw failTest('Creating peer connection, but we already have one.'); |
| 58 gPeerConnection = createPeerConnection_( |
| 59 {iceServers:[], certificates:[certificate]}); |
| 60 returnToTest('ok-peerconnection-created'); |
| 61 } |
| 62 |
| 61 /** | 63 /** |
| 62 * Asks this page to create a local offer. | 64 * Asks this page to create a local offer. |
| 63 * | 65 * |
| 64 * Returns a string on the format ok-(JSON encoded session description). | 66 * Returns a string on the format ok-(JSON encoded session description). |
| 65 * | 67 * |
| 66 * @param {!Object} constraints Any createOffer constraints. | 68 * @param {!Object} constraints Any createOffer constraints. |
| 67 * @param {string} videoCodec If not null, promotes the specified codec to be | 69 * @param {string} videoCodec If not null, promotes the specified codec to be |
| 68 * the default video codec, e.g. the first one in the list on the 'm=video' | 70 * the default video codec, e.g. the first one in the list on the 'm=video' |
| 69 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g. | 71 * SDP offer line. |videoCodec| is the case-sensitive codec name, e.g. |
| 70 * 'VP8' or 'H264'. | 72 * 'VP8' or 'H264'. |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 function parseJson_(json) { | 342 function parseJson_(json) { |
| 341 // Escape since the \r\n in the SDP tend to get unescaped. | 343 // Escape since the \r\n in the SDP tend to get unescaped. |
| 342 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 344 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
| 343 try { | 345 try { |
| 344 return JSON.parse(jsonWithEscapedLineBreaks); | 346 return JSON.parse(jsonWithEscapedLineBreaks); |
| 345 } catch (exception) { | 347 } catch (exception) { |
| 346 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 348 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
| 347 exception); | 349 exception); |
| 348 } | 350 } |
| 349 } | 351 } |
| OLD | NEW |