Timeout in Barcodescanner

Hi,

I have implemented ionic native barcode scanner in my app. I am trying to put timeout period if there is any problem with qr code scan. If scan does not happen, camera should automatically go back to previous page and show an alert. Is there anyway we can cancel the scan? Can someone help in resolving this issue? Below code times out properly after 15 secs, but I get the alert only when i click hardware back button.

scanCode() {

this.qrCodeScan = new QRCodeScan();
const scanData = new Observable((observable) => {
  let scansub = this.barcodeScanner
    .scan(this.barcodeScannerOptions)
    .then(barcodeData => {
      this.scannedData = barcodeData;
   })
    .catch(err => {
      
      console.log("Error", err);
    })
})

   
// Call subscribe() to start listening for updates.
const qrCodeSubscription = scanData.subscribe({
  next(position) { console.log('subscribing now: ', position); },
  error(msg) { console.log('Error Getting Location: ', msg); }
});
// Stop listening for location after 10 seconds
setTimeout(() => { 
  console.log("timeout reached...unsubscribing now...");
  qrCodeSubscription.unsubscribe(); 
  this.alertMeetingCode('Having trouble scanning?');
}, 15000);

}