@ -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 {
const devices = await window . navigator . mediaDevices . enumerateDevices ( )
DetectRTC . load ( _ => {
const webcams = devices . filter ( device => device . kind === 'videoinput' )
if ( DetectRTC . hasWebcam ) {
const hasWebcam = webcams . length > 0
let environmentReady = true
// A non-empty-string label implies that the webcam has been granted permission, as
if ( ( isFirefoxOrBrave && isPopup ) || ( isPopup && ! DetectRTC . isWebsiteHasWebcamPermissions ) ) {
// otherwise the label is kept blank to prevent fingerprinting
environmentReady = false
const hasWebcamPermissions = webcams . some ( webcam => webcam . label && webcam . label . length > 0 )
}
resolve ( {
if ( hasWebcam ) {
permissions : DetectRTC . isWebsiteHasWebcamPermissions ,
let environmentReady = true
environmentReady ,
if ( ( isFirefoxOrBrave && isPopup ) || ( isPopup && ! hasWebcamPermissions ) ) {
} )
environmentReady = false
} else {
}
reject ( { type : 'NO_WEBCAM_FOUND' } )
return {
}
permissions : hasWebcamPermissions ,
} )
environmentReady ,
} catch ( e ) {
reject ( { type : 'UNKNOWN_ERROR' } )
}
}
} )
} else {
const error = new Error ( 'No webcam found' )
error . type = 'NO_WEBCAM_FOUND'
throw error
}
}
}
}
}