-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we need a "trackremoved" event? #1161
Comments
The track's "ended" event achieves this, no? |
Not quite... Because the track only actually ends when the transceiver is stopped or the m= section is rejected. The transceiver direction changing is the only indication that currently exists, as far as I can tell. |
when we need add/remove track after when we have made a peerconneciton and need renegotiate. |
i meet the same question. it not very friendly for user. |
We have this in http://w3c.github.io/webrtc-pc/#rtcpeerconnection-interface-extensions:
which however does not explain how that happens (referring to jsep) In the old model when you have a audio m-line and a video m-line and you renegotiate without video, the video tracks ended will be called even though there is no removestream. Having a trackremoved event will not solve all issues however. Consider the (somewhat hypothetical) case where a track was part of multiple streams and is removed from some streams. Would you expect trackremoved to be called and if yes, with what streams? How does that relate to the mediastreams removetrack event? |
I believe that paragraph is just obsolete. I traced the history and it goes at least as far back as when we had
This still happens. But
Well, assuming that setting the remote description removes the track from the correct streams (it doesn't right now), you'd be able to listen for the streams' |
Agree. I think this issue and #1168 are more than editorial changes, and need discussion. |
@taylor-b If we did this then we wouldn't need a trackremoved event, right? |
Iif we followed that pattern we would get a addstream event for every new stream and could listen for stream.onremovetrack. Surfacing both "a track was added" and "a track was removed" at the peerconnection level makes sense imo. Or is at least consistent if we want the first event. (I agree that it is quite surprising that SRD doesn't remove the track from streams though... well, that can be fixed) |
a lot of the confusion is coming from the lack of an example that show when to remove a video element that shows a remote track. In the old stream model this was easy, I have code from 2012 doing this:
or using MST.onended (which was removed)
In the track-based model this is somewhat more complex:
or alternatively do it it track.onended
@taylor-b how would this look like with a trackremoved event?
(we should have an example for this in the spec!) |
Agreed. I decided to test Chrome and Firefox behavior here using https://jsfiddle.net/jib1/xrwsp7o9/ The good news is that, where available,
But there were differences in the details that threw me:
I almost missed the good news because of the last one. I'd say the last three here are bugs.
I think it's important to support this model, for legacy reasons if nothing else, to let users |
Firefox doesn't implement the "removetrack" event on
That's wrong I'm afraid. Firefox passes a new stream on the remote side with the new tracks in it. It happens to have the same id as the old stream. I updated your fiddle to show this: https://jsfiddle.net/pehrsons/xrwsp7o9/7/ [1] https://w3c.github.io/webrtc-pc/archives/20160513/webrtc.html#processing-remote-mediastreamtracks |
@Pehrsons Ok that explains what I'm seeing in Firefox. Isn't two streams with the same But regardless, the net effect is nearly the same: There's a model for content replacement here that sorta works in at least two browsers. That seems worth preserving IMHO. |
The current draft of mediacapture-main even says that stream ids Of course webrtc-pc contradicts this by saying
-- This behavior though is probably a legacy bug in Firefox where renegotiations have been implemented for quite long, and at the same time hasn't gotten much attention from users. |
That contradiction seems like an issue in itself. Made a new issue for it. |
@fippo Section 5.3 says "When one of the SSRCs for RTP source media streams received by receiver is removed (either due to reception of a BYE or via timeout), the mute event is fired at track. If and when packets are received again, the unmute event is fired at track." So according to this one could argue that when the sender stops sending, a mute event is received on the remote received track. |
@aboba The |
@taylor-b I did some digging, and I need to correct your initial premise:
The answer since Oct 2014 has been "onremovestream has been removed (now, .onended is fired)." Transceivers weren't added until a year later, and the "ended" language remains to this day (#1168). For a whole year, the spec was In other words, we did not go straight from streams to transceivers, and the So we moved from:
I cover these 3 stages in my recent blog post and webinar. Also note Chrome fires |
@jan-ivar With respect to the transceiver model, the remote effects of transceiver.stop() are described in Section 5.4: "When a remote description is applied with a zero port in the media description for the corresponding transceiver, as defined in [JSEP] (section 4.2.2), the user agent must run the above steps as if stop had been called. In addition, since transceiver.receiver.track has ended, the steps described in track ended must be followed." Is this confused/unclear? |
@aboba That part seems clear, but sheds no light on what happens except when |
@aboba Oh I see how that was confusing. With the third bullet I just meant:
|
@jan-ivar what you write in #1161 (comment) and #1161 (comment) matches my memory. |
Is there an update on this? The only event we have is
This only happens if the event has not fired for the track before according to the set remote description steps.
I hope we can't re-use a transceiver with an old track whose event will not fire because it has already been fired before. Assuming remote streams should not be created for stream-less local tracks, the |
@henbos I believe we decided on #1402 which is waiting to be merged, so we won't need this. It lets users use
#1402 fixes this to fire |
Consensus at the September interim was to close this issue. |
@youennf How do you detect that a remote track is removed in Safari? |
Currently, there is no other way than looking at the SDP. |
@youennf Are you going to add one of the following? Is there an attribute on the pc, stream, track, or transceiver I can check after applying the remote offer or answer to know that a track was removed? |
We don't need an event for the pc to tell us what happened due the SDP we passed to it. Instead, what we need is pc.addRemoteTrack(rtpParams). But that's impossible with SDP. I no longer rely on pc events but instead I check the remote streams/tracks/receivers after sRD and match them with previous values (stored at app level). |
@ibc what do you check to find out that a remote track was removed in Safari? |
Actually I produce the remote SDP locally by adding the info (RTP parameters) of the added/removed remote track (whose RTP parameters are signaled). Then I call https://github.com/versatica/mediasoup-client/blob/master/lib/handlers/Safari11.js#L352 |
So you don't "check the remote streams/tracks/receivers after sRD". |
Not in my personal case (because I don't receive a SDP monster from the remote, but specific API "commands/events" such as "new remote track" with its specific RTP parameters). However, if I had to receive a remote SDP (not created by me or my app) I would parse it and, assuming Chrome or Safari, I would check the remote SSRCs of audio and video, would match them with the previous values, would realize that there is a new remote track, then would get its I just don't want to rely on peerconnection stream/track events at all. Events happen out of context, I hate that, it makes the application logic ugly. |
@fippo we should consider a shim for this in adapter. |
Plan is to handle these correctly as per spec.
Plan is to support it also, the infrastructure is there although I am not sure we should push people to rely on that. |
@youennf any news about a way to know when a remote track was removed on Safari? |
Hi, in Firefox 59+ I'm seeing that the |
@itsthetaste Yes that is correct. Firefox 59 implements Transceivers in the spec, which break this. See my blog post for details. I hope to write an updated one soon. |
@jan-ivar thanks, i found track.onmute fires like track.onended used to. hopefully, that will stay. |
Thanks! Yes |
In the pre-transceiver world, we had
addStream
/removeStream
methods, and"addstream"
/"removestream"
events. If you calladdStream
, then do an offer/answer, the"addstream"
event will fire for the PeerConnection on the other side, and same forremoveStream
/"removestream"
.Now, we have
addTrack
/removeTrack
... But we only have a single event,"track"
. So how are applications expected to know when the other peer removed the track? They would need to inspect the transceiver and see if its direction changed (for example, from"sendrecv"
to"recvonly"
). This makes the migration from the stream-based API (which is still all that Chrome implements) to the track-based API non-trivial.So, do we need a
"trackremoved"
event that fires when a transceiver's direction loses the "send" bit as a result of setting a remote description? This seems like a pretty trivial addition which would be appreciated by existing application developers.We're also missing a step that will remove the track from any remote streams that were created for it in this step: https://www.w3.org/TR/webrtc/#process-remote-track
I don't know if this was intentional or just an oversight from the
RTCRtpTransceiver
refactoring.The text was updated successfully, but these errors were encountered: