I am a newbie in use webrtc with angular6. when I research WebRTC APIs and build a simple page to show/stop webcam stream in local test. I get a error message in development. There is my development environment:
Angular 6.1.0
Angular-cli 6.1.2
Typescript 2.9.2
I build "stop" button to execute function stopBtn(). But typescript compiler will throw the error message in building app :
error TS2339: Property 'getTracks' does not exist on type 'MediaStream | Blob | MediaSource'. Property 'getTracks' does not exist on type 'Blob'.
stopBtn() function code :
private video: HTMLVideoElement;
.......
ngOnInit() {
this.video = <HTMLVideoElement>this.el.nativeElement.querySelector('#video');
}
........
getDevice() {.....}
getStream() {.....}
gotStream() {.....}
.......
stopBtn() {
if (this.video.srcObject) {
this.video.srcObject.getTracks().forEach( stream => stream.stop());
this.video.srcObject = null;
}
}
html simple code:
<video id="video" autoplay></video>
<button id="stopbtn" type="button" (click)="stopBtn()">Stop</button>
This page can show stream correctly.
I had search many keywords for this error message by stackoverflow or google. But do not get any good answer for it. So hope someone can resolve it for me. Thank you.