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