aboutsummaryrefslogtreecommitdiffstats
path: root/ui/lib/webcam-utils.js
blob: e4261dfbc39f573c31efe9e9ad937a265b832bf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'

import DetectRTC from 'detectrtc'
const { ENVIRONMENT_TYPE_POPUP } = require('../../app/scripts/lib/enums')
const { getEnvironmentType } = require('../../app/scripts/lib/util')

class WebcamUtils {

  static checkStatus () {
    return new Promise((resolve, reject) => {
      const isPopup = getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_POPUP
      const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
      const isBrave = !!window.chrome.ipcRenderer
      const isFirefoxOrBrave = isFirefox || isBrave
      try {
        reject({type: 'NO_WEBCAM_FOUND'})
        // 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