Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config input break the scanner events #60

Open
etsraphael opened this issue Apr 22, 2024 · 2 comments
Open

Config input break the scanner events #60

etsraphael opened this issue Apr 22, 2024 · 2 comments

Comments

@etsraphael
Copy link

I'm using the following template to display the QR code scanner:

<ngx-scanner-qrcode [config]="scannerConfig" #action="scanner"></ngx-scanner-qrcode>

TypeScript Configuration:

The scanner configuration is set up as follows, but the scanner does not trigger the event when the constraints are commented out:

scannerConfig: ScannerQRCodeConfig = {
  // TODO: This has to be uncommented to keep the scanner working
  // constraints: {
  //   video: {
  //     width: {
  //       ideal: 100
  //     },
  //     height: {
  //       ideal: 100
  //     }
  //   }
  // }
};

Event Subscription:

Here's how I'm subscribing to the scanner events:

ngOnInit(): void {
  navigator.mediaDevices
    ?.getUserMedia({ video: true, audio: false })
    .then((stream: MediaStream) => {
      this.scanner.start();

      this.scanner?.event.subscribe((result: ScannerQRCodeResult[]) => {
        // TODO: Redirect to the page with the scanned QR code
        console.log('Scanned QR code:', result);
        this.scanner?.stop();
      })

    })
    .catch((err) => {
      console.error('Error on get user media:', err);
    });
}

Expected Behavior:

The scanner should trigger the event and log the scanned QR code, regardless of whether the video constraints are specified in the configuration.

Actual Behavior:

The event does not trigger unless the video constraints in the configuration are uncommented.

Steps to Reproduce:

  1. Comment out the constraints block in the scannerConfig.
  2. Scan a QR code.
  3. Observe that no events are triggered.

Additional Information:

  • It seems like the scanner configuration requires explicit video constraints to function. However, I need flexibility in handling different devices and conditions where predefined constraints might not be ideal.

Potential Solutions or Suggestions:

  • Is there a way to set default constraints that are more adaptive to different devices?
  • Could this issue be related to browser permissions or media device compatibility?
@Nathanael-Rayapin
Copy link

Hey :)

I'm not reproducing your problem right now. No matter if the config is empty or not, I manage to log in the subscribe..
Can you provide more information about your project conf ?

@etsraphael
Copy link
Author

etsraphael commented Apr 23, 2024

Thanks @Nathanael-Rayapin for your quick response. After a couple of tests, I found out that the QR code is working. But no matter what, once the constraints are added it's not possible anymore to scan a bar code.

I will leave this topic open to the owner of this repository because it should be noticed somewhere or upgraded. But for me it's fixed, because I only need a QR code.

Thanks again, really appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants