Я использую Angular 8 для доступа к веб-камере через браузер.
startCamera() {
if (!!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) {
navigator.mediaDevices.getUserMedia(this.constraints).then(this.attachVideo.bind(this)).catch(this.handleError);
} else {
alert('Sorry, camera not available.');
}
}
handleError(error) {
console.log('Error: ', error);
}
attachVideo(stream) {
this.renderer.setProperty(this.videoElement.nativeElement, 'srcObject', stream);
this.renderer.listen(this.videoElement.nativeElement, 'play', (event) => {
this.videoHeight = this.videoElement.nativeElement.videoHeight;
this.videoWidth = this.videoElement.nativeElement.videoWidth;
});
}
capture() {
this.renderer.setProperty(this.canvas.nativeElement, 'width', this.videoWidth);
this.renderer.setProperty(this.canvas.nativeElement, 'height', this.videoHeight);
this.canvas.nativeElement.getContext('2d').drawImage(this.videoElement.nativeElement, 0, 0);
var data_uri = this.canvas.nativeElement.toDataURL("image/png")
this.visitor.photoFileName = data_uri
}
, когда я запускаю свое приложение на локальном хосте, оно работает, а через Http - нет. Есть ли способ или библиотека, чтобы сделать эту работу?