Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing turning off camera and calling it on hidding camera #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,32 @@ describe('AppComponent', () => {
]
}).compileComponents();
}));

it('should create the app', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));

it('should render title in a h1 tag', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('ngx-webcam Demo');
}));

it('closing camera connection when turning off camera', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
app.deviceId = '111';
app.showWebcam = true;
const compiled = fixture.debugElement.nativeElement;

app.turnOffCamera();

expect(app.deviceId).toBeNull();
expect(app.showWebcam).toBeFalse();
expect(compiled.querySelector('webcam')).toBeNull();
}));

});
9 changes: 9 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export class AppComponent implements OnInit {

public toggleWebcam(): void {
this.showWebcam = !this.showWebcam;
if (!this.showWebcam) {
this.turnOffCamera();
}
}

public turnOffCamera(): void {
this.deviceId = null;
this.showWebcam = false;
this.nextWebcam.complete();
}

public handleInitError(error: WebcamInitError): void {
Expand Down