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 doGetUserMedia(constraints) { | 42 function getUserMedia(constraints) { |
43 if (!getUserMedia) { | 43 if (!navigator.webkitGetUserMedia) { |
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 doGetUserMedia: constraints: ' + constraints); | 53 debug('Requesting getUserMedia: constraints: ' + constraints); |
54 getUserMedia(evaluatedConstraints, getUserMediaOkCallback_, | 54 navigator.webkitGetUserMedia(evaluatedConstraints, |
55 getUserMediaFailedCallback_); | 55 getUserMediaOkCallback_, |
| 56 getUserMediaFailedCallback_); |
56 returnToTest('ok-requested'); | 57 returnToTest('ok-requested'); |
57 } | 58 } |
58 | 59 |
59 /** | 60 /** |
60 * Must be called after calling doGetUserMedia. | 61 * Must be called after calling getUserMedia. |
61 * @return {string} Returns not-called-yet if we have not yet been called back | 62 * @return {string} Returns not-called-yet if we have not yet been called back |
62 * by WebRTC. Otherwise it returns either ok-got-stream or | 63 * by WebRTC. Otherwise it returns either ok-got-stream or |
63 * failed-with-error-x (where x is the error code from the error | 64 * failed-with-error-x (where x is the error code from the error |
64 * callback) depending on which callback got called by WebRTC. | 65 * callback) depending on which callback got called by WebRTC. |
65 */ | 66 */ |
66 function obtainGetUserMediaResult() { | 67 function obtainGetUserMediaResult() { |
67 returnToTest(gRequestWebcamAndMicrophoneResult); | 68 returnToTest(gRequestWebcamAndMicrophoneResult); |
68 return gRequestWebcamAndMicrophoneResult; | 69 return gRequestWebcamAndMicrophoneResult; |
69 } | 70 } |
70 | 71 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 125 |
125 // Internals. | 126 // Internals. |
126 | 127 |
127 /** | 128 /** |
128 * @private | 129 * @private |
129 * @param {MediaStream} stream Media stream. | 130 * @param {MediaStream} stream Media stream. |
130 */ | 131 */ |
131 function getUserMediaOkCallback_(stream) { | 132 function getUserMediaOkCallback_(stream) { |
132 gLocalStream = stream; | 133 gLocalStream = stream; |
133 var videoTag = $('local-view'); | 134 var videoTag = $('local-view'); |
134 attachMediaStream(videoTag, stream); | 135 videoTag.src = webkitURL.createObjectURL(stream); |
135 | 136 |
136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 137 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
137 // videoTag.onloadedmetadata = displayVideoSize_(videoTag);. | 138 // videoTag.onloadedmetadata = displayVideoSize_(videoTag);. |
138 // Use setTimeout as a workaround for now. | 139 // Use setTimeout as a workaround for now. |
139 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
140 setTimeout(function() {displayVideoSize_(videoTag);}, 500); | 141 setTimeout(function() {displayVideoSize_(videoTag);}, 500); |
141 } | 142 } |
142 | 143 |
143 /** | 144 /** |
144 * @private | 145 * @private |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 */ | 197 */ |
197 function getUserMediaFailedCallback_(error) { | 198 function getUserMediaFailedCallback_(error) { |
198 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 199 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
199 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.name; | 200 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.name; |
200 debug(gRequestWebcamAndMicrophoneResult); | 201 debug(gRequestWebcamAndMicrophoneResult); |
201 } | 202 } |
202 | 203 |
203 $ = function(id) { | 204 $ = function(id) { |
204 return document.getElementById(id); | 205 return document.getElementById(id); |
205 }; | 206 }; |
OLD | NEW |