@ -1,34 +1,35 @@
'use strict'
'use strict'
import DetectRTC from 'detectrtc'
import { ENVIRONMENT _TYPE _POPUP , PLATFORM _BRAVE , PLATFORM _FIREFOX } from '../../app/scripts/lib/enums'
import { ENVIRONMENT _TYPE _POPUP , PLATFORM _BRAVE , PLATFORM _FIREFOX } from '../../app/scripts/lib/enums'
import { getEnvironmentType , getPlatform } from '../../app/scripts/lib/util'
import { getEnvironmentType , getPlatform } from '../../app/scripts/lib/util'
class WebcamUtils {
class WebcamUtils {
static checkStatus ( ) {
static async checkStatus ( ) {
return new Promise ( ( resolve , reject ) => {
const isPopup = getEnvironmentType ( window . location . href ) === ENVIRONMENT _TYPE _POPUP
const isPopup = getEnvironmentType ( window . location . href ) === ENVIRONMENT _TYPE _POPUP
const isFirefoxOrBrave = getPlatform ( ) === ( PLATFORM _FIREFOX || PLATFORM _BRAVE )
const isFirefoxOrBrave = getPlatform ( ) === ( PLATFORM _FIREFOX || PLATFORM _BRAVE )
try {
DetectRTC . load ( _ => {
const devices = await window . navigator . mediaDevices . enumerateDevices ( )
if ( DetectRTC . hasWebcam ) {
const webcams = devices . filter ( device => device . kind === 'videoinput' )
const hasWebcam = webcams . length > 0
// A non-empty-string label implies that the webcam has been granted permission, as
// otherwise the label is kept blank to prevent fingerprinting
const hasWebcamPermissions = webcams . some ( webcam => webcam . label && webcam . label . length > 0 )
if ( hasWebcam ) {
let environmentReady = true
let environmentReady = true
if ( ( isFirefoxOrBrave && isPopup ) || ( isPopup && ! DetectRTC . isWebsiteHasWebcamPermissions ) ) {
if ( ( isFirefoxOrBrave && isPopup ) || ( isPopup && ! h asWebcamPermissions) ) {
environmentReady = false
environmentReady = false
}
}
resolve ( {
return {
permissions : DetectRTC . isWebsiteHasWebcamPermissions ,
permissions : h asWebcamPermissions,
environmentReady ,
environmentReady ,
} )
} else {
reject ( { type : 'NO_WEBCAM_FOUND' } )
}
}
} )
} else {
} catch ( e ) {
const error = new Error ( 'No webcam found' )
reject ( { type : 'UNKNOWN_ERROR' } )
error . type = 'NO_WEBCAM_FOUND'
throw error
}
}
} )
}
}
}
}