fix logic error that made tracks disappear on the second track event

This commit is contained in:
Bruno Windels 2022-04-11 14:54:53 +02:00
parent 8153060831
commit 8e82aad86b

View file

@ -188,10 +188,11 @@ class DOMPeerConnection implements PeerConnection {
}
private handleRemoteTrack(evt: RTCTrackEvent) {
// TODO: unit test this code somehow
// the tracks on the new stream (with their stream)
const updatedTracks = evt.streams.flatMap(stream => stream.getTracks().map(track => {return {stream, track};}));
// of the tracks we already know about, filter the ones that aren't in the new stream
const withoutRemovedTracks = this._remoteTracks.filter(t => !updatedTracks.some(ut => t.track.id === ut.track.id));
const withoutRemovedTracks = this._remoteTracks.filter(t => updatedTracks.some(ut => t.track.id === ut.track.id));
// of the new tracks, filter the ones that we didn't already knew about
const addedTracks = updatedTracks.filter(ut => !this._remoteTracks.some(t => t.track.id === ut.track.id));
// wrap them