bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
568 stars 772 forks source link

How to stop camera after scan is completed #128

Closed VinayKumarSarda closed 6 years ago

VinayKumarSarda commented 6 years ago

Hi ,

The camera is still open after scan is successful. Please let me know how to stop camera after success scan.

VinayKumarSarda commented 6 years ago

Any help on how to stop camera after scan ??? ## helpneeded @team

VinayKumarSarda commented 6 years ago

HI Please need inputs as my camera is stilla ctive after scanning is done.

HeroCC commented 6 years ago

Does this work? https://github.com/bitpay/cordova-plugin-qrscanner#destroy

VinayKumarSarda commented 6 years ago

No @HeroCC

VinayKumarSarda commented 6 years ago

any inputs @HeroCC @team

VinayKumarSarda commented 6 years ago

Hi Team,

any inputs on how to close camera ?? in browser once the scan is success still camera is open.

VinayKumarSarda commented 6 years ago

any update @team @HeroCC

DavidRoebl commented 6 years ago

I'm having the same issues on Win10/Google Chrome. After successfully scanning the QR code, I hide the qrScanner (even destroy it for good measure) and then transition to the next screen. The app does not release the camera though, which is not expecte behaviour and therefore bad UX -- I don't want my users to think that I am spying on them when they use my app :(

scan(){
  let scanSub = this.qrScanner.scan().subscribe((text: string) => {
    //here: store scanned text
    this.qrScanner.hide();
    this.qrScanner.destroy();
    scanSub.unsubscribe();
    this.navCtrl.push(NextPage);
  });
}
bitjson commented 6 years ago

I'm not able to reproduce on any local devices, but PRs are certainly welcome. 2.6.0 also includes some big improvements which may help.

Closing this for now, but feel free to open a new issue with more specific details.

SimoneMSR commented 4 years ago

This is still an issue with version 3.0.1. Moreover, this piece of code causes the scanner.destroy function to raise an exception that cannot be catched

try {
    _this.qrScanner.destroy().then(function (status) {
        _this.hideCamera();
    }).catch(function (error) {
        _this.hideCamera();
    });
}
catch (error) {
    _this.hideCamera();
}

if I debug, the cordova.callbackFromNative function generates this error

{
    code: 6,
    name: "SCAN_CANCELED",
    _message: "Scan was canceled."
}

which does not really seem an error.

The errore arises from the cordova-plugin-qrscanner/src/browser/plugin.min.js The destroy function cannot procede after the cancelScan call because it calls the cancelNextScan which in turn throws the code error 6, with the following

cancelNextScan = function(sendError){
  window.clearTimeout(nextScan);
  nextScan = null;
  cancelNextScan = null;
  if(sendError){
    error(6); // SCAN_CANCELED
}
steinsleger commented 4 years ago

This is still an issue in current version (browser platform). Camera is not released after invoking .destroy() . Any ideas?

katringoogoo commented 4 years ago

yup, can confirm ... still an issue :/

justgeek commented 4 years ago

Have same issue on browser

donmb1 commented 3 years ago

+1

dotocan1 commented 2 years ago

Does anybody know how to route to another page after the scan is complete?

I call the destroy API but that just makes my screen black.

I am doing this in Vue by calling this.$router.push('/Home') but it doesn't work.

ewojjowe commented 2 years ago

+1