Reputation: 55
My program (javascipt) has captured a video stream from a camera and sent a video track (sentTrack
: MediaStreamTrack
) of the stream to the several peers (which each peer a webrtc-connection was established).
So I use the one stream/track and distribute them to several peers.
Then I need to stop sending video to one peer.
To do that I clear enabled
flag:
sentTrack.enabled = false
This code stops sending video to all peers, but I need to stop the video to one of them only.
How can I stop video to only one peer ?
Is it necessary to capture the "invidual" streams/track for each user in order to stop sending to the specific peer ?
If it is still necessary, will the creating multiple streams/track load the processor more comparing with the case 1 (one stream/track) ?
Upvotes: 0
Views: 174
Reputation: 76
Yes if you disable the local stream which you send to all peer connections then yes it will stop for all. But instead of disabling the localstream you could remove it from the individual peer connections you want to stop sending to.
You can either remove it by saving first the response from adding a track and removing then the track using that response:
sender = pc.addTrack(track, stream);
// some stuff happening
pc.removeTrack(sender);
Check here: https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/removeTrack
Or you can go also through all the senders and remove them all
const senders = pc.getSenders();
senders.forEach((sender) => pc.removeTrack(sender));
In these cases "pc" being the individual peerconnection, to which you want to stop sending the stream.
Upvotes: 1