From 947bfb7a118f3743e50fa2dd3c83e75d38c9207a Mon Sep 17 00:00:00 2001 From: David Walsh Date: Wed, 14 Oct 2020 16:48:09 -0500 Subject: [PATCH] Fix #9043 - Ensure QR code scanner works --- .../modals/qr-scanner/qr-scanner.component.js | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ui/app/components/app/modals/qr-scanner/qr-scanner.component.js b/ui/app/components/app/modals/qr-scanner/qr-scanner.component.js index d78db3d14..330bd3fa4 100644 --- a/ui/app/components/app/modals/qr-scanner/qr-scanner.component.js +++ b/ui/app/components/app/modals/qr-scanner/qr-scanner.component.js @@ -104,15 +104,28 @@ export default class QrScanner extends Component { componentWillUnmount () { this.mounted = false clearTimeout(this.permissionChecker) - if (this.codeReader) { - this.codeReader.reset() + 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. + // Removing this teardown will create 2 video streams in Firefox, one + // of which the user will not be able to remove without refreshing the page. + this.teardownCodeReader(); 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 +175,7 @@ export default class QrScanner extends Component { stopAndClose = () => { if (this.codeReader) { - this.codeReader.reset() + this.teardownCodeReader(); } this.props.hideModal() } @@ -170,7 +183,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()