猿问

我应该如何将 localStream 对象作为参数传递给 rtcpeerconnection

我尝试了下面的代码


   localPeerConnection.addTrack(await localStream)

   remotePeerConnection.ontrack = () => {

      const remoteStreamVideoElement = document.querySelector("#remoteStreamVideoElement")

      remoteStreamVideoElement.srcObject = localStream

      remoteStreamVideoElement.onloadedmetadata = () => remoteStreamVideoElement.play()

   }

但它返回了这个错误


TypeError: Argument 1 of RTCPeerConnection.addTrack does not implement interface MediaStreamTrack.



慕盖茨4494581
浏览 110回答 1
1回答

米琪卡哇伊

您需要添加曲目而不是流。localStream.getTracks().forEach(track => localPeerConnection.addTrack(track));
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答