我应该如何将 localStream 对象作为参数传递给 rtcpeerconnection addtrack 方法
How should i pass a localStream object as an argument to an rtcpeerconnection addtrack method
我尝试了下面的代码
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参考和示例可见here.
localStream.getTracks().forEach(track => localPeerConnection.addTrack(track));
我尝试了下面的代码
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参考和示例可见here.
localStream.getTracks().forEach(track => localPeerConnection.addTrack(track));