Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How should i pass a localStream object as an argument to an
rtcpeerconnection addtrack method


I tried the code below but it returned this error

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


What I have tried:

JavaScript
localPeerConnection.addTrack(await localStream)
            remotePeerConnection.ontrack = () => {
                const remoteStreamVideoElement = document.querySelector("#remoteStreamVideoElement")
                remoteStreamVideoElement.srcObject = localStream
                remoteStreamVideoElement.onloadedmetadata = () => remoteStreamVideoElement.play()
            }
Posted
Updated 23-Nov-20 20:19pm

1 solution

The error is telling you that whatever your localStream promise returns, it can't be passed to the addTrack method.

We can't tell you how to fix that, since you haven't shown how the localStream variable is initialized.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900