W3C home > Mailing lists > Public > public-webrtc@w3.org > July 2017

[webrtc-pc] setRemoteDescription and ontrack order of events: SRD before ontrack?

From: henbos via GitHub <sysbot+gh@w3.org>
Date: Tue, 25 Jul 2017 09:29:29 +0000
To: public-webrtc@w3.org
Message-ID: <issues.opened-245339857-1500974966-sysbot+gh@w3.org>
henbos has just created a new issue for https://github.com/w3c/webrtc-pc:

== setRemoteDescription and ontrack order of events: SRD before ontrack? ==
TL;DR: Should `setRemoteDescription` be resolved before the resulting `ontrack` fires for remote tracks or after in the same task? @jan-ivar @taylor-b 

`setRemoteDescription` does, in parallel to returning a promise, a number of things. On success this includes:
```
1. Process remote tracks.
   1a. Queue a task to fire an event named track.
2. Resolve the promise.
```
As described, the promise would be resolved before `ontrack` fires. Invoking `then()` of a resolved promise means the resolver is not executed immediately, but [at the end of the current run of the JavaScript event loop](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#Timing), which is still before any tasks queued for the next JavaScript event loop. We get this order of events:
```
1. Synchronous code after our setRemoteDescription() call is executed as part of
   the current loop.
2. resolve is called (setRemoteDescription(...).then(resolve)) at the end of
   the current loop.
3. ontrack fires in the next loop.
```

Question: Is this on purpose? setRemoteDescription happens before tracks are fired.

If this isn't on purpose it's not obvious how to make the ontrack events fire first. If we don't queue them but fire them immediately, they're fired before we've completed all steps of setRemoteDescription, so we may be in an incomplete state. If we queue a task to resolve the promise then it would be possible to run a task in-between calling setRemoteDescription having had its effect and before the promise being resolved, which might yield unexpected behavior when examining the pc.

Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1508 using your GitHub account
Received on Tuesday, 25 July 2017 09:29:32 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 15:19:51 UTC