1
0
Fork 0

Make QR scanner deinit properly.

This commit is contained in:
Kitteh 2021-05-25 12:41:02 +01:00
parent 64e3e9911b
commit bd36e9f5ea

View file

@ -16,6 +16,7 @@ export class QRScanner extends Component<QRScannerProps, unknown> {
videoElement = createRef<HTMLVideoElement>();
stream: MediaStream;
qrScanner: QrScanner;
componentDidMount(): void {
void navigator.mediaDevices
@ -33,16 +34,15 @@ export class QRScanner extends Component<QRScannerProps, unknown> {
if (lastSeenValue == value) return;
this.props.onScan(value);
});
this.qrScanner = qrScanner;
void qrScanner.start();
});
}
componentWillUnmount(): void {
try {
this.stream.getTracks().forEach(function (track) {
track.stop();
});
this.qrScanner.destroy();
} catch (_) {
() => {};
// Do Nothing
}
}