W3C home > Mailing lists > Public > public-webrtc@w3.org > November 2012

Re: [ACTION-59] Introduce lookup by id structures for streams and tracks.

From: Adam Bergkvist <adam.bergkvist@ericsson.com>
Date: Fri, 16 Nov 2012 07:27:29 +0100
Message-ID: <50A5DCD1.5090600@ericsson.com>
To: Martin Thomson <martin.thomson@gmail.com>
CC: "public-webrtc@w3.org" <public-webrtc@w3.org>
On 2012-11-15 22:01, Martin Thomson wrote:
> On 15 November 2012 02:47, Adam Bergkvist <adam.bergkvist@ericsson.com> wrote:
>> I'd like to add a third:
>> 3) Get the only track of a certain kind (if any) from a stream created by
>> getUserMedia().
>>
>> The forEach() approach has gotten some support, but I think it's a bit
>> clumsy doing 3) from the list of common uses.
>>
>> var theTrack;
>> stream.audioTracks.forEach(function (track) {
>>      theTrack = track;
>> });
>
> That would not be ideal; it selects the last audio track by iterating
> over the whole collection.

Exactly. This example was intended for a stream received from gUM() with 
only one track of each type, but in all other cases you would have to 
add extra code to not get the last track (as noted below the example).

> We have better tools available:
>
> MediaStream.prototype.getAudioTracks = function() {
>      return this.getTracks().filter(function(track) {
>          return track.type === 'audio';
>      });
> };

This would be a nice way to filter.

> Whether that is provided by the browser, or needs to be polyfilled, I
> don't care.  getTracks() is the key interface.

I don't have a strong opinion about one or two methods here. My first 
thought was that it's easier to concatenate the arrays if you wanted 
something that contained all tracks and implementations may already 
handle them separately (I know WebKit does).

> How important is it for application developers to be able to mess with
> the contents of their MediaStreams anyway?

I think pretty much all applications except the really simple ones need 
to touch tracks. For example to implement separate audio or video mute.

/Adam
Received on Friday, 16 November 2012 06:43:21 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 16 November 2012 06:43:22 GMT