I'm making a simple project that uses WebRTC in React with typescript.
I was following MDN HTMLMediaElement.captureStream().
const vid: HTMLVideoElement | null = document.querySelector("video");
if (vid) {
vid.captureStream();
}
.
.
.
<video id="myVid"></video>
But I'm getting this error,
Property 'captureStream' does not exist on type 'HTMLVideoElement'.ts(2339)
I've even tried,
const vid: HTMLMediaElement | null = document.querySelector("video");
What am I doing wrong??
I tried
const videoCont = useRef<HTMLVideoElement>(null);
var URL = window.URL || window.webkitURL
const fileURL = URL.createObjectURL(e)
if (videoCont.current) {
videoCont.current.src = fileURL;
videoCont.current.play = async () => {
const mediaStream = videoCont.current?.captureStream();
}
}
Still the same error,
Property 'captureStream' does not exist on type 'HTMLVideoElement'.
I looked into unresolved method captureStream on HTMLCanvasElement.
Apparently this is still an experimental feature not supported on all browsers. Will have to wait.
The property looks experimental and might not be added in TS yet. You can use any
or event make your own type:
interface HTMLMediaElementWithCaptureStream extends HTMLMediaElement{
captureStream(): MediaStream;
}