FS-10285: [verto.js] Device enumeration in Edge #resolve

This commit is contained in:
Anthony Minessale 2017-05-02 17:12:19 -05:00
parent d5b44cc12d
commit eafdc9d75b
6 changed files with 101 additions and 713 deletions

File diff suppressed because one or more lines are too long

View File

@ -1054,6 +1054,7 @@
video: check_video,
},
onsuccess: function(e) {
e.getTracks().forEach(function(track) {track.stop();});
console.info("media perm init complete");

View File

@ -2715,70 +2715,84 @@
var checkDevices = function(runtime) {
console.info("enumerating devices");
var aud_in = [], aud_out = [], vid = [];
var has_video = 0, has_audio = 0;
var Xstream;
if ((!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) && MediaStreamTrack.getSources) {
MediaStreamTrack.getSources(function (media_sources) {
for (var i = 0; i < media_sources.length; i++) {
function gotDevices(deviceInfos) {
// Handles being called several times to update labels. Preserve values.
for (var i = 0; i !== deviceInfos.length; ++i) {
var deviceInfo = deviceInfos[i];
var text = "";
if (media_sources[i].kind == 'video') {
vid.push(media_sources[i]);
} else {
aud_in.push(media_sources[i]);
}
console.log(deviceInfo);
console.log(deviceInfo.kind + ": " + deviceInfo.label + " id = " + deviceInfo.deviceId);
if (deviceInfo.kind === 'audioinput') {
text = deviceInfo.label || 'microphone ' + (aud_in.length + 1);
aud_in.push({id: deviceInfo.deviceId, kind: "audio_in", label: text});
} else if (deviceInfo.kind === 'audiooutput') {
text = deviceInfo.label || 'speaker ' + (aud_out.length + 1);
aud_out.push({id: deviceInfo.deviceId, kind: "audio_out", label: text});
} else if (deviceInfo.kind === 'videoinput') {
text = deviceInfo.label || 'camera ' + (vid.length + 1);
vid.push({id: deviceInfo.deviceId, kind: "video", label: text});
} else {
console.log('Some other kind of source/device: ', deviceInfo);
}
$.verto.videoDevices = vid;
$.verto.audioInDevices = aud_in;
console.info("Audio Devices", $.verto.audioInDevices);
console.info("Video Devices", $.verto.videoDevices);
runtime(true);
});
} else {
/* of course it's a totally different API CALL with different element names for the same exact thing */
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
console.log("enumerateDevices() not supported.");
return;
}
// List cameras and microphones.
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
console.log(device);
$.verto.videoDevices = vid;
$.verto.audioInDevices = aud_in;
$.verto.audioOutDevices = aud_out;
console.info("Audio IN Devices", $.verto.audioInDevices);
console.info("Audio Out Devices", $.verto.audioOutDevices);
console.info("Video Devices", $.verto.videoDevices);
console.log(device.kind + ": " + device.label +
" id = " + device.deviceId);
if (device.kind === "videoinput") {
vid.push({id: device.deviceId, kind: "video", label: device.label});
} else if (device.kind === "audioinput") {
aud_in.push({id: device.deviceId, kind: "audio_in", label: device.label});
} else if (device.kind === "audiooutput") {
aud_out.push({id: device.deviceId, kind: "audio_out", label: device.label});
}
});
if (Xstream) {
Xstream.getTracks().forEach(function(track) {track.stop();});
}
$.verto.videoDevices = vid;
$.verto.audioInDevices = aud_in;
$.verto.audioOutDevices = aud_out;
console.info("Audio IN Devices", $.verto.audioInDevices);
console.info("Audio Out Devices", $.verto.audioOutDevices);
console.info("Video Devices", $.verto.videoDevices);
runtime(true);
})
.catch(function(err) {
console.log(" Device Enumeration ERROR: " + err.name + ": " + err.message);
runtime(false);
});
if (runtime) {
runtime(true);
}
}
};
function handleError(error) {
console.log('device enumeration error: ', error);
if (runtime) runtime(false);
}
function checkTypes(devs) {
for (var i = 0; i !== devs.length; ++i) {
console.error(i, devs[i].kind);
if (devs[i].kind === 'audioinput') {
has_audio++;
} else if (devs[i].kind === 'videoinput') {
has_video++;
}
}
console.error("BLAH: ", has_audio, has_video);;
navigator.getUserMedia({ audio: (has_audio > 0 ? true : false), video: (has_video > 0 ? true : false)},
function(stream) {
Xstream = stream;
navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError);
},
function(err) {
console.log("The following error occurred: " + err.name);
}
);
}
navigator.mediaDevices.enumerateDevices().then(checkTypes).catch(handleError);
};
$.verto.refreshDevices = function(runtime) {
checkDevices(runtime);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1029,6 +1029,8 @@ function pop_select(id, cname, dft, onchange) {
function refresh_devices()
{
$.verto.refreshDevices();
$("#useshare").selectmenu({});
$("#useshare").selectmenu({});
$("#usemic").selectmenu({});