Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve video constraints (width|height|aspectRatio|frameRate).(ideal|exact) and add (aspectRatio|frameRate|facingMode).(ideal|exact) support enhancement #451

Merged
merged 3 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions dist/cordova-plugin-iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2396,20 +2396,20 @@ function getUserMedia(constraints) {
//
// getUserMedia({
// audio: {
// deviceId: 'azer-asdf-zxcv',
// deviceId: 'azer-asdf-zxcv',
// },
// video: {
// deviceId: 'qwer-asdf-zxcv',
// deviceId: 'qwer-asdf-zxcv',
// aspectRatio: 1.777.
// facingMode: 'user',
// width: {
// min: 400,
// max: 600
// },
// frameRate: {
// min: 1.0,
// max: 60.0
// }
// width: {
// min: 400,
// max: 600
// },
// frameRate: {
// min: 1.0,
// max: 60.0
// }
// }
// });

Expand Down Expand Up @@ -2510,7 +2510,7 @@ function getUserMedia(constraints) {
) {
newConstraints.video.deviceId = {
exact: constraints.video.mandatory.sourceId
};
};
}

// Only apply mandatory over optional
Expand Down Expand Up @@ -2577,7 +2577,12 @@ function getUserMedia(constraints) {
if (isPositiveInteger(constraints.video.width.max)) {
newConstraints.video.width.max = constraints.video.width.max;
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.width.exact)) {
newConstraints.video.width.exact = constraints.video.width.exact;
}
if (isPositiveInteger(constraints.video.width.ideal)) {
newConstraints.video.width.ideal = constraints.video.width.ideal;
}

// Get requested width long as exact
} else if (isPositiveInteger(constraints.video.width)) {
Expand All @@ -2595,7 +2600,12 @@ function getUserMedia(constraints) {
if (isPositiveInteger(constraints.video.height.max)) {
newConstraints.video.height.max = constraints.video.height.max;
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.height.exact)) {
newConstraints.video.height.exact = constraints.video.height.exact;
}
if (isPositiveInteger(constraints.video.height.ideal)) {
newConstraints.video.height.ideal = constraints.video.height.ideal;
}

// Get requested height long as exact
} else if (isPositiveInteger(constraints.video.height)) {
Expand All @@ -2613,7 +2623,12 @@ function getUserMedia(constraints) {
if (isPositiveFloat(constraints.video.frameRate.max)) {
newConstraints.video.frameRate.max = parseFloat(constraints.video.frameRate.max, 10);
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.frameRate.exact)) {
newConstraints.video.frameRate.exact = constraints.video.frameRate.exact;
}
if (isPositiveInteger(constraints.video.frameRate.ideal)) {
newConstraints.video.frameRate.ideal = constraints.video.frameRate.ideal;
}

// Get requested frameRate double as exact
} else if (isPositiveFloat(constraints.video.frameRate)) {
Expand All @@ -2624,7 +2639,20 @@ function getUserMedia(constraints) {

// get aspectRatio (e.g 1.7777777777777777)
// TODO ConstrainDouble min, max
if (isPositiveFloat(constraints.video.aspectRatio)) {
if (typeof constraints.video.aspectRatio === 'object') {
if (isPositiveFloat(constraints.video.aspectRatio.min)) {
newConstraints.video.aspectRatio.min = parseFloat(constraints.video.aspectRatio.min, 10);
}
if (isPositiveFloat(constraints.video.aspectRatio.max)) {
newConstraints.video.aspectRatio.max = parseFloat(constraints.video.aspectRatio.max, 10);
}
if (isPositiveInteger(constraints.video.aspectRatio.exact)) {
newConstraints.video.aspectRatio.exact = constraints.video.aspectRatio.exact;
}
if (isPositiveInteger(constraints.video.aspectRatio.ideal)) {
newConstraints.video.aspectRatio.ideal = constraints.video.aspectRatio.ideal;
}
} else if (isPositiveFloat(constraints.video.aspectRatio)) {
newConstraints.video.aspectRatio = {
exact: parseFloat(constraints.video.aspectRatio, 10)
};
Expand All @@ -2636,6 +2664,16 @@ function getUserMedia(constraints) {
newConstraints.video.facingMode = {
exact: constraints.video.facingMode
};
} else if (typeof constraints.video.facingMode === 'object') {
if (typeof constraints.video.facingMode.exact === 'string') {
newConstraints.video.facingMode = {
exact: constraints.video.facingMode.exact
};
} else if (constraints.video.facingMode.ideal === 'string') {
newConstraints.video.facingMode = {
ideal: constraints.video.facingMode.ideal
};
}
}
}

Expand Down Expand Up @@ -2674,7 +2712,7 @@ function getUserMedia(constraints) {
) {
newConstraints.audio.deviceId = {
exact: constraints.audio.mandatory.sourceId
};
};
}
}

Expand Down Expand Up @@ -2703,7 +2741,7 @@ function getUserMedia(constraints) {
constraints.audio.deviceId.ideal[0] : constraints.audio.deviceId.ideal
};
}
}
}
}

