Commit c53e567c authored by Hasini Piumika Alwis's avatar Hasini Piumika Alwis

component.ts

parent 967d2d2e
import { Output } from '@angular/core';
import { EventEmitter } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ChartDataSets, ChartType, plugins } from 'chart.js';
import { Color, Label } from 'ng2-charts';
import { WebcamImage, WebcamInitError, WebcamUtil } from 'ngx-webcam';
import { Observable, Subject } from 'rxjs';
@Component({
selector: 'app-facial-expression',
templateUrl: './facial-expression.component.html',
styleUrls: ['./facial-expression.component.css'],
})
export class FacialExpressionComponent implements OnInit {
@Output() getPicture = new EventEmitter<WebcamImage>();
showWebcam = true;
isCameraExist = true;
errors: WebcamInitError[] = [];
// webcam snapshot trigger
private trigger: Subject<void> = new Subject<void>();
private nextWebcam: Subject<boolean | string> = new Subject<boolean | string>();
constructor() { }
ngOnInit(): void {
WebcamUtil.getAvailableVideoInputs()
.then((mediaDevices: MediaDeviceInfo[]) => {
this.isCameraExist = mediaDevices && mediaDevices.length > 0;
});
}
takeSnapshot(): void {
this.trigger.next();
}
onOffWebCame() {
this.showWebcam = !this.showWebcam;
}
handleInitError(error: WebcamInitError) {
this.errors.push(error);
}
changeWebCame(directionOrDeviceId: boolean | string) {
this.nextWebcam.next(directionOrDeviceId);
}
handleImage(webcamImage: WebcamImage) {
this.getPicture.emit(webcamImage);
this.showWebcam = false;
}
get triggerObservable(): Observable<void> {
return this.trigger.asObservable();
}
get nextWebcamObservable(): Observable<boolean | string> {
return this.nextWebcam.asObservable();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment