Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: getusermedia.js

Issue 12824011: Updated Chrome Test pages (Closed) Base URL: https://src.chromium.org/svn/trunk/src/chrome/test/data/webrtc/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | jsep01_call.js » ('j') | manual/constraints.html » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 /** 31 /**
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 */
phoglund_chromium 2013/03/22 15:07:18 This gets called from the browser tests and PyAuto
elham1 2013/03/25 21:58:23 Okay, I will upload a seperate cl for that. On 201
kjellander_chromium 2013/03/26 06:46:10 I think it's better to include these changes in th
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,
phoglund_chromium 2013/03/22 15:07:18 Nit: indentation
elham1 2013/03/25 21:58:23 Done.
55 getUserMediaOkCallback_, 55 getUserMediaOkCallback_,
56 getUserMediaFailedCallback_); 56 getUserMediaFailedCallback_);
57 returnToTest('ok-requested'); 57 returnToTest('ok-requested');
58 } 58 }
59 59
60 /** 60 /**
61 * Must be called after calling getUserMedia. Returns not-called-yet if we have 61 * Must be called after calling doGetUserMedia. Returns not-called-yet if we
phoglund_chromium 2013/03/22 15:07:18 Nit: lines should not end with whitespace. Configu
elham1 2013/03/25 21:58:23 Done.
62 * not yet been called back by WebRTC. Otherwise it returns either ok-got-stream 62 * have not yet been called back by WebRTC. Otherwise it returns either
63 * or failed-with-error-x (where x is the error code from the error callback) 63 * ok-got-stream or failed-with-error-x (where x is the error code from the
64 * depending on which callback got called by WebRTC. 64 * error callback) depending on which callback got called by WebRTC.
65 */ 65 */
66 function obtainGetUserMediaResult() { 66 function obtainGetUserMediaResult() {
67 returnToTest(gRequestWebcamAndMicrophoneResult); 67 returnToTest(gRequestWebcamAndMicrophoneResult);
68 return gRequestWebcamAndMicrophoneResult; 68 return gRequestWebcamAndMicrophoneResult;
69 } 69 }
70 70
71 /** 71 /**
72 * Stops the local stream. 72 * Stops the local stream.
73 */ 73 */
74 function stopLocalStream() { 74 function stopLocalStream() {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 // Internals. 125 // Internals.
126 126
127 /** 127 /**
128 * @private 128 * @private
129 * @param {MediaStream} stream Media stream. 129 * @param {MediaStream} stream Media stream.
130 */ 130 */
131 function getUserMediaOkCallback_(stream) { 131 function getUserMediaOkCallback_(stream) {
132 gLocalStream = stream; 132 gLocalStream = stream;
133 var videoTag = $('local-view'); 133 var videoTag = $('local-view');
134 videoTag.src = webkitURL.createObjectURL(stream); 134 attachMediaStream(videoTag, stream);
135
136 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. 135 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires.
137 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view'); 136 // videoTag.onloadedmetadata = updateVideoTagSize_('local-view');
138 // Use setTimeout as a workaround for now. 137 // Use setTimeout as a workaround for now.
139 setTimeout(function() {updateVideoTagSize_('local-view')}, 500); 138 setTimeout(function() {updateVideoTagSize_('local-view')}, 500);
140 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; 139 gRequestWebcamAndMicrophoneResult = 'ok-got-stream';
141 } 140 }
142 141
143 /** 142 /**
144 * @private 143 * @private
145 * @param {string} videoTagId The ID of the video tag to update. 144 * @param {string} videoTagId The ID of the video tag to update.
146 */ 145 */
147 function updateVideoTagSize_(videoTagId) { 146 function updateVideoTagSize_(videoTagId) {
148 var videoTag = $(videoTagId); 147 var videoTag = $(videoTagId);
149 // Don't update if sizes are 0 (happens for Chrome M23). 148 // Don't update if sizes are 0 (happens for Chrome M23).
150 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) { 149 if (videoTag.videoWidth > 0 && videoTag.videoHeight > 0) {
151 debug('Set video tag "' + videoTagId + '" width and height to ' + 150 debug('Set video tag "' + videoTagId + '" width and height to ' +
152 videoTag.videoWidth + 'x' + videoTag.videoHeight); 151 videoTag.videoWidth + 'x' + videoTag.videoHeight);
153 videoTag.width = videoTag.videoWidth; 152 videoTag.width = videoTag.videoWidth;
154 videoTag.height = videoTag.videoHeight; 153 videoTag.height = videoTag.videoHeight;
155 } 154 }
156 } 155 }
157 156
158 /** 157 /**
159 * @private 158 * @private
160 * @param {NavigatorUserMediaError} error Error containing details. 159 * @param {NavigatorUserMediaError} error Error containing details.
161 */ 160 */
162 function getUserMediaFailedCallback_(error) { 161 function getUserMediaFailedCallback_(error) {
phoglund_chromium 2013/03/22 15:07:18 Nit: line length
elham1 2013/03/25 21:58:23 Done.
163 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); 162 debug('doGetUserMedia FAILED: Maybe the camera is in use by another process?') ;
164 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code; 163 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + error.code;
165 } 164 }
166 165
167 $ = function(id) { 166 $ = function(id) {
168 return document.getElementById(id); 167 return document.getElementById(id);
169 }; 168 };
OLDNEW
« no previous file with comments | « no previous file | jsep01_call.js » ('j') | manual/constraints.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698