Commit 5aadf1f8 authored by jansson@chromium.org's avatar jansson@chromium.org

Renamed erronous element id refresh_devices to get_devices.

Simplified the updateGetUserMediaConstraints function.

BUG=None
Test=gjslint, manually setup a call, verified that the constraints are
updated correctly.

Review URL: https://codereview.chromium.org/338853008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278409 0039d316-1c4b-4281-b951-d872f2087c98
parent a03cf54a
...@@ -194,39 +194,37 @@ function forceIsacChanged() { ...@@ -194,39 +194,37 @@ function forceIsacChanged() {
/** /**
* Updates the constraints in the getusermedia-constraints text box with a * Updates the constraints in the getusermedia-constraints text box with a
* MediaStreamConstraints string. This string is created based on the status of * MediaStreamConstraints string. This string is created based on the state
* the checkboxes for audio and video. If device enumeration is supported and * of the 'audiosrc' and 'videosrc' checkboxes.
* device source id's are not null they will be added to the constraints string. * If device enumeration is supported and device source id's are not null they
* Fetches the screen size using "screen" in Chrome as we need to pass a max * will be added to the constraints string.
* resolution else it defaults to 640x480 in the constraints for screen
* capturing.
*/ */
function updateGetUserMediaConstraints() { function updateGetUserMediaConstraints() {
var audioSelected = $('audiosrc'); var selectedAudioDevice = $('audiosrc');
var videoSelected = $('videosrc'); var selectedVideoDevice = $('videosrc');
var constraints = { var constraints = {audio: $('audio').checked,
audio: $('audio').checked, video: $('video').checked
video: $('video').checked
}; };
if (audioSelected.disabled == false && videoSelected.disabled == false) { if ($('video').checked) {
var devices = getSourcesFromField_(audioSelected, videoSelected); // Default optional constraints placed here.
if ($('audio').checked == true) { constraints.video = {optional: [{minWidth: $('video-width').value},
if (devices.audioId != null) { {minHeight: $('video-height').value},
{googLeakyBucket: true}]};
}
if (!selectedAudioDevice.disabled && !selectedAudioDevice.disabled) {
var devices = getSourcesFromField_(selectedAudioDevice,
selectedVideoDevice);
if ($('audio').checked) {
if (devices.audioId != null)
constraints.audio = {optional: [{sourceId: devices.audioId}]}; constraints.audio = {optional: [{sourceId: devices.audioId}]};
} else {
constraints.audio = true;
}
} }
if ($('video').checked == true) {
// Default optional constraints placed here. if ($('video').checked) {
constraints.video = {optional: [{minWidth: $('video-width').value}, if (devices.videoId != null)
{minHeight: $('video-height').value},
{googLeakyBucket: true}]
};
if (devices.videoId != null) {
constraints.video.optional.push({sourceId: devices.videoId}); constraints.video.optional.push({sourceId: devices.videoId});
}
} }
} }
...@@ -237,10 +235,11 @@ function updateGetUserMediaConstraints() { ...@@ -237,10 +235,11 @@ function updateGetUserMediaConstraints() {
maxWidth: screen.width, maxWidth: screen.width,
maxHeight: screen.height}} maxHeight: screen.height}}
}; };
if ($('audio').checked == true) if ($('audio').checked)
print_('Audio for screencapture is not implemented yet, please ' + print_('Audio for screencapture is not implemented yet, please ' +
'try to set audio = false prior requesting screencapture'); 'try to set audio = false prior requesting screencapture');
} }
$('getusermedia-constraints').value = JSON.stringify(constraints, null, ' '); $('getusermedia-constraints').value = JSON.stringify(constraints, null, ' ');
} }
...@@ -311,35 +310,38 @@ function removeLocalStreamFromPeerConnection(peerConnection) { ...@@ -311,35 +310,38 @@ function removeLocalStreamFromPeerConnection(peerConnection) {
* to update the constraints. * to update the constraints.
*/ */
function getDevices() { function getDevices() {
var audio_select = $('audiosrc'); selectedAudioDevice = $('audiosrc');
var video_select = $('videosrc'); selectedVideoDevice = $('videosrc');
var get_devices = $('get-devices'); selectedAudioDevice.innerHTML = '';
audio_select.innerHTML = ''; selectedVideoDevice.innerHTML = '';
video_select.innerHTML = '';
try { try {
eval(MediaStreamTrack.getSources(function() {})); eval(MediaStreamTrack.getSources(function() {}));
} catch (exception) { } catch (exception) {
audio_select.disabled = true; selectedAudioDevice.disabled = true;
video_select.disabled = true; selectedVideoDevice.disabled = true;
refresh_devices.disabled = true; $('get-devices').disabled = true;
$('get-devices-onload').disabled = true;
updateGetUserMediaConstraints(); updateGetUserMediaConstraints();
error_('Device enumeration not supported. ' + exception); error_('Device enumeration not supported. ' + exception);
} }
MediaStreamTrack.getSources(function(devices) { MediaStreamTrack.getSources(function(devices) {
for (var i = 0; i < devices.length; i++) { for (var i = 0; i < devices.length; i++) {
var option = document.createElement('option'); var option = document.createElement('option');
option.value = devices[i].id; option.value = devices[i].id;
option.text = devices[i].label; option.text = devices[i].label;
if (devices[i].kind == 'audio') { if (devices[i].kind == 'audio') {
if (option.text == '') { if (option.text == '') {
option.text = devices[i].id; option.text = devices[i].id;
} }
audio_select.appendChild(option); selectedAudioDevice.appendChild(option);
} else if (devices[i].kind == 'video') { } else if (devices[i].kind == 'video') {
if (option.text == '') { if (option.text == '') {
option.text = devices[i].id; option.text = devices[i].id;
} }
video_select.appendChild(option); selectedVideoDevice.appendChild(option);
} else { } else {
error_('Device type ' + devices[i].kind + ' not recognized, ' + error_('Device type ' + devices[i].kind + ' not recognized, ' +
'cannot enumerate device. Currently only device types' + 'cannot enumerate device. Currently only device types' +
...@@ -349,12 +351,13 @@ function getDevices() { ...@@ -349,12 +351,13 @@ function getDevices() {
} }
} }
}); });
checkIfDeviceDropdownsArePopulated_(); checkIfDeviceDropdownsArePopulated_();
} }
/** /**
* Sets the transform to apply just before setting the local description and * Sets the transform to apply just before setting the local description and
* sending to the peer. * sending to the peer.
* @param {function} transformFunction A function which takes one SDP string as * @param {function} transformFunction A function which takes one SDP string as
* argument and returns the modified SDP string. * argument and returns the modified SDP string.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment