Skip to content

Instantly share code, notes, and snippets.

@gtk2k
Created September 12, 2018 04:22
Show Gist options
  • Save gtk2k/23fc3dba48c960a335f3e7d5072d5c8c to your computer and use it in GitHub Desktop.
Save gtk2k/23fc3dba48c960a335f3e7d5072d5c8c to your computer and use it in GitHub Desktop.
Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/prejs/MediaDevices.jsの修正案
var MediaDevices = [];
Module['preRun'].push(function () {
var enumerateMediaDevices = function () {
var getMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
if (!getMedia)
return;
function addDevice(device) {
var label = device.label;
label = label ? label : ("device #" + MediaDevices.length);
var device =
{
deviceId: device.deviceId,
deviceName: label,
refCount: 0,
video: null
};
MediaDevices.push(device);
}
// try MediaDevices.enumerateDevices, if available
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
if (typeof MediaStreamTrack == 'undefined' ||
typeof MediaStreamTrack.getSources == 'undefined') {
console.log("Media Devices cannot be enumerated on this browser.");
return;
}
function gotSources(sourceInfos) {
for (var i = 0; i !== sourceInfos.length; ++i) {
var sourceInfo = sourceInfos[i];
if (sourceInfo.kind === 'video')
addDevice(sourceInfo);
}
}
// MediaStreamTrack.getSources asynchronously returns a list of objects that identify devices
// and for privacy purposes the .label properties are not filled in unless the user has consented to
// device access through getUserMedia.
MediaStreamTrack.getSources(gotSources);
}
// List cameras and microphones.
navigator.mediaDevices.enumerateDevices().then(function (devices) {
devices.forEach(function (device) {
// device: kind, label, deviceId
if (device.kind == 'videoinput')
addDevice(device);
});
}).catch(function (err) {
console.log(err.name + ": " + error.message);
});
};
enumerateMediaDevices();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment