1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var Janus = require('../externals/janus.nojquery');
var Promise = require('bluebird/js/release/bluebird');
var getDevices = function(config) {
if (config == null) config = { audio: true, video: true };
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
});
}, config);
});
};
exports.getDevices = getDevices;