i have tried to on/off video using addTrack and remove Track but not working
` document.getElementById('stopVedio').addEventListener('click', function () {
peer1.removeTrack(stream.getVideoTracks()[0], stream);
})
document.getElementById('startVedio').addEventListener('click', function () {
peer1.addTrack(stream.getVideoTracks()[0] stream);
})`
error : Track has been removed. You should enable/disable tracks that you want to re-add
Indeed, you should better enable/disable tracks by changing enabled field instead of adding/removing them, which in turn requires renegotiation and is more nuanced than you may want it to be.
Adding/removing should also work, but you will need to create a new track for that.
@nazar-pc Is there a workaround which allows adding of previously removed mediaTracks?
For background: I'm attempting a full mesh topology, in which each peer-to-peer stream quality is determined by the distance between the two peers in a 3D environment. The whole project is similar to VR chat or Mozilla Hubs. I had planned to store a high, middle and low quality stream and swap them out for each peer. Enabling / disabling mediaStream tracks doesn't work in this situation because it would affect all peer connections using a given mediaStream.
Thanks!
@AidanNelson sounds like you want to use replaceTrack() API instead of adding/removing it. Also you can clone it and then it would appear as a new distinct track while being the same internally: https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/clone
That seems to work. Thank you!