| OLD | NEW |
| 1 /** | 1 /** |
| 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 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 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more | 8 * See http://dev.w3.org/2011/webrtc/editor/getusermedia.html for more |
| 9 * information on getUserMedia. | 9 * information on getUserMedia. |
| 10 */ | 10 */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * This function asks permission to use the webcam and mic from the browser. It | 32 * This function asks permission to use the webcam and mic from the browser. It |
| 33 * will return ok-requested to PyAuto. This does not mean the request was | 33 * will return ok-requested to PyAuto. This does not mean the request was |
| 34 * approved though. The test will then have to click past the dialog that | 34 * approved though. The test will then have to click past the dialog that |
| 35 * appears in Chrome, which will run either the OK or failed callback as a | 35 * appears in Chrome, which will run either the OK or failed callback as a |
| 36 * a result. To see which callback was called, use obtainGetUserMediaResult(). | 36 * a result. To see which callback was called, use obtainGetUserMediaResult(). |
| 37 * | 37 * |
| 38 * @param {string} constraints Defines what to be requested, with mandatory | 38 * @param {string} constraints Defines what to be requested, with mandatory |
| 39 * and optional constraints defined. The contents of this parameter depends | 39 * and optional constraints defined. The contents of this parameter depends |
| 40 * on the WebRTC version. This should be JavaScript code that we eval(). | 40 * on the WebRTC version. This should be JavaScript code that we eval(). |
| 41 */ | 41 */ |
| 42 function getUserMedia(constraints) { | 42 function doGetUserMedia(constraints) { |
| 43 if (!navigator.webkitGetUserMedia) { | 43 if (!getUserMedia) { |
| 44 returnToTest('Browser does not support WebRTC.'); | 44 returnToTest('Browser does not support WebRTC.'); |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 try { | 47 try { |
| 48 var evaluatedConstraints; | 48 var evaluatedConstraints; |
| 49 eval('evaluatedConstraints = ' + constraints); | 49 eval('evaluatedConstraints = ' + constraints); |
| 50 } catch (exception) { | 50 } catch (exception) { |
| 51 throw failTest('Not valid JavaScript expression: ' + constraints); | 51 throw failTest('Not valid JavaScript expression: ' + constraints); |
| 52 } | 52 } |
| 53 debug('Requesting getUserMedia: constraints: ' + constraints); | 53 debug('Requesting doGetUserMedia: constraints: ' + constraints); |
| 54 navigator.webkitGetUserMedia(evaluatedConstraints, | 54 getUserMedia(evaluatedConstraints, getUserMediaOkCallback_, |
| 55 getUserMediaOkCallback_, | 55 getUserMediaFailedCallback_); |
| 56 getUserMediaFailedCallback_); | |
| 57 returnToTest('ok-requested'); | 56 returnToTest('ok-requested'); |
| 58 } | 57 } |
| 59 | 58 |
| 60 /** | 59 /** |
| 61 * Must be called after calling getUserMedia. | 60 * Must be called after calling doGetUserMedia. |
| 62 * @return {string} Returns not-called-yet if we have not yet been called back | 61 * @return {string} Returns not-called-yet if we have not yet been called back |
| 63 * by WebRTC. Otherwise it returns either ok-got-stream or | 62 * by WebRTC. Otherwise it returns either ok-got-stream or |
| 64 * failed-with-error-x (where x is the error code from the error | 63 * failed-with-error-x (where x is the error code from the error |
| 65 * callback) depending on which callback got called by WebRTC. | 64 * callback) depending on which callback got called by WebRTC. |
| 66 */ | 65 */ |
| 67 function obtainGetUserMediaResult() { | 66 function obtainGetUserMediaResult() { |
| 68 returnToTest(gRequestWebcamAndMicrophoneResult); | 67 returnToTest(gRequestWebcamAndMicrophoneResult); |
| 69 return gRequestWebcamAndMicrophoneResult; | 68 return gRequestWebcamAndMicrophoneResult; |
| 70 } | 69 } |
| 71 | 70 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 124 |
| 126 // Internals. | 125 // Internals. |
| 127 | 126 |
| 128 /** | 127 /** |
| 129 * @private | 128 * @private |
| 130 * @param {MediaStream} stream Media stream. | 129 * @param {MediaStream} stream Media stream. |
| 131 */ | 130 */ |
| 132 function getUserMediaOkCallback_(stream) { | 131 function getUserMediaOkCallback_(stream) { |
| 133 gLocalStream = stream; | 132 gLocalStream = stream; |
| 134 var videoTag = $('local-view'); | 133 var videoTag = $('local-view'); |
| 135 videoTag.src = webkitURL.createObjectURL(stream); | 134 attachMediaStream(videoTag, stream); |
| 136 | 135 |
| 137 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
| 138 // videoTag.onloadedmetadata = displayVideoSize_(videoTag);. | 137 // videoTag.onloadedmetadata = displayVideoSize_(videoTag);. |
| 139 // Use setTimeout as a workaround for now. | 138 // Use setTimeout as a workaround for now. |
| 140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 139 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
| 141 setTimeout(function() {displayVideoSize_(videoTag);}, 500); | 140 setTimeout(function() {displayVideoSize_(videoTag);}, 500); |
| 142 } | 141 } |
| 143 | 142 |
| 144 /** | 143 /** |
| 145 * @private | 144 * @private |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 */ | 196 */ |
| 198 function getUserMediaFailedCallback_(error) { | 197 function getUserMediaFailedCallback_(error) { |
| 199 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 198 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
| 200 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.name; | 199 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.name; |
| 201 debug(gRequestWebcamAndMicrophoneResult); | 200 debug(gRequestWebcamAndMicrophoneResult); |
| 202 } | 201 } |
| 203 | 202 |
| 204 $ = function(id) { | 203 $ = function(id) { |
| 205 return document.getElementById(id); | 204 return document.getElementById(id); |
| 206 }; | 205 }; |
| OLD | NEW |