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

Issue9 #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
78 changes: 42 additions & 36 deletions www/mediadevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,58 +20,51 @@
*/
/* globals Promise, cordova, MediaStream */
var exec = cordova.require('cordova/exec');
var channel = require('cordova/channel');
var flagConstraints = true;
var flagDevices = true;

var mediaDevices = {
_devices: null
};

var supportedConstraints = {
width: true,
height: true,
aspectRatio: true,
frameRate: true,
facingMode: true,
volume: true,
sampleRate: true,
sampleSize: true,
echoCancellation: true,
latency: true,
channelCount: true,
deviceId: true,
groupId: true
_devices: [],
_supportedConstraints: {
width: true,
height: true,
aspectRatio: true,
frameRate: true,
facingMode: true,
volume: true,
sampleRate: true,
sampleSize: true,
echoCancellation: true,
latency: true,
channelCount: true,
deviceId: true,
groupId: true
}
};

mediaDevices.getSupportedConstraints = function () {
var success = function (constraints) {
console.log('constraints: ' + JSON.stringify(constraints));
supportedConstraints = constraints;
var successConstraints = function (constraints) {
mediaDevices._supportedConstraints = constraints;
flagConstraints = false;
};

// assign new values returned from native ios ; until then default values returned
if (flagConstraints) {
exec(success, null, 'Stream', 'getSupportedConstraints', []);
if (!flagConstraints) {
return this._supportedConstraints;
} else {
exec(successConstraints, null, 'Stream', 'getSupportedConstraints', []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maverickmishra they only thing that needs to be changes is after the exec call we'll need to:

return this._supportedConstraints;

This will return the default constraints as per the spec. Without a return statement here the function will return an undefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had missed it for mediaDevices.enumerateDevices() as well. Fixed it now

}

flagConstraints = false;
return supportedConstraints;
};

mediaDevices.enumerateDevices = function () {
var that = this;
return new Promise(function (resolve, reject) {
var success = function (device) {
var successDevices = function (device) {
mediaDevices._devices = device.devices;
flagDevices = false;
console.log('success ' + device.devices);
that._devices = device.devices;
resolve(that._devices);
};

if (flagDevices) {
exec(success, null, 'Stream', 'enumerateDevices', []);
} else {
if (!flagDevices) {
resolve(that._devices);
} else {
exec(successDevices, null, 'Stream', 'enumerateDevices', []);
}
});
};
Expand All @@ -96,4 +89,17 @@ mediaDevices.getUserMedia = function (constraints) {
});
};

channel.onCordovaReady.subscribe(function () {
var successConstraints = function (constraints) {
mediaDevices._supportedConstraints = constraints;
flagConstraints = false;
};
var successDevices = function (device) {
mediaDevices._devices = device.devices;
flagDevices = false;
};
exec(successConstraints, null, 'Stream', 'getSupportedConstraints', []);
exec(successDevices, null, 'Stream', 'enumerateDevices', []);
});

module.exports = mediaDevices;