var Janus = require('../externals/janus.nojquery');
var Promise = require('../../node_modules/bluebird/js/release/bluebird');
/**
* Gets the list of available media devices (Audio and Video) in the browser/app
* @class
* @classdesc Get Devices
* @return {Promise<ListDevices>}
* @example
* usecases.getDevices()
* .then((devices) => {
* console.log(devices.videoDevices); // [{label: 'Camera Front', id: *****}]
* console.log(devices.audioDevices); // [{label: 'Microphone', id: *****}]
* })
*/
var getDevices = function() {
return new Promise(function (resolve, reject) {
Janus.listDevices(function(devices) {
var audioDevices = [];
var videoDevices = [];
devices.forEach(function(device) {
var label = device.label;
if(label === null || label === undefined || label === "") label = "";
if(device.kind === 'audioinput') {
if(label === "") label = 'Audio ' + (audioDevices.length + 1);
audioDevices.push({
label: label,
id: device.deviceId
});
}
if(device.kind === 'videoinput') {
if(label === "") label = 'Camera ' + (videoDevices.length + 1);
videoDevices.push({
label: label,
id: device.deviceId
});
}
});
resolve({
audioDevices: audioDevices,
videoDevices: videoDevices
});
});
});
};
exports.getDevices = getDevices;