1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 11:28:51 +01:00
metamask-extension/ui/lib/webcam-utils.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict'
import DetectRTC from 'detectrtc'
const { ENVIRONMENT_TYPE_POPUP } = require('../../app/scripts/lib/enums')
2018-08-08 09:00:39 +02:00
const { getEnvironmentType, getPlatform } = require('../../app/scripts/lib/util')
const { PLATFORM_BRAVE, PLATFORM_FIREFOX } = require('../../app/scripts/lib/enums')
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) {
let environmentReady = true
if ((isFirefoxOrBrave && isPopup) || (isPopup && !DetectRTC.isWebsiteHasWebcamPermissions)) {
environmentReady = false
}
resolve({
permissions: DetectRTC.isWebsiteHasWebcamPermissions,
environmentReady,
})
} else {
reject({type: 'NO_WEBCAM_FOUND'})
}
})
} catch (e) {
reject({type: 'UNKNOWN_ERROR'})
}
})
}
}
module.exports = WebcamUtils