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

Handle getUserMedia constraints mandatory / optional syntax that was … #405

Merged
merged 2 commits into from
Oct 9, 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
52 changes: 52 additions & 0 deletions dist/cordova-plugin-iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2348,6 +2348,40 @@ function getUserMedia(constraints) {

// Get video constraints
if (videoRequested) {

// Handle Stupid not up-to-date webrtc-adapter
// Note: Firefox [38+] does support a subset of constraints with getUserMedia(), but not the outdated syntax that Chrome and Opera are using.
// The mandatory / optional syntax was deprecated a in 2014, and minWidth and minHeight the year before that.

if (
typeof constraints.video === 'object' &&
(typeof constraints.video.optional === 'object' || 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 (isPositiveFloat(videoConstraints.minWidth)) {
constraints.video.width = {
min: videoConstraints.minWidth
};
}

if (isPositiveFloat(videoConstraints.minHeight)) {
constraints.video.height = {
min: videoConstraints.minHeight
};
}
}

// Handle getUserMedia proper spec

// Get requested video deviceId.
if (typeof constraints.video.deviceId === 'string') {
newConstraints.videoDeviceId = constraints.video.deviceId;
Expand Down Expand Up @@ -2395,6 +2429,24 @@ function getUserMedia(constraints) {

// Get audio constraints
if (audioRequested) {

// Handle Stupid not up-to-date webrtc-adapter
// Note: Firefox [38+] does support a subset of constraints with getUserMedia(), but not the outdated syntax that Chrome and Opera are using.
// The mandatory / optional syntax was deprecated a in 2014, and minWidth and minHeight the year before that.
if (
typeof constraints.audio === 'object' &&
(typeof constraints.audio.optional === 'object' || constraints.audio.mandatory === 'object')
) {
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;
}
}

// Get requested audio deviceId.
if (typeof constraints.audio.deviceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.deviceId;
Expand Down
52 changes: 52 additions & 0 deletions js/getUserMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,40 @@ function getUserMedia(constraints) {

// Get video constraints
if (videoRequested) {

// Handle Stupid not up-to-date webrtc-adapter
// Note: Firefox [38+] does support a subset of constraints with getUserMedia(), but not the outdated syntax that Chrome and Opera are using.
// The mandatory / optional syntax was deprecated a in 2014, and minWidth and minHeight the year before that.

if (
typeof constraints.video === 'object' &&
(typeof constraints.video.optional === 'object' || 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 (isPositiveFloat(videoConstraints.minWidth)) {
constraints.video.width = {
min: videoConstraints.minWidth
};
}

if (isPositiveFloat(videoConstraints.minHeight)) {
constraints.video.height = {
min: videoConstraints.minHeight
};
}
}

// Handle getUserMedia proper spec

// Get requested video deviceId.
if (typeof constraints.video.deviceId === 'string') {
newConstraints.videoDeviceId = constraints.video.deviceId;
Expand Down Expand Up @@ -123,6 +157,24 @@ function getUserMedia(constraints) {

// Get audio constraints
if (audioRequested) {

// Handle Stupid not up-to-date webrtc-adapter
// Note: Firefox [38+] does support a subset of constraints with getUserMedia(), but not the outdated syntax that Chrome and Opera are using.
// The mandatory / optional syntax was deprecated a in 2014, and minWidth and minHeight the year before that.
if (
typeof constraints.audio === 'object' &&
(typeof constraints.audio.optional === 'object' || constraints.audio.mandatory === 'object')
) {
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;
}
}

// Get requested audio deviceId.
if (typeof constraints.audio.deviceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.deviceId;
Expand Down