debug('[computed constraints:%o]', newConstraints);
Expand Down
72 changes: 55 additions & 17 deletions js/getUserMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ function getUserMedia(constraints) {
//
// getUserMedia({
// audio: {
// deviceId: 'azer-asdf-zxcv',
// deviceId: 'azer-asdf-zxcv',
// },
// video: {
// deviceId: 'qwer-asdf-zxcv',
// deviceId: 'qwer-asdf-zxcv',
// aspectRatio: 1.777.
// facingMode: 'user',
// width: {
// min: 400,
// max: 600
// },
// frameRate: {
// min: 1.0,
// max: 60.0
// }
// width: {
// min: 400,
// max: 600
// },
// frameRate: {
// min: 1.0,
// max: 60.0
// }
// }
// });

Expand Down Expand Up @@ -172,7 +172,7 @@ function getUserMedia(constraints) {
) {
newConstraints.video.deviceId = {
exact: constraints.video.mandatory.sourceId
};
};
}

// Only apply mandatory over optional
Expand Down Expand Up @@ -239,7 +239,12 @@ function getUserMedia(constraints) {
if (isPositiveInteger(constraints.video.width.max)) {
newConstraints.video.width.max = constraints.video.width.max;
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.width.exact)) {
newConstraints.video.width.exact = constraints.video.width.exact;
}
if (isPositiveInteger(constraints.video.width.ideal)) {
newConstraints.video.width.ideal = constraints.video.width.ideal;
}

// Get requested width long as exact
} else if (isPositiveInteger(constraints.video.width)) {
Expand All @@ -257,7 +262,12 @@ function getUserMedia(constraints) {
if (isPositiveInteger(constraints.video.height.max)) {
newConstraints.video.height.max = constraints.video.height.max;
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.height.exact)) {
newConstraints.video.height.exact = constraints.video.height.exact;
}
if (isPositiveInteger(constraints.video.height.ideal)) {
newConstraints.video.height.ideal = constraints.video.height.ideal;
}

// Get requested height long as exact
} else if (isPositiveInteger(constraints.video.height)) {
Expand All @@ -275,7 +285,12 @@ function getUserMedia(constraints) {
if (isPositiveFloat(constraints.video.frameRate.max)) {
newConstraints.video.frameRate.max = parseFloat(constraints.video.frameRate.max, 10);
}
// TODO exact, ideal
if (isPositiveInteger(constraints.video.frameRate.exact)) {
newConstraints.video.frameRate.exact = constraints.video.frameRate.exact;
}
if (isPositiveInteger(constraints.video.frameRate.ideal)) {
newConstraints.video.frameRate.ideal = constraints.video.frameRate.ideal;
}

// Get requested frameRate double as exact
} else if (isPositiveFloat(constraints.video.frameRate)) {
Expand All @@ -286,7 +301,20 @@ function getUserMedia(constraints) {

// get aspectRatio (e.g 1.7777777777777777)
// TODO ConstrainDouble min, max
if (isPositiveFloat(constraints.video.aspectRatio)) {
if (typeof constraints.video.aspectRatio === 'object') {
if (isPositiveFloat(constraints.video.aspectRatio.min)) {
newConstraints.video.aspectRatio.min = parseFloat(constraints.video.aspectRatio.min, 10);
}
if (isPositiveFloat(constraints.video.aspectRatio.max)) {
newConstraints.video.aspectRatio.max = parseFloat(constraints.video.aspectRatio.max, 10);
}
if (isPositiveInteger(constraints.video.aspectRatio.exact)) {
newConstraints.video.aspectRatio.exact = constraints.video.aspectRatio.exact;
}
if (isPositiveInteger(constraints.video.aspectRatio.ideal)) {
newConstraints.video.aspectRatio.ideal = constraints.video.aspectRatio.ideal;
}
} else if (isPositiveFloat(constraints.video.aspectRatio)) {
newConstraints.video.aspectRatio = {
exact: parseFloat(constraints.video.aspectRatio, 10)
};
Expand All @@ -298,6 +326,16 @@ function getUserMedia(constraints) {
newConstraints.video.facingMode = {
exact: constraints.video.facingMode
};
} else if (typeof constraints.video.facingMode === 'object') {
if (typeof constraints.video.facingMode.exact === 'string') {
newConstraints.video.facingMode = {
exact: constraints.video.facingMode.exact
};
} else if (constraints.video.facingMode.ideal === 'string') {
newConstraints.video.facingMode = {
ideal: constraints.video.facingMode.ideal
};
}
}
}

Expand Down Expand Up @@ -336,7 +374,7 @@ function getUserMedia(constraints) {
) {
newConstraints.audio.deviceId = {
exact: constraints.audio.mandatory.sourceId
};
};
}
}

Expand Down Expand Up @@ -365,7 +403,7 @@ function getUserMedia(constraints) {
constraints.audio.deviceId.ideal[0] : constraints.audio.deviceId.ideal
};
}
}
}
}

debug('[computed constraints:%o]', newConstraints);
Expand Down
Loading