62 lines
2.1 KiB
JavaScript
Vendored
62 lines
2.1 KiB
JavaScript
Vendored
|
|
function marhunPhotoCapturerDebugger() {
|
|
|
|
return {
|
|
|
|
scan: function () {
|
|
if ('mediaDevices' in navigator && navigator.mediaDevices.getUserMedia) {
|
|
|
|
// let camera_label = "HP TrueVision HD Camera (05c8:03d2)";
|
|
// let camera_label = "USB Camera (0c45:6366)";
|
|
let camera_label = "Doccamera (2b19:0200)";
|
|
|
|
const generateCameraListing = (cameras) => {
|
|
let title = "Available cameras: ";
|
|
|
|
let mapCameraWithDeviceId = (index, camera) => {
|
|
index = index + 1;
|
|
return `${index}. deviceLabel : ${camera.label}\n`;
|
|
}
|
|
|
|
let mapCameraWithGroupId = (index, camera) => {
|
|
index = index + 1;
|
|
return `${index}. groupId : ${camera.groupId}\n`;
|
|
}
|
|
|
|
let content = cameras.map((camera, index) => {
|
|
if(camera.deviceId !== ''){
|
|
return mapCameraWithDeviceId(index, camera);
|
|
}
|
|
|
|
if(camera.groupId !== ''){
|
|
return mapCameraWithGroupId(index, camera);
|
|
}
|
|
|
|
|
|
});
|
|
|
|
return `${title}\n${content.join('')}`;
|
|
};
|
|
|
|
navigator.mediaDevices.getUserMedia({audio: true, video: true});
|
|
|
|
navigator.mediaDevices.enumerateDevices()
|
|
.then(devices => devices.filter(x => x.kind === 'videoinput'))
|
|
.then(devices => devices.map(device => {
|
|
let altered_label = device.label.split(" ");
|
|
altered_label.splice(-1);
|
|
altered_label = altered_label.join(" ");
|
|
|
|
return {
|
|
label: altered_label,
|
|
deviceId: device.deviceId,
|
|
};
|
|
}))
|
|
.then(devices => alert(generateCameraListing(devices)))
|
|
}
|
|
|
|
return true;
|
|
},
|
|
}
|
|
}
|