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

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 

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.

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 

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.

for (var i = 0; i < pc.localStreams.length; i++) {
     // use pc.localStreams[i]

What do people think?


Received on Monday, 5 November 2012 13:36:42 UTC