You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
4 years ago
|
'use strict';
|
||
6 years ago
|
|
||
4 years ago
|
import {
|
||
|
ENVIRONMENT_TYPE_POPUP,
|
||
|
PLATFORM_BRAVE,
|
||
|
PLATFORM_FIREFOX,
|
||
4 years ago
|
} from '../../../shared/constants/app';
|
||
|
import { getEnvironmentType, getPlatform } from '../../../app/scripts/lib/util';
|
||
6 years ago
|
|
||
|
class WebcamUtils {
|
||
4 years ago
|
static async checkStatus() {
|
||
4 years ago
|
const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP;
|
||
4 years ago
|
const isFirefoxOrBrave =
|
||
4 years ago
|
getPlatform() === (PLATFORM_FIREFOX || PLATFORM_BRAVE);
|
||
5 years ago
|
|
||
4 years ago
|
const devices = await window.navigator.mediaDevices.enumerateDevices();
|
||
|
const webcams = devices.filter((device) => device.kind === 'videoinput');
|
||
|
const hasWebcam = webcams.length > 0;
|
||
5 years ago
|
// A non-empty-string label implies that the webcam has been granted permission, as
|
||
|
// otherwise the label is kept blank to prevent fingerprinting
|
||
4 years ago
|
const hasWebcamPermissions = webcams.some(
|
||
|
(webcam) => webcam.label && webcam.label.length > 0,
|
||
4 years ago
|
);
|
||
5 years ago
|
|
||
|
if (hasWebcam) {
|
||
4 years ago
|
let environmentReady = true;
|
||
5 years ago
|
if ((isFirefoxOrBrave && isPopup) || (isPopup && !hasWebcamPermissions)) {
|
||
4 years ago
|
environmentReady = false;
|
||
5 years ago
|
}
|
||
|
return {
|
||
|
permissions: hasWebcamPermissions,
|
||
|
environmentReady,
|
||
4 years ago
|
};
|
||
5 years ago
|
}
|
||
4 years ago
|
const error = new Error('No webcam found');
|
||
|
error.type = 'NO_WEBCAM_FOUND';
|
||
|
throw error;
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
export default WebcamUtils;
|