simple-peer icon indicating copy to clipboard operation
simple-peer copied to clipboard

Reuse transceivers to reduce signal size

Open Mfron-42 opened this issue 5 years ago • 6 comments

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.

Mfron-42 avatar Apr 30 '19 18:04 Mfron-42

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.

t-mullen avatar May 04 '19 18:05 t-mullen

I thought about this some more - it'd be nice to automatically reuse transceivers when calling addTrack.

t-mullen avatar May 04 '19 23:05 t-mullen

actually it does, this is called "m-line recycling" (and there have been spec changes recently). Implementations may vary though.

fippo avatar May 05 '19 05:05 fippo

@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?

t-mullen avatar May 06 '19 17:05 t-mullen

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.

fippo avatar May 06 '19 17:05 fippo

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);
    }

arun3528 avatar Mar 15 '20 22:03 arun3528