1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #9608 from darkwing/9043-camera

Fix #9043 - Ensure QR code scanner works
This commit is contained in:
David Walsh 2020-10-16 09:15:00 -05:00 committed by GitHub
commit b1f7fbf343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -104,15 +104,29 @@ export default class QrScanner extends Component {
componentWillUnmount () {
this.mounted = false
clearTimeout(this.permissionChecker)
this.teardownCodeReader()
}
teardownCodeReader () {
if (this.codeReader) {
this.codeReader.reset()
this.codeReader.stop()
this.codeReader = null
}
}
initCamera = async () => {
// The `decodeFromInputVideoDevice` call prompts the browser to show
// the user the camera permission request. We must then call it again
// once we receive permission so that the video displays.
// It's important to prevent this codeReader from being created twice;
// Firefox otherwise starts 2 video streams, one of which cannot be stopped
if (!this.codeReader) {
this.codeReader = new BrowserQRCodeReader()
}
try {
await this.codeReader.getVideoInputDevices()
this.checkPermissions()
const content = await this.codeReader.decodeFromInputVideoDevice(undefined, 'video')
const result = this.parseContent(content.text)
if (!this.mounted) {
@ -162,7 +176,7 @@ export default class QrScanner extends Component {
stopAndClose = () => {
if (this.codeReader) {
this.codeReader.reset()
this.teardownCodeReader()
}
this.props.hideModal()
}
@ -170,7 +184,7 @@ export default class QrScanner extends Component {
tryAgain = () => {
clearTimeout(this.permissionChecker)
if (this.codeReader) {
this.codeReader.reset()
this.teardownCodeReader()
}
this.setState(this.getInitialState(), () => {
this.checkEnvironment()