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:
commit
b1f7fbf343
@ -104,15 +104,29 @@ export default class QrScanner extends Component {
|
|||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.mounted = false
|
this.mounted = false
|
||||||
clearTimeout(this.permissionChecker)
|
clearTimeout(this.permissionChecker)
|
||||||
|
this.teardownCodeReader()
|
||||||
|
}
|
||||||
|
|
||||||
|
teardownCodeReader () {
|
||||||
if (this.codeReader) {
|
if (this.codeReader) {
|
||||||
this.codeReader.reset()
|
this.codeReader.reset()
|
||||||
|
this.codeReader.stop()
|
||||||
|
this.codeReader = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initCamera = async () => {
|
initCamera = async () => {
|
||||||
this.codeReader = new BrowserQRCodeReader()
|
// 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 {
|
try {
|
||||||
await this.codeReader.getVideoInputDevices()
|
await this.codeReader.getVideoInputDevices()
|
||||||
|
this.checkPermissions()
|
||||||
const content = await this.codeReader.decodeFromInputVideoDevice(undefined, 'video')
|
const content = await this.codeReader.decodeFromInputVideoDevice(undefined, 'video')
|
||||||
const result = this.parseContent(content.text)
|
const result = this.parseContent(content.text)
|
||||||
if (!this.mounted) {
|
if (!this.mounted) {
|
||||||
@ -162,7 +176,7 @@ export default class QrScanner extends Component {
|
|||||||
|
|
||||||
stopAndClose = () => {
|
stopAndClose = () => {
|
||||||
if (this.codeReader) {
|
if (this.codeReader) {
|
||||||
this.codeReader.reset()
|
this.teardownCodeReader()
|
||||||
}
|
}
|
||||||
this.props.hideModal()
|
this.props.hideModal()
|
||||||
}
|
}
|
||||||
@ -170,7 +184,7 @@ export default class QrScanner extends Component {
|
|||||||
tryAgain = () => {
|
tryAgain = () => {
|
||||||
clearTimeout(this.permissionChecker)
|
clearTimeout(this.permissionChecker)
|
||||||
if (this.codeReader) {
|
if (this.codeReader) {
|
||||||
this.codeReader.reset()
|
this.teardownCodeReader()
|
||||||
}
|
}
|
||||||
this.setState(this.getInitialState(), () => {
|
this.setState(this.getInitialState(), () => {
|
||||||
this.checkEnvironment()
|
this.checkEnvironment()
|
||||||
|
Loading…
Reference in New Issue
Block a user