类型“HTMLVideoElement”上不存在属性“captureStream”

Nit*_*Sai 5 html webrtc typescript reactjs capturestream

我正在制作一个简单的项目,在 React 中使用 WebRTC 和 typescript。

我正在关注MDN HTMLMediaElement.captureStream()

const vid: HTMLVideoElement | null = document.querySelector("video");
if (vid) {
   vid.captureStream();
}

.
.
.

<video id="myVid"></video>
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误

Property 'captureStream' does not exist on type 'HTMLVideoElement'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

我什至尝试过,

const vid: HTMLMediaElement | null = document.querySelector("video");
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么??

编辑

我试过

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();
       }
   }
Run Code Online (Sandbox Code Playgroud)

还是同样的错误,

Property 'captureStream' does not exist on type 'HTMLVideoElement'.
Run Code Online (Sandbox Code Playgroud)

编辑2

我研究了HTMLCanvasElement 上未解决的方法 captureStream

显然这仍然是一个实验性功能,并非所有浏览器都支持。还得等。

Tus*_*ahi 4

该属性看起来是实验性的,可能尚未添加到TS中。您可以使用any或创建自己的类型:

interface HTMLMediaElementWithCaptureStream extends HTMLMediaElement{
  captureStream(): MediaStream;
}
Run Code Online (Sandbox Code Playgroud)