Best Way To Switch Screen Share And Video On/Off

Hi, I am using VideoRoom plugin to build a simple video conference demo. The problem I am facing is that i want to close the video if user presses video mute button (not disable but remove it from peer connection because camera light remains on when it is disabled) so I do it with a remove request but it does not remove it from the sdp rather it just disables the video by adding a:inactive line to the sdp so if I turned the video on again, a new mid is assigned and sdp updates with 2 videos (one active and one inactive) but this will be a problem if I turn video on and off again and again, sdp will continue to increase and mid will go on increasing as well. Is there any better way to do this or I will have to spawn a new peer connection on demand?

It’s absolutely normal for the video track to turn inactive when you remove the track: in the SDP m-lines are persistent, they’ll stay there forever. If you use janus.js for Janus 1.x, you can use the replaceTrack function to tell the code specifically which mid the new video should be put in, which means you can tell it to re-use the one you were using before instead of adding a new mline. Please refer to the documentation or the original PR for info on how to do that.

Thanks for the quick reply @lorenzo . I used the replace property to replace inactive video track and it worked great. However, there is an edge case in which if i turn the video off by remove:true and then add screen share track using add:true, it shows to me that i am sharing my screen track on mid=2 “Janus started receiving our video (mid=2)” but to the remote peer screen sharing track is received on mid=1 “Remote track (mid=1) added (created)” which creates problems classifying and displaying the stream.