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

Re: [webrtc-pc] replaceTrack and removeTrack: Synchronous?

From: jan-ivar via GitHub <sysbot+gh@w3.org>
Date: Thu, 07 Dec 2017 04:41:08 +0000
To: public-webrtc-logs@w3.org
Message-ID: <issue_comment.created-349861201-1512621667-sysbot+gh@w3.org>
> setting the track after it was null, which would arguably lead to unexpected behavior, whether or not racy

Most async methods are spec'ed to modify JS state on success, so this doesn't seem unexpected to me, much like both of these produce the same result:
```js
let x;
Promise.resolve().then(() => x = 1);
x = 2;
```
```js
let x = 2;
Promise.resolve().then(() => x = 1);
```
Similarly, both of these produce the same result:
```js
sender = pc.addTrack(t1);
sender.replaceTrack(t2);
pc.removeTrack(sender);
```
```js
sender = pc.addTrack(t1);
pc.removeTrack(sender);
sender.replaceTrack(t2);
```
What may be unexpected is that `removeTrack` is just a glorified setter for `track` and `direction`.

In practice, I expect racing like this is usually a bug, and best avoided:
```js
sender = pc.addTrack(t1);
await sender.replaceTrack(t2);
pc.removeTrack(sender);
```

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1677#issuecomment-349861201 using your GitHub account
Received on Thursday, 7 December 2017 04:41:11 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:21:52 UTC