simple-peer
simple-peer copied to clipboard
Reuse transceivers to reduce signal size
I noticed that the signals keep on growing as I add new streams. Seems like removed stream are still referenced in futur signals. After a fewe cycles of adding and removing a stream the signal grows to more than 100ko.
WebRTC’s Unified Plan never actually removes transceivers from the connection, so they stick around in the session description. There’s no way to remove them.
You can reuse transceivers with peer.replaceTrack
instead of calling peer.addTrack
again.
I thought about this some more - it'd be nice to automatically reuse transceivers when calling addTrack
.
actually it does, this is called "m-line recycling" (and there have been spec changes recently). Implementations may vary though.
@fippo How would we go about recycling m-lines? I can't seem to find a description of this.
Do we set the transceiver's direction to inactive
and the recycling happens eventually?
This is something the browser would do when you call transceiver.stop() which marks the m-line in the SDP as inactive. - which isn't implemented in Chrome yet.
If the problem is caused by using addTrack and removeTrack to start and stop media, using replaceTrack on the same sender might avoid the problem.
Yep replace track with null and change the direction works
const result = Media.checkTracks(type, sendTrack && track, receiveTrack);
transceiver.direction = result.direction;
if (options.track) {
transceiver.sender.replaceTrack(track);
}