How should i pass a localStream object as an argument to an rtcpeerconnection addtrack method

467 views Asked by At

I tried the code below

   localPeerConnection.addTrack(await localStream)
   remotePeerConnection.ontrack = () => {
      const remoteStreamVideoElement = document.querySelector("#remoteStreamVideoElement")
      remoteStreamVideoElement.srcObject = localStream
      remoteStreamVideoElement.onloadedmetadata = () => remoteStreamVideoElement.play()
   }

but it returned this error

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

1

There are 1 answers

2
sipsorcery On BEST ANSWER

You need to add a track not a stream. The API reference and an example can be seen here.

localStream.getTracks().forEach(track => localPeerConnection.addTrack(track));