From 8e82aad86be656250b732458fa3a560659332fd9 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:54:53 +0200 Subject: [PATCH] fix logic error that made tracks disappear on the second track event --- src/platform/web/dom/WebRTC.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/web/dom/WebRTC.ts b/src/platform/web/dom/WebRTC.ts index 39a6f9d2..8c840ddc 100644 --- a/src/platform/web/dom/WebRTC.ts +++ b/src/platform/web/dom/WebRTC.ts @@ -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