| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 try { | 114 try { |
| 115 peerConnection.addStream(gLocalStream, gAddStreamConstraints); | 115 peerConnection.addStream(gLocalStream, gAddStreamConstraints); |
| 116 } catch (exception) { | 116 } catch (exception) { |
| 117 throw failTest('Failed to add stream with constraints ' + | 117 throw failTest('Failed to add stream with constraints ' + |
| 118 gAddStreamConstraints + ': ' + exception); | 118 gAddStreamConstraints + ': ' + exception); |
| 119 } | 119 } |
| 120 debug('Added local stream.'); | 120 debug('Added local stream.'); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Removes the local stream from the peer connection. | |
| 125 * @param {rtcpeerconnection} peerConnection | |
| 126 */ | |
| 127 function removeLocalStreamFromPeerConnection(peerConnection) { | |
| 128 if (gLocalStream == null) | |
| 129 throw failTest('Tried to remove local stream from peer connection, ' + | |
| 130 'but there is no stream yet.'); | |
| 131 try { | |
| 132 peerConnection.removeStream(gLocalStream); | |
| 133 } catch (exception) { | |
| 134 throw failTest('Could not remove stream: ' + exception); | |
| 135 } | |
| 136 debug('Removed local stream.'); | |
| 137 } | |
| 138 | |
| 139 /** | |
| 140 * @return {string} Returns the current local stream - |gLocalStream|. | 124 * @return {string} Returns the current local stream - |gLocalStream|. |
| 141 */ | 125 */ |
| 142 function getLocalStream() { | 126 function getLocalStream() { |
| 143 return gLocalStream; | 127 return gLocalStream; |
| 144 } | 128 } |
| 145 | 129 |
| 146 // Internals. | 130 // Internals. |
| 147 | 131 |
| 148 /** | 132 /** |
| 149 * @private | 133 * @private |
| (...skipping 22 matching lines...) Expand all Loading... |
| 172 * @param {MediaStream} stream Media stream. | 156 * @param {MediaStream} stream Media stream. |
| 173 */ | 157 */ |
| 174 function getUserMediaOkCallback_(stream) { | 158 function getUserMediaOkCallback_(stream) { |
| 175 gLocalStream = stream; | 159 gLocalStream = stream; |
| 176 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; | 160 gRequestWebcamAndMicrophoneResult = 'ok-got-stream'; |
| 177 | 161 |
| 178 attachMediaStream($('local-view'), stream); | 162 attachMediaStream($('local-view'), stream); |
| 179 } | 163 } |
| 180 | 164 |
| 181 /** | 165 /** |
| 182 * Enumerates the audio and video devices available in Chrome and adds the | |
| 183 * devices to the HTML elements with Id 'audiosrc' and 'videosrc'. | |
| 184 * Checks if device enumeration is supported and if the 'audiosrc' + 'videosrc' | |
| 185 * elements exists, if not a debug printout will be displayed. | |
| 186 * If the device label is empty, audio/video + sequence number will be used to | |
| 187 * populate the name. Also makes sure the children has been loaded in order | |
| 188 * to update the constraints. | |
| 189 */ | |
| 190 function getDevices() { | |
| 191 if ($('audiosrc') && $('videosrc') && $('get-devices')) { | |
| 192 var audio_select = $('audiosrc'); | |
| 193 var video_select = $('videosrc'); | |
| 194 var get_devices = $('get-devices'); | |
| 195 audio_select.innerHTML = ''; | |
| 196 video_select.innerHTML = ''; | |
| 197 try { | |
| 198 eval(MediaStreamTrack.getSources(function() {})); | |
| 199 } catch (exception) { | |
| 200 audio_select.disabled = true; | |
| 201 video_select.disabled = true; | |
| 202 get_devices.disabled = true; | |
| 203 updateGetUserMediaConstraints(); | |
| 204 debug('Device enumeration not supported. ' + exception); | |
| 205 return; | |
| 206 } | |
| 207 MediaStreamTrack.getSources(function(devices) { | |
| 208 for (var i = 0; i < devices.length; i++) { | |
| 209 var option = document.createElement('option'); | |
| 210 option.value = devices[i].id; | |
| 211 option.text = devices[i].label; | |
| 212 if (devices[i].kind == 'audio') { | |
| 213 if (option.text == '') { | |
| 214 option.text = devices[i].id; | |
| 215 } | |
| 216 audio_select.appendChild(option); | |
| 217 } | |
| 218 else if (devices[i].kind == 'video') { | |
| 219 if (option.text == '') { | |
| 220 option.text = devices[i].id; | |
| 221 } | |
| 222 video_select.appendChild(option); | |
| 223 } | |
| 224 else { | |
| 225 debug('Device type ' + devices[i].kind + ' not recognized, cannot ' + | |
| 226 'enumerate device. Currently only device types \'audio\' and ' + | |
| 227 '\'video\' are supported'); | |
| 228 updateGetUserMediaConstraints(); | |
| 229 return; | |
| 230 } | |
| 231 } | |
| 232 }); | |
| 233 checkIfDeviceDropdownsArePopulated(); | |
| 234 } | |
| 235 else { | |
| 236 debug('Device DOM elements cannot be found, cannot display devices'); | |
| 237 updateGetUserMediaConstraints(); | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 /** | |
| 242 * This provides the selected source id from the objects in the parameters | |
| 243 * provided to this function. If the audio_select or video_select objects does | |
| 244 * not have any HTMLOptions children it will return null in the source object. | |
| 245 * @param {object} audio_select HTML drop down element with audio devices added | |
| 246 * as HTMLOptionsCollection children. | |
| 247 * @param {object} video_select HTML drop down element with audio devices added | |
| 248 * as HTMLPptionsCollection children. | |
| 249 * @return {object} audio_id video_id Containing audio and video source ID from | |
| 250 * the selected devices in the drop down menus provided as parameters to | |
| 251 * this function. | |
| 252 */ | |
| 253 function getSourcesFromField(audio_select, video_select) { | |
| 254 var source = { | |
| 255 audio_id: null, | |
| 256 video_id: null | |
| 257 }; | |
| 258 if (audio_select.options.length > 0) { | |
| 259 source.audio_id = audio_select.options[audio_select.selectedIndex].value; | |
| 260 } | |
| 261 if (video_select.options.length > 0) { | |
| 262 source.video_id = video_select.options[video_select.selectedIndex].value; | |
| 263 } | |
| 264 return source; | |
| 265 } | |
| 266 | |
| 267 /** | |
| 268 * @private | 166 * @private |
| 269 * @param {NavigatorUserMediaError} error Error containing details. | 167 * @param {NavigatorUserMediaError} error Error containing details. |
| 270 */ | 168 */ |
| 271 function getUserMediaFailedCallback_(error) { | 169 function getUserMediaFailedCallback_(error) { |
| 272 // Translate from the old error to the new. Remove when rename fully deployed. | 170 // Translate from the old error to the new. Remove when rename fully deployed. |
| 273 var errorName = error.name; | 171 var errorName = error.name; |
| 274 | 172 |
| 275 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); | 173 debug('GetUserMedia FAILED: Maybe the camera is in use by another process?'); |
| 276 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName; | 174 gRequestWebcamAndMicrophoneResult = 'failed-with-error-' + errorName; |
| 277 debug(gRequestWebcamAndMicrophoneResult); | 175 debug(gRequestWebcamAndMicrophoneResult); |
| 278 } | 176 } |
| OLD | NEW |