Make QR scanner deinit properly.
This commit is contained in:
parent
64e3e9911b
commit
bd36e9f5ea
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue