Skip to content

Commit

Permalink
Fix and Update getUserMedia webrtc-adapter constaints support
Browse files Browse the repository at this point in the history
  • Loading branch information
hthetiot authored Oct 11, 2019
1 parent c40dfcc commit 621e88e
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions js/getUserMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,34 @@ function getUserMedia(constraints) {

if (
typeof constraints.video === 'object' &&
(typeof constraints.video.optional === 'object' || constraints.video.mandatory === 'object')
(typeof constraints.video.optional === 'object' || typeof constraints.video.mandatory === 'object')
) {

var videoConstraints = constraints.video.mandatory || constraints.video.optional;
videoConstraints = Array.isArray(videoConstraints) ? videoConstraints[0] : videoConstraints;

constraints.video = {};

if (typeof videoConstraints.sourceId === 'string') {
constraints.video.deviceId = videoConstraints.sourceId;
if (constraints.video.optional && constraints.video.optional.sourceId) {
newConstraints.videoDeviceId = constraints.video.optional.sourceId;
} else {
newConstraints.videoDeviceId = constraints.video.mandatory.sourceId;
}
}

if (isPositiveFloat(videoConstraints.minWidth)) {
constraints.video.width = {
min: videoConstraints.minWidth
};
if (isPositiveInteger(videoConstraints.minWidth)) {
newConstraints.video.videoMinWidth = videoConstraints.minWidth;
}

if (isPositiveInteger(videoConstraints.minHeight)) {
newConstraints.video.videoMinHeight = videoConstraints.minHeight;
}

if (isPositiveFloat(videoConstraints.minFrameRate)) {
newConstraints.videoMinFrameRate = parseFloat(videoConstraints.minFrameRate, 10);
}

if (isPositiveFloat(videoConstraints.minHeight)) {
constraints.video.height = {
min: videoConstraints.minHeight
};
if (isPositiveFloat(videoConstraints.maxFrameRate)) {
newConstraints.videoMaxFrameRate = parseFloat(videoConstraints.maxFrameRate, 10);
}
}

Expand Down Expand Up @@ -144,14 +150,14 @@ function getUserMedia(constraints) {
// Get requested min/max frame rate.
if (typeof constraints.video.frameRate === 'object') {
if (isPositiveFloat(constraints.video.frameRate.min)) {
newConstraints.videoMinFrameRate = constraints.video.frameRate.min;
newConstraints.videoMinFrameRate = parseFloat(constraints.video.frameRate.min, 10);
}
if (isPositiveFloat(constraints.video.frameRate.max)) {
newConstraints.videoMaxFrameRate = constraints.video.frameRate.max;
newConstraints.videoMaxFrameRate = parseFloat(constraints.video.frameRate.max, 10);
}
} else if (isPositiveFloat(constraints.video.frameRate)) {
newConstraints.videoMinFrameRate = constraints.video.frameRate;
newConstraints.videoMaxFrameRate = constraints.video.frameRate;
newConstraints.videoMinFrameRate = parseFloat(constraints.video.frameRate, 10);
newConstraints.videoMaxFrameRate = parseFloat(constraints.video.frameRate, 10);
}
}

Expand All @@ -168,10 +174,12 @@ function getUserMedia(constraints) {
var audioConstraints = constraints.audio.mandatory || constraints.audio.optional;
audioConstraints = Array.isArray(audioConstraints) ? audioConstraints[0] : audioConstraints;

constraints.audio = {};

if (typeof audioConstraints.sourceId === 'string') {
constraints.audio.deviceId = audioConstraints.sourceId;
if (constraints.audio.optional && constraints.audio.optional.sourceId) {
newConstraints.audioDeviceId = constraints.audio.optional.sourceId;
} else {
newConstraints.audioDeviceId = constraints.audio.mandatory.sourceId;
}
}
}

Expand Down Expand Up @@ -207,4 +215,4 @@ function getUserMedia(constraints) {

exec(onResultOK, onResultError, 'iosrtcPlugin', 'getUserMedia', [newConstraints]);
});
}
}

0 comments on commit 621e88e

Please sign in to comment.