0

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 Answers1

0

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));
sipsorcery
  • 30,273
  • 24
  • 104
  • 155
  • Thank you very much for your answer. It solved it for me and also gave me a heads up for another bug unrelated to this –  Nov 21 '20 at 12:36
  • You might want to add the stream association as well, i.e. `.addTrack(track, localStream)`. That way the tracks will be grouped and surfaced in a stream with the same `stream.id` remotely. – jib Nov 23 '20 at 19:23