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 */ |
11 | 11 |
12 /** | 12 /** |
13 * Asks permission to use the webcam and mic from the browser. | 13 * Asks permission to use the webcam and mic from the browser. |
14 */ | 14 */ |
15 function getUserMedia() { | 15 function doGetUserMedia() { |
| 16 // Call into getUserMedia via the polyfill (adapter.js). |
16 var constraints = getConstraints_(); | 17 var constraints = getConstraints_(); |
17 var constraintsString = JSON.stringify(constraints, null, ' '); | 18 var constraintsString = JSON.stringify(constraints, null, ' '); |
18 $('getusermedia-constraints').innerHTML = constraintsString; | 19 $('getusermedia-constraints').innerHTML = constraintsString; |
19 if (!navigator.webkitGetUserMedia) { | 20 if (!getUserMedia) { |
20 log_('Browser does not support WebRTC.'); | 21 log_('Browser does not support WebRTC.'); |
21 return; | 22 return; |
22 } | 23 } |
23 log_('Requesting getUserMedia with constraints: ' + constraintsString); | 24 log_('Requesting getUserMedia with constraints: ' + constraintsString); |
24 navigator.webkitGetUserMedia(constraints, | 25 getUserMedia(constraints, getUserMediaOkCallback_, |
25 getUserMediaOkCallback_, | 26 getUserMediaFailedCallback_); |
26 getUserMediaFailedCallback_); | |
27 } | 27 } |
28 | 28 |
29 // Internals | 29 // Internals |
30 | 30 |
31 /** | 31 /** |
32 * Builds a Javascript constraints dictionary out of the selected options in the | 32 * Builds a Javascript constraints dictionary out of the selected options in the |
33 * HTML controls on the page. | 33 * HTML controls on the page. |
34 * @private | 34 * @private |
35 * @return {Object} A dictionary of constraints. | 35 * @return {Object} A dictionary of constraints. |
36 */ | 36 */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return c; | 97 return c; |
98 } | 98 } |
99 | 99 |
100 /** | 100 /** |
101 * @private | 101 * @private |
102 * @param {MediaStream} stream Media stream. | 102 * @param {MediaStream} stream Media stream. |
103 */ | 103 */ |
104 function getUserMediaOkCallback_(stream) { | 104 function getUserMediaOkCallback_(stream) { |
105 gLocalStream = stream; | 105 gLocalStream = stream; |
106 var videoTag = $('local-view'); | 106 var videoTag = $('local-view'); |
107 videoTag.src = webkitURL.createObjectURL(stream); | 107 attachMediaStream(videoTag, stream); |
108 | 108 |
109 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. | 109 // Due to crbug.com/110938 the size is 0 when onloadedmetadata fires. |
110 // videoTag.onloadedmetadata = updateVideoTagSize_(videoTag); | 110 // videoTag.onloadedmetadata = updateVideoTagSize_(videoTag); |
111 // Use setTimeout as a workaround for now. | 111 // Use setTimeout as a workaround for now. |
112 setTimeout(function() {updateVideoTagSize_(videoTag)}, 500); | 112 setTimeout(function() {updateVideoTagSize_(videoTag)}, 500); |
113 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 113 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
114 } | 114 } |
115 | 115 |
116 /** | 116 /** |
117 * @private | 117 * @private |
(...skipping 23 matching lines...) Expand all Loading... |
141 | 141 |
142 /** | 142 /** |
143 * Simple logging function. | 143 * Simple logging function. |
144 * @private | 144 * @private |
145 * @param {string} message Message to print. | 145 * @param {string} message Message to print. |
146 */ | 146 */ |
147 function log_(message) { | 147 function log_(message) { |
148 console.log(message); | 148 console.log(message); |
149 $('messages').innerHTML += message + '<br>'; | 149 $('messages').innerHTML += message + '<br>'; |
150 } | 150 } |
OLD | NEW |