Skip to content

Commit

Permalink
Switch audio and video devices support
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Aug 29, 2019
1 parent 637d442 commit 558fcf3
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 53 deletions.
26 changes: 23 additions & 3 deletions dist/cordova-plugin-iosrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* cordova-plugin-iosrtc v5.0.0
* Cordova iOS plugin exposing the full WebRTC W3C JavaScript APIs
* Copyright 2015-2017 eFace2Face, Inc. (https://eface2face.com)
* Copyright 2017-2019 BasqueVoIPMafia (https://github.com/BasqueVoIPMafia)
* Copyright 2019 Cordova-RTC (https://github.com/cordova-rtc)
* Copyright 2015-2019 BasqueVoIPMafia (https://github.com/BasqueVoIPMafia)
* Copyright 2017-2019 Cordova-RTC (https://github.com/cordova-rtc)
* License MIT
*/

Expand Down Expand Up @@ -2357,6 +2357,11 @@ function getUserMedia(constraints) {
// Also check sourceId (mangled by adapter.js).
} else if (typeof constraints.video.sourceId === 'string') {
newConstraints.videoDeviceId = constraints.video.sourceId;
} else if (typeof constraints.video.deviceId === 'object') {
newConstraints.videoDeviceId = !!constraints.video.deviceId.exact ? constraints.video.deviceId.exact : constraints.video.deviceId.ideal;
if (Array.isArray(newConstraints.videoDeviceId)) {
newConstraints.videoDeviceId = newConstraints.videoDeviceId[0];
}
}

// Get requested min/max width.
Expand Down Expand Up @@ -2391,6 +2396,22 @@ function getUserMedia(constraints) {
}
}

// Get audio constraints
if (audioRequested) {
// Get requested audio deviceId.
if (typeof constraints.audio.deviceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.deviceId;
// Also check sourceId (mangled by adapter.js).
} else if (typeof constraints.audio.sourceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.sourceId;
} else if (typeof constraints.audio.deviceId === 'object') {
newConstraints.audioDeviceId = !!constraints.audio.deviceId.exact ? constraints.audio.deviceId.exact : constraints.audio.deviceId.ideal;
if (Array.isArray(newConstraints.audioDeviceId)) {
newConstraints.audioDeviceId = newConstraints.audioDeviceId[0];
}
}
}

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

if (isPromise) {
Expand Down Expand Up @@ -2433,7 +2454,6 @@ function getUserMedia(constraints) {

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

},{"./Errors":1,"./MediaStream":3,"cordova/exec":undefined,"debug":17}],15:[function(_dereq_,module,exports){
(function (global){
/**
Expand Down
23 changes: 22 additions & 1 deletion js/getUserMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function getUserMedia(constraints) {
// Also check sourceId (mangled by adapter.js).
} else if (typeof constraints.video.sourceId === 'string') {
newConstraints.videoDeviceId = constraints.video.sourceId;
} else if (typeof constraints.video.deviceId === 'object') {
newConstraints.videoDeviceId = !!constraints.video.deviceId.exact ? constraints.video.deviceId.exact : constraints.video.deviceId.ideal;
if (Array.isArray(newConstraints.videoDeviceId)) {
newConstraints.videoDeviceId = newConstraints.videoDeviceId[0];
}
}

// Get requested min/max width.
Expand Down Expand Up @@ -131,6 +136,22 @@ function getUserMedia(constraints) {
}
}

// Get audio constraints
if (audioRequested) {
// Get requested audio deviceId.
if (typeof constraints.audio.deviceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.deviceId;
// Also check sourceId (mangled by adapter.js).
} else if (typeof constraints.audio.sourceId === 'string') {
newConstraints.audioDeviceId = constraints.audio.sourceId;
} else if (typeof constraints.audio.deviceId === 'object') {
newConstraints.audioDeviceId = !!constraints.audio.deviceId.exact ? constraints.audio.deviceId.exact : constraints.audio.deviceId.ideal;
if (Array.isArray(newConstraints.audioDeviceId)) {
newConstraints.audioDeviceId = newConstraints.audioDeviceId[0];
}
}
}

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

if (isPromise) {
Expand Down Expand Up @@ -172,4 +193,4 @@ function getUserMedia(constraints) {
}

exec(onResultOK, onResultError, 'iosrtcPlugin', 'getUserMedia', [newConstraints]);
}
}
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 558fcf3

Please sign in to comment.