PSA: Legacy getLocalStreams()/addStream()/removeStream() implemented on top of spec APIs in M66

59 views
Skip to first unread message

hb...@webrtc.org

unread,
Feb 15, 2018, 12:52:21 PM2/15/18
to discuss-webrtc
WebRTC is going through an evolution for how it handles media, see The evolution of WebRTC 1.0, a Mozilla blogpost written before addTrack(), removeTrack() and sender.replaceTrack() was shipped in M64 and M65.

Chrome has shipped the essentials of addTrack(), removeTrack() and getSenders() with "Unified Plan" work still in-progress.
Part of the work to move away from the legacy stream-based APIs is to redefine them in ways compatible with the future of WebRTC, the APIs described in the spec, ensuring compatibility with "Unified Plan".

The changes are meant to make apps relying on legacy APIs to continue to work as they did before. However, changes in behaviors are observable if legacy and non-legacy APIs are mixed compared to how things worked in M64-65.
In M66, the following changes are made:

getLocalStreams() is redefined as "all streams of all active senders (getSenders())".
addStream() is redefined as "For each track in stream, do pc.addTrack(track, stream). Attach an observer to stream such that if a track is added/removed from the stream, perform pc.addTrack()/pc.removeTrack() accordingly."
removeStream() is redefined as "For each track in stream, do pc.removeTrack(track's sender). Detach the stream observer."

Most notably, this means that streams added with pc.addTrack(track, stream) will show up in pc.getLocalStreams(), not just streams added with pc.addStream(stream).
Note that while addTrack() is in the spec, getLocalStreams() is not, and everyone is encouraged to stop using the legacy APIs, but these two APIs now work together.
Reply all
Reply to author
Forward
0 new messages