OLD | NEW |
---|---|
1 /** | 1 /** |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 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. See | 9 * information on getUserMedia. See |
10 * http://dev.w3.org/2011/webrtc/editor/webrtc.html for more information on | 10 * http://dev.w3.org/2011/webrtc/editor/webrtc.html for more information on |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 var forceIsac = $('force-isac').checked; | 187 var forceIsac = $('force-isac').checked; |
188 if (forceIsac) { | 188 if (forceIsac) { |
189 forceIsac_(); | 189 forceIsac_(); |
190 } else { | 190 } else { |
191 dontTouchSdp_(); | 191 dontTouchSdp_(); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 /** | 195 /** |
196 * Updates the constraints in the getusermedia-constraints text box with a | 196 * Updates the constraints in the getusermedia-constraints text box with a |
197 * MediaStreamConstraints string. This string is created based on the status of | 197 * MediaStreamConstraints string. This string is created based on the state |
phoglund_chromium
2014/06/19 11:54:35
Nit: don't indent comments like this.
jansson
2014/06/19 13:02:32
Done.
| |
198 * the checkboxes for audio and video. If device enumeration is supported and | 198 * of the 'audiosrc' and 'videosrc' checboxes. |
phoglund_chromium
2014/06/19 11:54:35
Nit: checkboxes
jansson
2014/06/19 13:02:32
Done.
| |
199 * device source id's are not null they will be added to the constraints string. | 199 * If device enumeration is supported and device source id's are not null they |
200 * Fetches the screen size using "screen" in Chrome as we need to pass a max | 200 * will be added to the constraints string. |
201 * resolution else it defaults to 640x480 in the constraints for screen | |
202 * capturing. | |
203 */ | 201 */ |
204 function updateGetUserMediaConstraints() { | 202 function updateGetUserMediaConstraints() { |
205 var audioSelected = $('audiosrc'); | 203 var selectedAudioDevice = $('audiosrc'); |
206 var videoSelected = $('videosrc'); | 204 var selectedVideoDevice = $('videosrc'); |
207 var constraints = { | 205 var constraints = {audio: $('audio').checked, |
208 audio: $('audio').checked, | 206 video: $('video').checked |
209 video: $('video').checked | |
210 }; | 207 }; |
211 | 208 |
212 if (audioSelected.disabled == false && videoSelected.disabled == false) { | 209 if ($('video').checked) { |
213 var devices = getSourcesFromField_(audioSelected, videoSelected); | 210 // Default optional constraints placed here. |
214 if ($('audio').checked == true) { | 211 constraints.video = {optional: [{minWidth: $('video-width').value}, |
215 if (devices.audioId != null) { | 212 {minHeight: $('video-height').value}, |
213 {googLeakyBucket: true}]}; | |
214 } | |
215 | |
216 if (!selectedAudioDevice.disabled && !selectedAudioDevice.disabled) { | |
217 var devices = getSourcesFromField_(selectedAudioDevice, | |
218 selectedVideoDevice); | |
219 | |
220 if ($('audio').checked) { | |
221 if (devices.audioId != null) | |
216 constraints.audio = {optional: [{sourceId: devices.audioId}]}; | 222 constraints.audio = {optional: [{sourceId: devices.audioId}]}; |
217 } else { | |
218 constraints.audio = true; | |
219 } | |
220 } | 223 } |
221 if ($('video').checked == true) { | 224 |
222 // Default optional constraints placed here. | 225 if ($('video').checked) { |
223 constraints.video = {optional: [{minWidth: $('video-width').value}, | 226 if (devices.videoId != null) |
224 {minHeight: $('video-height').value}, | |
225 {googLeakyBucket: true}] | |
226 }; | |
227 if (devices.videoId != null) { | |
228 constraints.video.optional.push({sourceId: devices.videoId}); | 227 constraints.video.optional.push({sourceId: devices.videoId}); |
229 } | |
230 } | 228 } |
231 } | 229 } |
232 | 230 |
233 if ($('screencapture').checked) { | 231 if ($('screencapture').checked) { |
234 var constraints = { | 232 var constraints = { |
235 audio: $('audio').checked, | 233 audio: $('audio').checked, |
236 video: {mandatory: {chromeMediaSource: 'screen', | 234 video: {mandatory: {chromeMediaSource: 'screen', |
237 maxWidth: screen.width, | 235 maxWidth: screen.width, |
238 maxHeight: screen.height}} | 236 maxHeight: screen.height}} |
239 }; | 237 }; |
240 if ($('audio').checked == true) | 238 if ($('audio').checked) |
241 print_('Audio for screencapture is not implemented yet, please ' + | 239 print_('Audio for screencapture is not implemented yet, please ' + |
242 'try to set audio = false prior requesting screencapture'); | 240 'try to set audio = false prior requesting screencapture'); |
243 } | 241 } |
242 | |
244 $('getusermedia-constraints').value = JSON.stringify(constraints, null, ' '); | 243 $('getusermedia-constraints').value = JSON.stringify(constraints, null, ' '); |
245 } | 244 } |
246 | 245 |
247 function showServerHelp() { | 246 function showServerHelp() { |
248 alert('You need to build and run a peerconnection_server on some ' + | 247 alert('You need to build and run a peerconnection_server on some ' + |
249 'suitable machine. To build it in chrome, just run make/ninja ' + | 248 'suitable machine. To build it in chrome, just run make/ninja ' + |
250 'peerconnection_server. Otherwise, read in https://code.google' + | 249 'peerconnection_server. Otherwise, read in https://code.google' + |
251 '.com/searchframe#xSWYf0NTG_Q/trunk/peerconnection/README&q=REA' + | 250 '.com/searchframe#xSWYf0NTG_Q/trunk/peerconnection/README&q=REA' + |
252 'DME%20package:webrtc%5C.googlecode%5C.com.'); | 251 'DME%20package:webrtc%5C.googlecode%5C.com.'); |
253 } | 252 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 try { | 295 try { |
297 peerConnection.removeStream(global.localStream); | 296 peerConnection.removeStream(global.localStream); |
298 } catch (exception) { | 297 } catch (exception) { |
299 error_('Could not remove stream: ' + exception); | 298 error_('Could not remove stream: ' + exception); |
300 } | 299 } |
301 print_('Removed local stream.'); | 300 print_('Removed local stream.'); |
302 } | 301 } |
303 | 302 |
304 /** | 303 /** |
305 * Enumerates the audio and video devices available in Chrome and adds the | 304 * Enumerates the audio and video devices available in Chrome and adds the |
306 * devices to the HTML elements with Id 'audiosrc' and 'videosrc'. | 305 * devices to the HTML elements with Id 'audiosrc' and 'videosrc'. |
phoglund_chromium
2014/06/19 11:54:35
Nit: don't indent here either.
jansson
2014/06/19 13:02:32
Done.
| |
307 * Checks if device enumeration is supported and if the 'audiosrc' + 'videosrc' | 306 * Checks if device enumeration is supported and if the 'audiosrc' + 'videosrc' |
308 * elements exists, if not a debug printout will be displayed. | 307 * elements exists, if not a debug printout will be displayed. |
309 * If the device label is empty, audio/video + sequence number will be used to | 308 * If the device label is empty, audio/video + sequence number will be used to |
310 * populate the name. Also makes sure the children has been loaded in order | 309 * populate the name. Also makes sure the children has been loaded in order |
311 * to update the constraints. | 310 * to update the constraints. |
312 */ | 311 */ |
313 function getDevices() { | 312 function getDevices() { |
314 var audio_select = $('audiosrc'); | 313 selectedAudioDevice = $('audiosrc'); |
315 var video_select = $('videosrc'); | 314 selectedVideoDevice = $('videosrc'); |
316 var get_devices = $('get-devices'); | 315 selectedAudioDevice.innerHTML = ''; |
317 audio_select.innerHTML = ''; | 316 selectedVideoDevice.innerHTML = ''; |
318 video_select.innerHTML = ''; | 317 |
319 try { | 318 try { |
320 eval(MediaStreamTrack.getSources(function() {})); | 319 eval(MediaStreamTrack.getSources(function() {})); |
321 } catch (exception) { | 320 } catch (exception) { |
322 audio_select.disabled = true; | 321 selectedAudioDevice.disabled = true; |
323 video_select.disabled = true; | 322 selectedVideoDevice.disabled = true; |
324 refresh_devices.disabled = true; | 323 $('get-devices').disabled = true; |
324 $('get-devices-onload').disabled = true; | |
325 updateGetUserMediaConstraints(); | 325 updateGetUserMediaConstraints(); |
326 error_('Device enumeration not supported. ' + exception); | 326 error_('Device enumeration not supported. ' + exception); |
327 } | 327 } |
328 | |
328 MediaStreamTrack.getSources(function(devices) { | 329 MediaStreamTrack.getSources(function(devices) { |
329 for (var i = 0; i < devices.length; i++) { | 330 for (var i = 0; i < devices.length; i++) { |
330 var option = document.createElement('option'); | 331 var option = document.createElement('option'); |
331 option.value = devices[i].id; | 332 option.value = devices[i].id; |
332 option.text = devices[i].label; | 333 option.text = devices[i].label; |
334 | |
333 if (devices[i].kind == 'audio') { | 335 if (devices[i].kind == 'audio') { |
334 if (option.text == '') { | 336 if (option.text == '') { |
335 option.text = devices[i].id; | 337 option.text = devices[i].id; |
336 } | 338 } |
337 audio_select.appendChild(option); | 339 selectedAudioDevice.appendChild(option); |
338 } else if (devices[i].kind == 'video') { | 340 } else if (devices[i].kind == 'video') { |
339 if (option.text == '') { | 341 if (option.text == '') { |
340 option.text = devices[i].id; | 342 option.text = devices[i].id; |
341 } | 343 } |
342 video_select.appendChild(option); | 344 selectedVideoDevice.appendChild(option); |
343 } else { | 345 } else { |
344 error_('Device type ' + devices[i].kind + ' not recognized, ' + | 346 error_('Device type ' + devices[i].kind + ' not recognized, ' + |
345 'cannot enumerate device. Currently only device types' + | 347 'cannot enumerate device. Currently only device types' + |
346 '\'audio\' and \'video\' are supported'); | 348 '\'audio\' and \'video\' are supported'); |
347 updateGetUserMediaConstraints(); | 349 updateGetUserMediaConstraints(); |
348 return; | 350 return; |
349 } | 351 } |
350 } | 352 } |
351 }); | 353 }); |
354 | |
352 checkIfDeviceDropdownsArePopulated_(); | 355 checkIfDeviceDropdownsArePopulated_(); |
353 } | 356 } |
354 | 357 |
355 /** | 358 /** |
356 * Sets the transform to apply just before setting the local description and | 359 * Sets the transform to apply just before setting the local description and |
357 * sending to the peer. | 360 * sending to the peer. |
358 * @param {function} transformFunction A function which takes one SDP string as | 361 * @param {function} transformFunction A function which takes one SDP string as |
359 * argument and returns the modified SDP string. | 362 * argument and returns the modified SDP string. |
360 */ | 363 */ |
361 function setOutgoingSdpTransform(transformFunction) { | 364 function setOutgoingSdpTransform(transformFunction) { |
362 global.transformOutgoingSdp = transformFunction; | 365 global.transformOutgoingSdp = transformFunction; |
363 } | 366 } |
364 | 367 |
365 /** | 368 /** |
366 * Sets the MediaConstraints to be used for PeerConnection createAnswer() calls. | 369 * Sets the MediaConstraints to be used for PeerConnection createAnswer() calls. |
367 * @param {string} mediaConstraints The constraints, as defined in the | 370 * @param {string} mediaConstraints The constraints, as defined in the |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1379 | 1382 |
1380 /** @private */ | 1383 /** @private */ |
1381 function readResponseHeader_(request, key) { | 1384 function readResponseHeader_(request, key) { |
1382 var value = request.getResponseHeader(key); | 1385 var value = request.getResponseHeader(key); |
1383 if (value == null || value.length == 0) { | 1386 if (value == null || value.length == 0) { |
1384 error_('Received empty value ' + value + | 1387 error_('Received empty value ' + value + |
1385 ' for response header key ' + key + '.'); | 1388 ' for response header key ' + key + '.'); |
1386 } | 1389 } |
1387 return parseInt(value); | 1390 return parseInt(value); |
1388 } | 1391 } |
OLD | NEW |