2018-08-01 00:30:40 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
import DetectRTC from 'detectrtc'
|
2020-01-09 04:34:58 +01:00
|
|
|
import { ENVIRONMENT_TYPE_POPUP, PLATFORM_BRAVE, PLATFORM_FIREFOX } from '../../app/scripts/lib/enums'
|
|
|
|
import { getEnvironmentType, getPlatform } from '../../app/scripts/lib/util'
|
2018-08-01 00:30:40 +02:00
|
|
|
|
|
|
|
class WebcamUtils {
|
|
|
|
|
|
|
|
static checkStatus () {
|
|
|
|
return new Promise((resolve, reject) => {
|
2018-08-04 01:36:01 +02:00
|
|
|
const isPopup = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP
|
2018-08-08 09:00:39 +02:00
|
|
|
const isFirefoxOrBrave = getPlatform() === (PLATFORM_FIREFOX || PLATFORM_BRAVE)
|
2018-08-04 01:36:01 +02:00
|
|
|
try {
|
|
|
|
DetectRTC.load(_ => {
|
|
|
|
if (DetectRTC.hasWebcam) {
|
2019-07-31 22:17:11 +02:00
|
|
|
let environmentReady = true
|
|
|
|
if ((isFirefoxOrBrave && isPopup) || (isPopup && !DetectRTC.isWebsiteHasWebcamPermissions)) {
|
|
|
|
environmentReady = false
|
|
|
|
}
|
|
|
|
resolve({
|
|
|
|
permissions: DetectRTC.isWebsiteHasWebcamPermissions,
|
|
|
|
environmentReady,
|
|
|
|
})
|
2018-08-04 01:36:01 +02:00
|
|
|
} else {
|
2019-12-03 21:50:55 +01:00
|
|
|
reject({ type: 'NO_WEBCAM_FOUND' })
|
2018-08-04 01:36:01 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} catch (e) {
|
2019-12-03 21:50:55 +01:00
|
|
|
reject({ type: 'UNKNOWN_ERROR' })
|
2018-08-04 01:36:01 +02:00
|
|
|
}
|
2018-08-01 00:30:40 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export default WebcamUtils
|