ngx-webcam how to identify if user allowed webcam permission or not - Angular 4+

1.8k Views Asked by At

I'm having issue with ngx-webcam plugin in Angular4+, as i'm using this plugin to capture images in my application but when user doesn't allow permission of using webcam then I should make a change from capturing to upload a image from computer or mobile.

In this ngx-webcam plugin we do have, to turn on/off webcam but what i need is to identify if user gave permission or not to use webcame for capturing image.

I'm trying to get this resolved and searched a lot but couldn't find anything relevant to find whether a user allowed

2

There are 2 best solutions below

0
On

Display errors and then take action accordingly

0
On

  public handleInitError(error: WebcamInitError): void {
    if (error.mediaStreamError && error.mediaStreamError.name === 'NotAllowedError') {
      this.camPermission = true;
      console.warn('Camera access was not allowed by user!');
    }
  }
<webcam (initError)="handleInitError($event)"></webcam>