Chromium Code Reviews| 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. | 8 * We need a STUN server for some API calls. |
| 9 * @private | 9 * @private |
| 10 */ | 10 */ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 * @param {!Object} constraints Any createOffer constraints. | 52 * @param {!Object} constraints Any createOffer constraints. |
| 53 */ | 53 */ |
| 54 function createLocalOffer(constraints) { | 54 function createLocalOffer(constraints) { |
| 55 peerConnection_().createOffer( | 55 peerConnection_().createOffer( |
| 56 function(localOffer) { | 56 function(localOffer) { |
| 57 success_('createOffer'); | 57 success_('createOffer'); |
| 58 setLocalDescription(peerConnection, localOffer); | 58 setLocalDescription(peerConnection, localOffer); |
| 59 | 59 |
| 60 returnToTest('ok-' + JSON.stringify(localOffer)); | 60 returnToTest('ok-' + JSON.stringify(localOffer)); |
| 61 }, | 61 }, |
| 62 function() { failure_('createOffer'); }, | 62 function() { failure_('createOffer'); }, |
|
kjellander_chromium
2014/06/09 19:42:56
Please fix this one too.
According to the spec, it
jansson
2014/06/10 05:50:27
Done.
| |
| 63 constraints); | 63 constraints); |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * Asks this page to accept an offer and generate an answer. | 67 * Asks this page to accept an offer and generate an answer. |
| 68 * | 68 * |
| 69 * Returns a string on the format ok-(JSON encoded session description). | 69 * Returns a string on the format ok-(JSON encoded session description). |
| 70 * | 70 * |
| 71 * @param {!string} sessionDescJson A JSON-encoded session description of type | 71 * @param {!string} sessionDescJson A JSON-encoded session description of type |
| 72 * 'offer'. | 72 * 'offer'. |
| 73 * @param {!Object} constraints Any createAnswer constraints. | 73 * @param {!Object} constraints Any createAnswer constraints. |
| 74 */ | 74 */ |
| 75 function receiveOfferFromPeer(sessionDescJson, constraints) { | 75 function receiveOfferFromPeer(sessionDescJson, constraints) { |
| 76 offer = parseJson_(sessionDescJson); | 76 offer = parseJson_(sessionDescJson); |
| 77 if (!offer.type) | 77 if (!offer.type) |
| 78 failTest('Got invalid session description from peer: ' + sessionDescJson); | 78 failTest('Got invalid session description from peer: ' + sessionDescJson); |
| 79 if (offer.type != 'offer') | 79 if (offer.type != 'offer') |
| 80 failTest('Expected to receive offer from peer, got ' + offer.type); | 80 failTest('Expected to receive offer from peer, got ' + offer.type); |
| 81 | 81 |
| 82 var sessionDescription = new RTCSessionDescription(offer); | 82 var sessionDescription = new RTCSessionDescription(offer); |
| 83 peerConnection_().setRemoteDescription( | 83 peerConnection_().setRemoteDescription( |
| 84 sessionDescription, | 84 sessionDescription, |
| 85 function() { success_('setRemoteDescription'); }, | 85 function() { success_('setRemoteDescription'); }, |
| 86 function() { failure_('setRemoteDescription'); }); | 86 function(error) { failure_('setRemoteDescription', error); }); |
| 87 | 87 |
| 88 peerConnection_().createAnswer( | 88 peerConnection_().createAnswer( |
| 89 function(answer) { | 89 function(answer) { |
| 90 success_('createAnswer'); | 90 success_('createAnswer'); |
| 91 setLocalDescription(peerConnection, answer); | 91 setLocalDescription(peerConnection, answer); |
| 92 returnToTest('ok-' + JSON.stringify(answer)); | 92 returnToTest('ok-' + JSON.stringify(answer)); |
| 93 }, | 93 }, |
| 94 function() { failure_('createAnswer'); }, | 94 function(error) { failure_('createAnswer', error); }, |
| 95 constraints); | 95 constraints); |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Asks this page to accept an answer generated by the peer in response to a | 99 * Asks this page to accept an answer generated by the peer in response to a |
| 100 * previous offer by this page | 100 * previous offer by this page |
| 101 * | 101 * |
| 102 * Returns a string ok-accepted-answer on success. | 102 * Returns a string ok-accepted-answer on success. |
| 103 * | 103 * |
| 104 * @param {!string} sessionDescJson A JSON-encoded session description of type | 104 * @param {!string} sessionDescJson A JSON-encoded session description of type |
| 105 * 'answer'. | 105 * 'answer'. |
| 106 */ | 106 */ |
| 107 function receiveAnswerFromPeer(sessionDescJson) { | 107 function receiveAnswerFromPeer(sessionDescJson) { |
| 108 answer = parseJson_(sessionDescJson); | 108 answer = parseJson_(sessionDescJson); |
| 109 if (!answer.type) | 109 if (!answer.type) |
| 110 failTest('Got invalid session description from peer: ' + sessionDescJson); | 110 failTest('Got invalid session description from peer: ' + sessionDescJson); |
| 111 if (answer.type != 'answer') | 111 if (answer.type != 'answer') |
| 112 failTest('Expected to receive answer from peer, got ' + answer.type); | 112 failTest('Expected to receive answer from peer, got ' + answer.type); |
| 113 | 113 |
| 114 var sessionDescription = new RTCSessionDescription(answer); | 114 var sessionDescription = new RTCSessionDescription(answer); |
| 115 peerConnection_().setRemoteDescription( | 115 peerConnection_().setRemoteDescription( |
| 116 sessionDescription, | 116 sessionDescription, |
| 117 function() { | 117 function() { |
| 118 success_('setRemoteDescription'); | 118 success_('setRemoteDescription'); |
| 119 returnToTest('ok-accepted-answer'); | 119 returnToTest('ok-accepted-answer'); |
| 120 }, | 120 }, |
| 121 function() { failure_('setRemoteDescription'); }); | 121 function(error) { failure_('setRemoteDescription', error); }); |
| 122 } | 122 } |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Adds the local stream to the peer connection. You will have to re-negotiate | 125 * Adds the local stream to the peer connection. You will have to re-negotiate |
| 126 * the call for this to take effect in the call. | 126 * the call for this to take effect in the call. |
| 127 */ | 127 */ |
| 128 function addLocalStream() { | 128 function addLocalStream() { |
| 129 addLocalStreamToPeerConnection(peerConnection_()); | 129 addLocalStreamToPeerConnection(peerConnection_()); |
| 130 returnToTest('ok-added'); | 130 returnToTest('ok-added'); |
| 131 } | 131 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 var iceCandidates = parseJson_(iceCandidatesJson); | 210 var iceCandidates = parseJson_(iceCandidatesJson); |
| 211 if (!iceCandidates.length) | 211 if (!iceCandidates.length) |
| 212 throw failTest('Received invalid ICE candidate list from peer: ' + | 212 throw failTest('Received invalid ICE candidate list from peer: ' + |
| 213 iceCandidatesJson); | 213 iceCandidatesJson); |
| 214 | 214 |
| 215 iceCandidates.forEach(function(iceCandidate) { | 215 iceCandidates.forEach(function(iceCandidate) { |
| 216 if (!iceCandidate.candidate) | 216 if (!iceCandidate.candidate) |
| 217 failTest('Received invalid ICE candidate from peer: ' + | 217 failTest('Received invalid ICE candidate from peer: ' + |
| 218 iceCandidatesJson); | 218 iceCandidatesJson); |
| 219 | 219 |
| 220 peerConnection_().addIceCandidate(new RTCIceCandidate(iceCandidate)); | 220 peerConnection_().addIceCandidate(new RTCIceCandidate(iceCandidate)); |
|
kjellander_chromium
2014/06/09 19:42:56
This also takes success and failure callback funct
jansson
2014/06/10 05:50:27
Done.
kjellander_chromium
2014/06/10 08:55:33
Have you verified the success callback is actually
| |
| 221 }); | 221 }); |
| 222 | 222 |
| 223 returnToTest('ok-received-candidates'); | 223 returnToTest('ok-received-candidates'); |
| 224 } | 224 } |
| 225 | 225 |
| 226 /** | 226 /** |
| 227 * Returns | 227 * Returns |
| 228 */ | 228 */ |
| 229 function hasSeenCryptoInSdp() { | 229 function hasSeenCryptoInSdp() { |
| 230 returnToTest(gHasSeenCryptoInSdp); | 230 returnToTest(gHasSeenCryptoInSdp); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 253 return gPeerConnection; | 253 return gPeerConnection; |
| 254 } | 254 } |
| 255 | 255 |
| 256 /** @private */ | 256 /** @private */ |
| 257 function success_(method) { | 257 function success_(method) { |
| 258 debug(method + '(): success.'); | 258 debug(method + '(): success.'); |
| 259 } | 259 } |
| 260 | 260 |
| 261 /** @private */ | 261 /** @private */ |
| 262 function failure_(method, error) { | 262 function failure_(method, error) { |
| 263 throw failTest(method + '() failed: ' + error); | 263 throw failTest(method + '() failed: ' + JSON.stringify(error); |
| 264 } | 264 } |
| 265 | 265 |
| 266 /** @private */ | 266 /** @private */ |
| 267 function iceCallback_(event) { | 267 function iceCallback_(event) { |
| 268 if (event.candidate) | 268 if (event.candidate) |
| 269 gIceCandidates.push(event.candidate); | 269 gIceCandidates.push(event.candidate); |
| 270 } | 270 } |
| 271 | 271 |
| 272 /** @private */ | 272 /** @private */ |
| 273 function setLocalDescription(peerConnection, sessionDescription) { | 273 function setLocalDescription(peerConnection, sessionDescription) { |
| 274 if (sessionDescription.sdp.search('a=crypto') != -1 || | 274 if (sessionDescription.sdp.search('a=crypto') != -1 || |
| 275 sessionDescription.sdp.search('a=fingerprint') != -1) | 275 sessionDescription.sdp.search('a=fingerprint') != -1) |
| 276 gHasSeenCryptoInSdp = 'crypto-seen'; | 276 gHasSeenCryptoInSdp = 'crypto-seen'; |
| 277 | 277 |
| 278 peerConnection.setLocalDescription( | 278 peerConnection.setLocalDescription( |
| 279 sessionDescription, | 279 sessionDescription, |
| 280 function() { success_('setLocalDescription'); }, | 280 function() { success_('setLocalDescription'); }, |
| 281 function() { failure_('setLocalDescription'); }); | 281 function(error) { failure_('setLocalDescription', error); }); |
| 282 } | 282 } |
| 283 | 283 |
| 284 /** @private */ | 284 /** @private */ |
| 285 function addStreamCallback_(event) { | 285 function addStreamCallback_(event) { |
| 286 debug('Receiving remote stream...'); | 286 debug('Receiving remote stream...'); |
| 287 var videoTag = document.getElementById('remote-view'); | 287 var videoTag = document.getElementById('remote-view'); |
| 288 attachMediaStream(videoTag, event.stream); | 288 attachMediaStream(videoTag, event.stream); |
| 289 } | 289 } |
| 290 | 290 |
| 291 /** @private */ | 291 /** @private */ |
| 292 function removeStreamCallback_(event) { | 292 function removeStreamCallback_(event) { |
| 293 debug('Call ended.'); | 293 debug('Call ended.'); |
| 294 document.getElementById('remote-view').src = ''; | 294 document.getElementById('remote-view').src = ''; |
| 295 } | 295 } |
| 296 | 296 |
| 297 /** | 297 /** |
| 298 * Parses JSON-encoded session descriptions and ICE candidates. | 298 * Parses JSON-encoded session descriptions and ICE candidates. |
| 299 * @private | 299 * @private |
| 300 */ | 300 */ |
| 301 function parseJson_(json) { | 301 function parseJson_(json) { |
| 302 // Escape since the \r\n in the SDP tend to get unescaped. | 302 // Escape since the \r\n in the SDP tend to get unescaped. |
| 303 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 303 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
| 304 try { | 304 try { |
| 305 return JSON.parse(jsonWithEscapedLineBreaks); | 305 return JSON.parse(jsonWithEscapedLineBreaks); |
| 306 } catch (exception) { | 306 } catch (exception) { |
| 307 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 307 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
| 308 exception); | 308 exception); |
| 309 } | 309 } |
| 310 } | 310 } |
| OLD | NEW |