Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add and remove tracks in sync with the original on a linked stream
Until now a linked stream stopped its tracks when the original tracks
were stopped. Now linked tracks are added and removed too when tracks
are added and removed to and from the original stream. This will make
possible to keep audio monitor streams in sync with the original ones
without explicit handling.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and nickvergessen committed Aug 21, 2020
commit ded9c20df3832a5be9fd8747ef98e65222f3d5e0
17 changes: 17 additions & 0 deletions src/utils/webrtc/simplewebrtc/localmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ util.inherits(LocalMedia, WildEmitter)
const cloneLinkedTrack = function(track) {
const linkedTrack = track.clone()

// Keep a reference of all the linked clones of a track to be able to
// remove them when the source track is removed.
if (!track.linkedTracks) {
track.linkedTracks = []
}
track.linkedTracks.push(linkedTrack)

track.addEventListener('ended', function() {
linkedTrack.stop()
})
Expand All @@ -95,6 +102,16 @@ const cloneLinkedStream = function(stream) {
linkedStream.addTrack(cloneLinkedTrack(track))
})

stream.addEventListener('addtrack', function(event) {
linkedStream.addTrack(cloneLinkedTrack(event.track))
})

stream.addEventListener('removetrack', function(event) {
event.track.linkedTracks.forEach(linkedTrack => {
linkedStream.removeTrack(linkedTrack)
})
})

return linkedStream
}

Expand Down