ngx-scanner icon indicating copy to clipboard operation
ngx-scanner copied to clipboard

Avoid setting a device during auto-start.

Open BryanManfrinTS opened this issue 5 years ago • 11 comments

Describe the bug When using the camera, I get an error saying: 'Avoid setting a device during auto-start.'

To Reproduce Steps to reproduce the behavior:

  1. Open a page using the camera and the tag.

Expected behavior The feedback of the camera should appear

Desktop (please complete the following information):

  • OS: MacOs Cataline 10.15.5
  • Browser Chrome
  • Version 84.0.4147.135

Additional context According to source code, we are setting the device during auto start:

private autostartScanner(devices: MediaDeviceInfo[]) {

    const matcher = ({ label }) => /back|trás|rear|traseira|environment|ambiente/gi.test(label);

    // select the rear camera by default, otherwise take the last camera.
    const device = devices.find(matcher) || devices.pop();

    if (!device) {
      throw new Error('Impossible to autostart, no input devices available.');
    }

    this.device = device; // HERE!
    // @note when listening to this change, callback code will sometimes run before the previous line.
    this.deviceChange.emit(device);

    this.isAutostarting = false;
    this.autostarted.next();
  }

IMPORTANT: This might help you debug my issue: I had ^3.0.0 as a package dependency. while facing the issue I was on v 3.0.1 with your latest commit. Fixing version to 3.0.0 solved my issue.

BryanManfrinTS avatar Aug 20 '20 06:08 BryanManfrinTS

Have same issue on 3.0.1, 3.0.0. Going back to 2.0.1 solved issue for me.

andrzejfigula avatar Sep 03 '20 13:09 andrzejfigula

Reverting to version 3.0.0 fixed the issue for me too.

PadraigGalvin avatar Sep 09 '20 18:09 PadraigGalvin

  • version 3.0.1
  • Windows 10 Laptop
  • Browser: Chrome 85.0.4183.102

I had the same problem. Resolved by following the demo app structure. The demo gives nice guidelines how to efficiently load the camera.

bvassilis avatar Sep 10 '20 12:09 bvassilis

  • version 3.0.1
  • Windows 10 Laptop
  • Browser: Chrome 85.0.4183.102

I had the same problem. Resolved by following the demo app structure. The demo gives nice guidelines how to efficiently load the camera.

Even use only the selector i'm getting this warning and the camera is not showing. What did you do?

lsrsilva avatar Sep 11 '20 21:09 lsrsilva

Same issue. It's not displaying any video for versions 3.0.0. nor 3.0.1. Luckily, 2.0.1. version works for me. Please notify when this bug gets fixed. Thanks!

gerardcastell avatar Sep 15 '20 10:09 gerardcastell

Same here, not working and get the same issu with 3.0.1 and Angular 10

kzay avatar Sep 24 '20 21:09 kzay

I've got this working via

html:

<zxing-scanner
          #webScanner
          *ngIf="scanning"
          [(device)]="currentDevice"
          (camerasFound)="onCamerasFound($event)"
          (scanSuccess)="webScanFoundItem($event)"
          [tryHarder]="true">        
        </zxing-scanner>

and in the ts code

  availableDevices: MediaDeviceInfo[];
  currentDevice: MediaDeviceInfo = null;

  onCamerasFound(devices: MediaDeviceInfo[]): void {
    this.availableDevices = devices;

    if (this.availableDevices && this.availableDevices.length > 0) {
      this.currentDevice = this.availableDevices[0];
    }
  }

coffeymatt avatar Sep 30 '20 15:09 coffeymatt

Got the same issue. @coffeymatt Your workaround works indeed, thank you. The warning appears in the console nontheless.

KlausHans avatar Oct 07 '20 13:10 KlausHans

This should be solved in the latest version. But, of course, if you do try to set a device during autostart it will still show this warning; for manually handling devices you should disable autostart with autostart="false" so the scanner doesn't try to boot up and ask for permissions, get media devices, auto start scanning for the first device available, etc.

odahcam avatar Oct 26 '20 19:10 odahcam

If you set the autostart="false" how do you start once you have set the device? All I get is this warning:

Feature 'autostart' disabled. Permissions and devices recovery has to be run manually.

The permissions have been requested and accepted, what is devices recorvery?

r3plica avatar Apr 01 '21 16:04 r3plica

I've got this working via

html:

<zxing-scanner
          #webScanner
          *ngIf="scanning"
          [(device)]="currentDevice"
          (camerasFound)="onCamerasFound($event)"
          (scanSuccess)="webScanFoundItem($event)"
          [tryHarder]="true">        
        </zxing-scanner>

and in the ts code

  availableDevices: MediaDeviceInfo[];
  currentDevice: MediaDeviceInfo = null;

  onCamerasFound(devices: MediaDeviceInfo[]): void {
    this.availableDevices = devices;

    if (this.availableDevices && this.availableDevices.length > 0) {
      this.currentDevice = this.availableDevices[0];
    }
  }

@coffeymatt which angular and ngx package version are you using?

Daveric avatar Feb 05 '22 00:02 Daveric