Как я могу заставить приложение запрашивать разрешение у пользователя? - PullRequest
1 голос
/ 07 мая 2019

Мне нужно запросить разрешение на включение камеры в угловое веб-приложение.Когда я переключаю cameraId, чтобы начать новый вызов (с другой камерой), он отлично работает в Windows, но в Andoroid у меня возникает эта ошибка: Media acces NotReadableError: Не удалось запустить источник видео.Это кажется из-за разрешений камеры.

Спасибо

  switchCamera() {
    for (let id of this.ids) {
      if (id != this.cameraId) {
        this.cameraId = id;
        break;
      }
    }
    this.dossierService.cameraId = this.cameraId;
    this.dossierService.fromClient = true;
    this.router.navigate(['videoperizia']);
  }

. Этот метод сохраняет новый Id камеры внутри this.dossierService.cameraId, затем я перехожу к другим компонентам "videoperizia".Поэтому, если VideoPerizia имеет fromClient == true, он возвращается к Client.component (этот код) и начинает новый вызов с новым идентификатором:

        ngOnInit() {
    this.canvas = <HTMLCanvasElement>document.getElementById('canvas');
    if (this.dossierService.cameraId) {
      this.startCall(this.dossierService.cameraId);
    }
  }


startCall(cameraId?: string) {
        try {
          this.agoraService.client.getCameras(_ => {
            if (_.length > 1) {
              this.enableSwitchCamera = true   
              this.cameraId = cameraId || _[1].deviceId;
              this.ids = _.map(device => device.deviceId);
            }
            else {
              this.enableSwitchCamera = false;
              this.cameraId = _[0].deviceId;
            }
        this.joinClient();
      })
    } catch (error) {
      this.toastr.error("errore nell'acquisizione video")
    }
  }

присоединиться к клиенту:

 joinClient() {

        this.agoraService.client.join(null, this.dossierId, null, (uid) => {
          this.streamSpec = { streamID: uid, audio: true, cameraId: this.cameraId, microphoneId: null, video: true, screen: false }
          this.localStream = this.agoraService.createStream(this.streamSpec);
          this.localStream.setVideoProfile('720p_3');
          this.subscribeToStreams();
          this.callIsStarted = true;
        });
      }

когда я начинаю вызов с самого начала, он отлично работает и на Android, но когда я переключаюсь, он работает только на Windows и MacOs

явно, когда я перехожу к «videoperizia», мой компонент проходит через ngOnDestroy:

  ngOnDestroy() {
    if (this.localStream) {
      this.localStream.stop();
      this.agoraService.client.unpublish(this.localStream);
    }    
    this.agoraService.client.leave();
  }

html:

<div id="agora_local_client" [style.height.px]="screenHeight" [style.width.px]="screenWidth" #clientVideo>  
</div>

затем @ViewChild внутри ts:

 @ViewChild("clientVideo") clientVideo
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...