[mediacapture-main] addtrack and removetrack events only fire when user agent updates stream

leahciMic has just created a new issue for https://github.com/w3c/mediacapture-main:

== addtrack and removetrack events only fire when user agent updates stream ==
Currently we already have a `addtrack` and a `removetrack` event on a `MediaStream`. These events are only fired when the user agent changes what is contained inside the stream, and does not fire when a script adds, or removes a track from a stream.

Currently if a script is passed in a `MediaStream` there is no good method of being notified when the tracks are changed without: a) polling, b) overriding the `addtrack`, and `removetrack` methods, both which are undesirable.

What is the rational of not firing these events when `addTrack` and `removeTrack` are called by a script? I understand that if you produced the `MediaStream` and you called `addTrack`, that you are aware that this is happening, but it's not always the case that your script owns the `MediaStream` and is aware of what is happening to it. 

Could we add some sort of `isExternal` flag (not sure on the naming here) to the `MediaStreamTrackEvent` that could indicate that this came from the useragent and fire `addtrack` and `removetrack` every time the stream is modified regardless of where the modifications came from?

Consider the following:

```
// stream is passed in to our API, and we want to monitor the tracks.
function processStream(stream) {
  const tracks = stream.getTracks();
  stream.addEventListener('addtrack', ({ track }) => tracks.push(track));
  stream.addEventListener('removetrack', ({ track }) => tracks.splice(tracks.indexOf(track), 1));
}
```

It would be really nice if `tracks` would be kept in sync with the actual tracks of the stream. But currently this is not the case.

Perhaps the `addtrack` and `removetrack` definition cannot be changed from what it is, without it affecting existing code. In this case, would it be possible to have yet another event? Perhaps a `updatetracks` event or something similar.

FWIW I'm completely open to the method/terminology used to provide this. I'm not fussed what it is called, or how it works, as long as there is a way to be notified when the track list is updated regardless of what did the updating.

Sorry if this is not the right place to post this sort of question, but I'm not sure where else to do so.

Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/517 using your GitHub account

Received on Tuesday, 1 May 2018 00:48:10 UTC