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

No scanning on mobile browser #89

Closed Naki21 closed 6 years ago

Naki21 commented 7 years ago

I'm back. I am having issues getting the scanner to work on my mobile phone in the browser. I can't seem to get the scanner working on my phone when I have it deployed on github. I have got it to work from the browser but this too is very unreliable(Renering black screen on QRScanner.show() randomly, not scanning consistently). It also seems to crash when the camera is open and 'scanning' for too long. I have tried setting the scan interval also to no avail. I don't know what is the issue and I don't really have an idea where to start. Any ideas?

globophobe commented 7 years ago

I'm not a developer, so don't trust everything I say. Anyway, black screens can mean there was no data from the camera. If the camera crashes, this is a further indication something could be wrong with the camera.

If this is the case, it would be nice if the scanner could warn, for example, that there is no data, etc.

Taking too long to scan can be the result of many things, including ambient light.

One way to increase scanning speed, at the cost of CPU time, is an adaptive threshold, but this could be difficult on mobile.

Naki21 commented 7 years ago

I dont think it is the camera. Again i have it working locally on the pc browser and I have used the mobile browser with other scanning android and web apps so the camera shouldn't be the issue. I'm thinking it may be something to do with how I'm calling the code and maybe there is a loop I'm not ending which is causing using all the memory and then causing the crash. Also on a semi-related note. Does anyone familiar with the code know if any of these functions return promises? Are they accessible or are they scoped to the internals of the package itself?

bitjson commented 7 years ago

@Naki21 on what platforms/devices/versions are you experiencing issues? Could you provide a test case to reproduce? (a GitHub repo is best)

amjadm61 commented 6 years ago

I'm facing the same issue. It is working perfectly on desktop browser. But not working on mobile browser (tried chrome and firefox). I'm getting this error message when I'm trying to scan a qr code from mobile browser: Error is Object {name: "CAMERA_UNAVAILABLE", code: 5, _message: "The camera is unavailable."} qrscanner

This my code:


startScan() {
    console.log('started qr code scanning');
    // Optionally request the permission early
    this.qrScanner.prepare()
      .then((status: QRScannerStatus) => {
        if (status.authorized) {
          // camera permission was granted
          console.log('authorized');
          // start scanning
          let scanSub = this.qrScanner.scan().subscribe((text: string) => {
            console.log('Scanned something', text);
            this.qrScanner.hide(); // hide camera preview
            scanSub.unsubscribe(); // stop scanning
          });

          // show camera preview
          this.qrScanner.show();

          // wait for user to scan something, then the observable callback will be called

        } else if (status.denied) {
          // camera permission was permanently denied
          // you must use QRScanner.openSettings() method to guide the user to the settings page
          // then they can grant the permission from there
          console.log('denied');
        } else {
          // permission was denied, but not permanently. You can ask for permission again at a later time.
          console.log('temperorly denied');

        }
      })
      .catch((e: any) => console.log('Error is', e));
  }
bitjson commented 6 years ago

@amjadm61 – the browser platform of the plugin should not work on mobile browsers. (Even if performance was acceptable, few mobile browsers support WebRTC.)

You'll need to use the cordova version of the plugin for the platform in question (e.g. the iOS, Android, or Windows platform). You can test it by building the cordova app.

blumk commented 6 years ago

@bitjson All major browser support WebRTC, see Can I use WebRTC Apple updated Safari on Sept 19, 2017 with iOS 11.

Would be great to use this plugin within a PWA.

bitjson commented 6 years ago

I think the original question here has been answered, so I'm going to close this issue.

For any future readers, please feel free to open a new issue or send a PR.