Skip to content

Commit

Permalink
✨ Issue #9 Implementation for pre-fetching device and constraint data
Browse files Browse the repository at this point in the history
  • Loading branch information
maverickmishra committed Nov 14, 2017
1 parent efaec7f commit 92309fe
Showing 1 changed file with 32 additions and 45 deletions.
77 changes: 32 additions & 45 deletions www/mediadevices.js
Expand Up @@ -20,59 +20,35 @@
*/
/* globals Promise, cordova, MediaStream */
var exec = cordova.require('cordova/exec');
var flagConstraints = true;
var flagDevices = true;
var channel = require('cordova/channel');

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: null,

This comment has been minimized.

Copy link
@macdonst

macdonst Nov 14, 2017

Member

@maverickmishra I double checked in the spec and this should be an empty list if there are no 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;
};

// assign new values returned from native ios ; until then default values returned
if (flagConstraints) {
exec(success, null, 'Stream', 'getSupportedConstraints', []);
}

flagConstraints = false;
return supportedConstraints;
return this._supportedConstraints;
};

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

if (flagDevices) {
exec(success, null, 'Stream', 'enumerateDevices', []);
} else {
resolve(that._devices);
}
resolve(that._devices);
});
};

Expand All @@ -95,6 +71,17 @@ mediaDevices.getUserMedia = function (constraints) {
}
});
};
mediaDevices.getSupportedConstraints();
mediaDevices.enumerateDevices();

channel.onCordovaReady.subscribe(function () {
var success = function (value) {
if ('devices' in value) {
mediaDevices._devices = value;
} else {
mediaDevices._supportedConstraints = value;
}
};
exec(success, null, 'Stream', 'getSupportedConstraints', []);
exec(success, null, 'Stream', 'enumerateDevices', []);
});

module.exports = mediaDevices;

0 comments on commit 92309fe

Please sign in to comment.