Skip to content

Commit

Permalink
Merge pull request #405 from cordova-rtc/task/webrtc-adatper-stupid-m…
Browse files Browse the repository at this point in the history
…andatory-optional

Handle getUserMedia constraints mandatory / optional syntax that was …
  • Loading branch information
hthetiot authored Oct 9, 2019
2 parents 2ba633b + 901d3d1 commit c40dfcc
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
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

0 comments on commit c40dfcc

Please sign in to comment.