Replace DetectRTC package with standard web APIs (#7887)

The only web API that our usage of DetectRTC relied upon was
'enumerateDevices', which is supported and stable among all of our
supported browsers.

Note that the error handling here is a little... non-standard, and the
logic around how Firefox and Brave are handled should be justified, but
I've left the logic as-is for now to keep this PR small.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent 7471e2df02
commit e79d18de2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      package.json
  2. 33
      ui/lib/webcam-utils.js
  3. 5
      yarn.lock

@ -88,7 +88,6 @@
"deep-extend": "^0.5.1", "deep-extend": "^0.5.1",
"deep-freeze-strict": "1.1.1", "deep-freeze-strict": "1.1.1",
"detect-node": "^2.0.3", "detect-node": "^2.0.3",
"detectrtc": "^1.3.6",
"dnode": "^1.2.2", "dnode": "^1.2.2",
"end-of-stream": "^1.1.0", "end-of-stream": "^1.1.0",
"eth-block-tracker": "^4.4.2", "eth-block-tracker": "^4.4.2",

@ -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 && !hasWebcamPermissions)) {
environmentReady = false environmentReady = false
} }
resolve({ return {
permissions: DetectRTC.isWebsiteHasWebcamPermissions, permissions: hasWebcamPermissions,
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
} }
})
} }
} }

@ -8861,11 +8861,6 @@ detective@^5.0.2:
defined "^1.0.0" defined "^1.0.0"
minimist "^1.1.1" minimist "^1.1.1"
detectrtc@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/detectrtc/-/detectrtc-1.3.6.tgz#dabc0353981a3da7732de969071c08b6dddd5b59"
integrity sha1-2rwDU5gaPadzLelpBxwItt3dW1k=
dezalgo@^1.0.0: dezalgo@^1.0.0:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.3.tgz#7f742de066fc748bc8db820569dddce49bf0d456" resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.3.tgz#7f742de066fc748bc8db820569dddce49bf0d456"

Loading…
Cancel
Save