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 * Used as a shortcut. Moved to the top of the page due to race conditions. | 32 * Used as a shortcut. Moved to the top of the page due to race conditions. |
33 * @param {string} id is a case-sensitive string representing the unique ID of | 33 * @param {string} id is a case-sensitive string representing the unique ID of |
34 * the element being sought. | 34 * the element being sought. |
35 * @return {string} id returns the element object specified as a parameter | 35 * @return {string} id returns the element object specified as a parameter |
36 */ | 36 */ |
37 $ = function(id) { | 37 $ = function(id) { |
38 return document.getElementById(id); | 38 return document.getElementById(id); |
39 }; | 39 }; |
40 | 40 |
41 /** | 41 /** |
42 * This function asks permission to use the webcam and mic from the browser. | 42 * This function asks permission to use the webcam and mic from the browser. It |
43 * Its callbacks will return either request-callback-granted or | 43 * will return ok-requested to the test. This does not mean the request was |
44 * request-callback-denied depending on the outcome. If the caller does not | 44 * approved though. The test will then have to click past the dialog that |
45 * successfully resolve the request by granting or denying, the test will hang. | 45 * appears in Chrome, which will run either the OK or failed callback as a |
46 * To verify which callback was called, use obtainGetUserMediaResult(). | 46 * a result. To see which callback was called, use obtainGetUserMediaResult(). |
47 * | 47 * |
48 * @param {!object} constraints Defines what to be requested, with mandatory | 48 * @param {!object} constraints Defines what to be requested, with mandatory |
49 * and optional constraints defined. The contents of this parameter depends | 49 * and optional constraints defined. The contents of this parameter depends |
50 * on the WebRTC version. | 50 * on the WebRTC version. |
51 */ | 51 */ |
52 function doGetUserMedia(constraints) { | 52 function doGetUserMedia(constraints) { |
53 if (!getUserMedia) { | 53 if (!getUserMedia) { |
54 returnToTest('Browser does not support WebRTC.'); | 54 returnToTest('Browser does not support WebRTC.'); |
55 return; | 55 return; |
56 } | 56 } |
57 debug('Requesting doGetUserMedia: constraints: ' + | 57 debug('Requesting doGetUserMedia: constraints: ' + |
58 JSON.stringify(constraints, null, 0).replace(/[\r\n]/g, '')); | 58 JSON.stringify(constraints, null, 0).replace(/[\r\n]/g, '')); |
59 getUserMedia(constraints, | 59 getUserMedia(constraints, |
60 function(stream) { | 60 function(stream) { |
61 ensureGotAllExpectedStreams_(stream, constraints); | 61 ensureGotAllExpectedStreams_(stream, constraints); |
62 getUserMediaOkCallback_(stream); | 62 getUserMediaOkCallback_(stream); |
63 }, | 63 }, |
64 getUserMediaFailedCallback_); | 64 getUserMediaFailedCallback_); |
| 65 returnToTest('ok-requested'); |
65 } | 66 } |
66 | 67 |
67 /** | 68 /** |
68 * Must be called after calling doGetUserMedia. | 69 * Must be called after calling doGetUserMedia. |
69 * @return {string} Returns not-called-yet if we have not yet been called back | 70 * @return {string} Returns not-called-yet if we have not yet been called back |
70 * by WebRTC. Otherwise it returns either ok-got-stream or | 71 * by WebRTC. Otherwise it returns either ok-got-stream or |
71 * failed-with-error-x (where x is the error code from the error | 72 * failed-with-error-x (where x is the error code from the error |
72 * callback) depending on which callback got called by WebRTC. | 73 * callback) depending on which callback got called by WebRTC. |
73 */ | 74 */ |
74 function obtainGetUserMediaResult() { | 75 function obtainGetUserMediaResult() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 /** | 150 /** |
150 * @private | 151 * @private |
151 * @param {MediaStream} stream Media stream. | 152 * @param {MediaStream} stream Media stream. |
152 */ | 153 */ |
153 function getUserMediaOkCallback_(stream) { | 154 function getUserMediaOkCallback_(stream) { |
154 gLocalStream = stream; | 155 gLocalStream = stream; |
155 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 156 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
156 | 157 |
157 attachMediaStream($('local-view'), stream); | 158 attachMediaStream($('local-view'), stream); |
158 | |
159 returnToTest('request-callback-granted'); | |
160 } | 159 } |
161 | 160 |
162 /** | 161 /** |
163 * @private | 162 * @private |
164 * @param {NavigatorUserMediaError} error Error containing details. | 163 * @param {NavigatorUserMediaError} error Error containing details. |
165 */ | 164 */ |
166 function getUserMediaFailedCallback_(error) { | 165 function getUserMediaFailedCallback_(error) { |
167 // Translate from the old error to the new. Remove when rename fully deployed. | 166 // Translate from the old error to the new. Remove when rename fully deployed. |
168 var errorName = error.name; | 167 var errorName = error.name; |
169 | 168 |
170 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 169 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
171 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName; | 170 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName; |
172 debug(gRequestWebcamAndMicrophoneResult); | 171 debug(gRequestWebcamAndMicrophoneResult); |
173 | |
174 returnToTest('request-callback-denied'); | |
175 } | 172 } |
OLD | NEW |