ngAfterViewInit()

in client/src/pages/capture/capture.ts [93:127]


  ngAfterViewInit() {
    let loadingPopUp: MatDialogRef<any> | undefined = this.sessionService.currentSession.currentModal;
    this.analyticsService.logPageView(this.router.url, 'Capture');
    if (!this.cameraPreview) {
      logger.error('Camera preview not found');
      if (loadingPopUp) {
        loadingPopUp.close();
      }
      this.router.navigateByUrl(AppRoutes.ImageSource, { replaceUrl: true });
      return;
    }
    if (!loadingPopUp) {
      loadingPopUp = this.dialog.open(LoadingPopUpComponent, { disableClose: true, panelClass: 'loading-popup' });
    }
    loadingPopUp.afterClosed().subscribe({
      next: () => this.modalIsForCameraStartup = false
    });
    this.cameraPreview.start().then(
      () => {
        logger.log('Camera started');
        if (loadingPopUp) {
          loadingPopUp.close();
        }
      },
      err => {
        logger.warn('Error starting camera', err);
        if (loadingPopUp) {
          loadingPopUp.close();
        }
        const errorMessage = this.i18n.getTranslation('startCameraError') || 'Unable to start camera, please try refreshing browser';
        const errorDialog = this.dialog.open(ErrorPopUpComponent, { data: { message: errorMessage }, panelClass: 'capture-camera-error' });
        errorDialog.afterClosed().subscribe({ complete: () => this.router.navigateByUrl(AppRoutes.ImageSource, { replaceUrl: true }) });
      }
    );
  }