| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 * Returns a string on the format ok-(JSON encoded session description). | 50 * Returns a string on the format ok-(JSON encoded session description). |
| 51 * | 51 * |
| 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-' + stringifyDOMObject_(localOffer)); | 60 returnToTest('ok-' + JSON.stringify(localOffer)); |
| 61 }, | 61 }, |
| 62 function(error) { failure_('createOffer', error); }, | 62 function(error) { failure_('createOffer', error); }, |
| 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 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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(error) { failure_('setRemoteDescription', error); }); | 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-' + stringifyDOMObject_(answer)); | 92 returnToTest('ok-' + JSON.stringify(answer)); |
| 93 }, | 93 }, |
| 94 function(error) { failure_('createAnswer', error); }, | 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. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 * | 171 * |
| 172 * Returns a JSON-encoded array of RTCIceCandidate instances to the test. | 172 * Returns a JSON-encoded array of RTCIceCandidate instances to the test. |
| 173 */ | 173 */ |
| 174 function getAllIceCandidates() { | 174 function getAllIceCandidates() { |
| 175 if (peerConnection_().iceGatheringState != 'complete') { | 175 if (peerConnection_().iceGatheringState != 'complete') { |
| 176 console.log('Still ICE gathering - waiting...'); | 176 console.log('Still ICE gathering - waiting...'); |
| 177 setTimeout(getAllIceCandidates, 100); | 177 setTimeout(getAllIceCandidates, 100); |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 | 180 |
| 181 returnToTest(stringifyDOMObject_(gIceCandidates)); | 181 returnToTest(JSON.stringify(gIceCandidates)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * Receives ICE candidates from the peer. | 185 * Receives ICE candidates from the peer. |
| 186 * | 186 * |
| 187 * Returns ok-received-candidates to the test on success. | 187 * Returns ok-received-candidates to the test on success. |
| 188 * | 188 * |
| 189 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances. | 189 * @param iceCandidatesJson a JSON-encoded array of RTCIceCandidate instances. |
| 190 */ | 190 */ |
| 191 function receiveIceCandidates(iceCandidatesJson) { | 191 function receiveIceCandidates(iceCandidatesJson) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 return gPeerConnection; | 254 return gPeerConnection; |
| 255 } | 255 } |
| 256 | 256 |
| 257 /** @private */ | 257 /** @private */ |
| 258 function success_(method) { | 258 function success_(method) { |
| 259 debug(method + '(): success.'); | 259 debug(method + '(): success.'); |
| 260 } | 260 } |
| 261 | 261 |
| 262 /** @private */ | 262 /** @private */ |
| 263 function failure_(method, error) { | 263 function failure_(method, error) { |
| 264 throw failTest(method + '() failed: ' + stringifyDOMObject_(error)); | 264 throw failTest(method + '() failed: ' + JSON.stringify(error)); |
| 265 } | 265 } |
| 266 | 266 |
| 267 /** @private */ | 267 /** @private */ |
| 268 function iceCallback_(event) { | 268 function iceCallback_(event) { |
| 269 if (event.candidate) | 269 if (event.candidate) |
| 270 gIceCandidates.push(event.candidate); | 270 gIceCandidates.push(event.candidate); |
| 271 } | 271 } |
| 272 | 272 |
| 273 /** @private */ | 273 /** @private */ |
| 274 function setLocalDescription(peerConnection, sessionDescription) { | 274 function setLocalDescription(peerConnection, sessionDescription) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 289 attachMediaStream(videoTag, event.stream); | 289 attachMediaStream(videoTag, event.stream); |
| 290 } | 290 } |
| 291 | 291 |
| 292 /** @private */ | 292 /** @private */ |
| 293 function removeStreamCallback_(event) { | 293 function removeStreamCallback_(event) { |
| 294 debug('Call ended.'); | 294 debug('Call ended.'); |
| 295 document.getElementById('remote-view').src = ''; | 295 document.getElementById('remote-view').src = ''; |
| 296 } | 296 } |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Stringifies a DOM object. | |
| 300 * | |
| 301 * This function stringifies not only own properties but also DOM attributes | |
| 302 * which are on a prototype chain. Note that JSON.stringify only stringifies | |
| 303 * own properties. | |
| 304 * @private | |
| 305 */ | |
| 306 function stringifyDOMObject_(object) | |
| 307 { | |
| 308 function deepCopy(src) { | |
| 309 if (typeof src != "object") | |
| 310 return src; | |
| 311 var dst = Array.isArray(src) ? [] : {}; | |
| 312 for (var property in src) { | |
| 313 dst[property] = deepCopy(src[property]); | |
| 314 } | |
| 315 return dst; | |
| 316 } | |
| 317 return JSON.stringify(deepCopy(object)); | |
| 318 } | |
| 319 | |
| 320 /** | |
| 321 * Parses JSON-encoded session descriptions and ICE candidates. | 299 * Parses JSON-encoded session descriptions and ICE candidates. |
| 322 * @private | 300 * @private |
| 323 */ | 301 */ |
| 324 function parseJson_(json) { | 302 function parseJson_(json) { |
| 325 // Escape since the \r\n in the SDP tend to get unescaped. | 303 // Escape since the \r\n in the SDP tend to get unescaped. |
| 326 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); | 304 jsonWithEscapedLineBreaks = json.replace(/\r\n/g, '\\r\\n'); |
| 327 try { | 305 try { |
| 328 return JSON.parse(jsonWithEscapedLineBreaks); | 306 return JSON.parse(jsonWithEscapedLineBreaks); |
| 329 } catch (exception) { | 307 } catch (exception) { |
| 330 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + | 308 failTest('Failed to parse JSON: ' + jsonWithEscapedLineBreaks + ', got ' + |
| 331 exception); | 309 exception); |
| 332 } | 310 } |
| 333 } | 311 } |
| OLD | NEW |