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.
You need to add a track not a stream. The API reference and an example can be seen here.