Skip to content

Commit

Permalink
Preventing to duplicate devices. Supporting JSON-stringify as well.
Browse files Browse the repository at this point in the history
JSON.stringify( DetectRTC.videoInputDevices );
  • Loading branch information
muaz-khan committed Nov 2, 2016
1 parent 2945317 commit 65a450d
Show file tree
Hide file tree
Showing 5 changed files with 518 additions and 547 deletions.
33 changes: 16 additions & 17 deletions DetectRTC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-10-12 6:16:40 AM UTC
// Last time updated: 2016-11-02 8:56:06 AM UTC

// Latest file can be found here: https://cdn.webrtc-experiment.com/DetectRTC.js

Expand Down Expand Up @@ -672,11 +672,22 @@
audioOutputDevices = [];
videoInputDevices = [];

// to prevent duplication
var alreadyUsedDevices = {};

navigator.enumerateDevices(function(devices) {
devices.forEach(function(_device) {
var device = {};
for (var d in _device) {
device[d] = _device[d];
try {
if (typeof _device[d] !== 'function') {
device[d] = _device[d];
}
} catch (e) {}
}

if (alreadyUsedDevices[device.deviceId]) {
return;
}

// if it is MediaStreamTrack.getSources
Expand All @@ -688,17 +699,6 @@
device.kind = 'videoinput';
}

var skip;
MediaDevices.forEach(function(d) {
if (d.id === device.id && d.kind === device.kind) {
skip = true;
}
});

if (skip) {
return;
}

if (!device.deviceId) {
device.deviceId = device.id;
}
Expand Down Expand Up @@ -749,10 +749,9 @@
}

// there is no 'videoouput' in the spec.
MediaDevices.push(device);

if (MediaDevices.indexOf(device) === -1) {
MediaDevices.push(device);
}
alreadyUsedDevices[device.deviceId] = device;
});

if (typeof DetectRTC !== 'undefined') {
Expand Down Expand Up @@ -837,7 +836,7 @@
if (item in window) {
webAudio.isSupported = true;

if ('createMediaStreamSource' in window[item].prototype) {
if (window[item] && 'createMediaStreamSource' in window[item].prototype) {
webAudio.isCreateMediaStreamSourceSupported = true;
}
}
Expand Down
Loading

0 comments on commit 65a450d

Please sign in to comment.