Webrtc-pc: ontrack events need to fire before setRemoteDescription resolves

Created on 5 Mar 2015  路  11Comments  路  Source: w3c/webrtc-pc

The spec says:

This will be fired only as a result of setRemoteDescription. Onnaddstream [sic] happens as early as possible after the setRemoteDescription.

The latter sentence is not right. It makes it impossible to build some forms of negotiation based on onaddstream because there is no definitive event that marks the end of the set of events. setRemoteDescription resolving is that event. For instance, if an application can only display one video track, it has to choose, and if it doesn't know that the set of options presented by a peer is complete, making an optimal choice is impossible.

It should say something like:

The onaddstream event fires only during the processing of setRemoteDescription. All streams and tracks that are signaled in a remote description MUST be exposed in an onaddstream event prior to the time that the promise returned by setRemoteDescription resolves.

bug

Most helpful comment

This saves my day

My problem is that ontrack doesn't fire, then I change the order or my code, move ontrack on top of setRemoteDescription, then it works.

Thanks

All 11 comments

100% agreed.

Works for me.

Agreed, although onaddstream is now ontrack.

It should also say that getRemoteTracks must return the complete set of tracks if called immediately after the promise is resolved.

Yes, I gather the same rule applies. We'll wanna fix up old getRemoteStreams() as well in implementations, as it'll probably need to stick around for quite some time in implementations.

@juberti

It should also say that getRemoteTracks must return the complete set of tracks if called immediately after the promise is resolved.

I'd rather say that getRemoteTracks() MUST produce a track when ontrack fires for that track. I think that's stronger.

i.e., the algorithm is roughly:

newtracks.forEach(track => {
  remoteTracks.push(track);
  dispatchEvent(new TrackAddedEvent('track', track));
});
resolveSetRemoteDescriptionPromise();

This should not be documented in the track/stream even handler attribute description. The latest spec addresses this to some extent.

We need to do some work in section: 5.1.3 Processing Remote MediaStreamTracks and in the description of setRemoteDescription().

Proposed fix: #221

Closing as #221 has been merged.

This saves my day

My problem is that ontrack doesn't fire, then I change the order or my code, move ontrack on top of setRemoteDescription, then it works.

Thanks

@maitrungduc1410 if you add the event listener for ontrack only after setRemoteDescription that is somewhat expected...

This saves my day

My problem is that ontrack doesn't fire, then I change the order or my code, move ontrack on top of setRemoteDescription, then it works.

Thanks

@maitrungduc1410 @fippo I had this same issue and spent many hours trying to figure out what was wrong and why I wasn't getting ontrack event triggers from one side, and it turns out it was just the order in which I created the event listeners (after setRemoteDescription). Posting here hoping others will find this too.

Thank you both for your comments. You saved my sanity.

Was this page helpful?
0 / 5 - 0 ratings