|
@ -1,7 +1,7 @@ |
|
|
// @flow
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
import React, { Component } from 'react' |
|
|
import React, { Component } from 'react' |
|
|
import QrCode from 'qrcode-reader' |
|
|
import jsQR from 'jsqr' |
|
|
import logger from 'logger' |
|
|
import logger from 'logger' |
|
|
|
|
|
|
|
|
export default class QRCodeCameraPickerCanvas extends Component< |
|
|
export default class QRCodeCameraPickerCanvas extends Component< |
|
@ -60,12 +60,6 @@ export default class QRCodeCameraPickerCanvas extends Component< |
|
|
if (!getUserMedia) { |
|
|
if (!getUserMedia) { |
|
|
this.setState({ message: 'Incompatible browser' }) // eslint-disable-line
|
|
|
this.setState({ message: 'Incompatible browser' }) // eslint-disable-line
|
|
|
} else { |
|
|
} else { |
|
|
const qr = new QrCode() |
|
|
|
|
|
qr.callback = (err, value) => { |
|
|
|
|
|
if (!err) { |
|
|
|
|
|
this.props.onPick(value.result) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
getUserMedia({ |
|
|
getUserMedia({ |
|
|
video: { facingMode: 'environment' }, |
|
|
video: { facingMode: 'environment' }, |
|
|
}) |
|
|
}) |
|
@ -146,7 +140,12 @@ export default class QRCodeCameraPickerCanvas extends Component< |
|
|
|
|
|
|
|
|
if (t - lastCheck >= intervalCheck) { |
|
|
if (t - lastCheck >= intervalCheck) { |
|
|
lastCheck = t |
|
|
lastCheck = t |
|
|
qr.decode(ctxMain.getImageData(0, 0, width, height)) |
|
|
const imageData = ctxMain.getImageData(0, 0, width, height) |
|
|
|
|
|
const code = jsQR(imageData.data, width, height) |
|
|
|
|
|
|
|
|
|
|
|
if (code && code.data) { |
|
|
|
|
|
this.props.onPick(code.data) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
raf = requestAnimationFrame(loop) |
|
|
raf = requestAnimationFrame(loop) |
|
|