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

Implement removestream, removetrack events

Open t-mullen opened this issue 7 years ago • 7 comments

These events were disabled due to a lack of a reliable way to detect media removals and correlate them with streams provided by the stream and track events.

They should be re-added to allow peers to observe remote stream removals.

peer.on('removestream', cb) peer.on('removetrack', cb)

t-mullen avatar Apr 29 '18 16:04 t-mullen

Any progress yet? Would be great to have indeed.

nielsswinkels avatar Nov 15 '18 14:11 nielsswinkels

Yes this would be great! Right now i have to fire an additional event to hide/remove track from ui of the receiver. Any other better ideas as per current scenario?

sahiljain2497 avatar Oct 04 '19 07:10 sahiljain2497

Have the same problem. I send an additional event when the stream removed. It would be great to have such events

vbabenko avatar Nov 19 '19 09:11 vbabenko

The mute event is a good workaround for the lack of a removetrack event.

link.on('track', (track) => {
    console.log('track added');
    track.addEventListener('mute', () => {
        console.log('track removed')
    });
});

ted-piotrowski avatar May 17 '20 20:05 ted-piotrowski

@ted-piotrowski isn't that only going to fire for the local stream?

localStream.getAudioTracks()[0].enabled = false

does not trigger this on a remote peer:

  peer.on('track', (track, stream) => {
    track.addEventListener('mute', () => {
      // TODO update UI
    });
  });

FWIW I'm sending the mute/unmute events out of band using the signaling server I have as a workaround.

horatio-sans-serif avatar May 19 '20 15:05 horatio-sans-serif

@fictorial The mute event fires on the remote peer for me (Latest Chrome/MacOS) 🤷 However, the mute event can't be used to infer if a track has ended because mute event gets periodically emitted when a peer can't stream data fast enough and unmute is emitted when data comes through again. I am also sending a trackRemoved event now, but using the simplepeer data channel instead of a signaling server. Would be a nice addition to have a removeTrack event.

ted-piotrowski avatar May 20 '20 16:05 ted-piotrowski

Any traction on this yet? If not, any pointers on how this should be properly implemented? Happy to submit a PR.

matallui avatar Jun 10 '23 00:06 matallui