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

On 11/05/2012 02:36 PM, Adam Bergkvist wrote:
> ACTION-59 is about moving away from a model where index is the only way
> to look up streams and tracks in
> PeerConnection.localStreams/remoteStreams and
> MediaStream.audioTracks/videoTracks.
>
> I see two common cases how these stream and track collections will be used.
> 1) Lookup by id.
> 2) Iterate/loop through all the items in the collection.
>
> Item 1) is easily solved by a getStreamById()/getTrackById() method.
> Item 2) could be achieved in a few ways and I would like to get some
> feedback on which way people in group prefer.
>
> I don't think the "for (var p in collection)"-approach is something we
> want to use here. It won't give us the result we want since it includes
> additional properties added with a "collection.someProp = ..."
> assignment as well as inherited constants, methods and attributes.
>
> Here are two options on how to solve item 2) (iteration) from the list
> above. I you have a better approach, feel free to suggest it.
>
> A) forEachStream()/forEachTrack() method
>
> You iterate through all the items by providing a callback to the
> forEachStream() method. The callback will be called synchronously for
> each item.
>
> Example:
> pc.localStreams.forEachStream(function (stream) {
>      // use stream
> });
>
> We could have the callback return a boolean value which could be used to
> "break" the iteration if the desired item was found before the end was
> reached.
>
>
> B) Keep the possibility to use indices for looping (but not guarantee
> the order)
>
> This kind of looping may be more familiar to developers, but it exposes
> the index that may be problematic if used outside of the "looping
> context". The reason for proposing this as an alternative is that the
> video element does this for its track lists.
>
> Example:
> for (var i = 0; i < pc.localStreams.length; i++) {
>      // use pc.localStreams[i]
> }
>
> What do people think?

Honestly I have no strong preference. Both seem to work fine, and 
preserve the structure MediaStream -> MediaStreamTrackList -> 
MediaStreamTrack (which I have not seen strong arguments for changing so 
far).

But "forEach" seems safer as it does not invite to mistakes from the app 
developer, so my vote goes for that option.

Stefan

>
> /Adam
>

Received on Tuesday, 6 November 2012 13:18:45 UTC