- From: Adam Bergkvist <adam.bergkvist@ericsson.com>
- Date: Thu, 15 Nov 2012 11:47:20 +0100
- To: "public-webrtc@w3.org" <public-webrtc@w3.org>
Hi
It's time for an update to reflect the feedback so far.
I've written a few code examples recently using a lot of stream and
track lookups and would like to add another bullet to the list of common
use cases (feedback on these?). We already have:
1) Lookup by id.
2) Iterate/loop through all the items in the collection.
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;
});
(if stream had more than one audio track and we wanted the "first" we
would have to either break the loop somehow or add a condition to not
overwrite theTrack every subsequent time)
compared to something that can use indexes (but without guaranteeing
stability).
var theTrack = stream.audioTracks[0];
Preferably you would use the id of the track to look it up, but when you
get a fresh stream from getUserMedia() you don't know the id yet.
To sum up the feedback, people seem to want something like this (mainly
based on Haralds feedback):
======
interface MediaStream {
// ...
sequence<MediaStreamTrack> getVideoTracks();
sequence<MediaStreamTrack> getAudioTracks();
MediaStreamTrack getTrackById(DOMString trackId);
void addTrack(MediaStreamTrack track);
void removeTrack(MediaStreamTrack track);
attribute EventHandler onaddtrack;
attribute EventHandler onremovetrack;
};
======
// 1) lookup by id
var track = stream.getTrackById(trackId);
// 2) Iterate
var audioTracks = stream.getAudioTracks();
for (var i = 0; i < audioTracks.length; i++)
// use audioTracks[i]
// 3) Get only (first) track of a kind
var audioTrack = localStream.getAudioTracks()[0];
/Adam
Received on Thursday, 15 November 2012 10:47:47 UTC