我尝试了下面的代码
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.
您需要添加一个音轨而不是流。API参考和示例可以在这里看到。
localStream.getTracks().forEach(track => localPeerConnection.addTrack(track));