Browse Source

fix(TPC): Remove the existing track instead of overwriting.

When a second remote track of the same mediatype is received for an endpoint, remove the existing track before creating the new remote track.
dev1
Jaya Allamsetty 4 years ago
parent
commit
4c668023b3
1 changed files with 12 additions and 3 deletions
  1. 12
    3
      modules/RTC/TraceablePeerConnection.js

+ 12
- 3
modules/RTC/TraceablePeerConnection.js View File

884
     }
884
     }
885
 
885
 
886
     if (existingTrack && existingTrack.getTrack() === track) {
886
     if (existingTrack && existingTrack.getTrack() === track) {
887
-        // Ignore duplicated event which can originate either from
888
-        // 'onStreamAdded' or 'onTrackAdded'.
887
+        // Ignore duplicated event which can originate either from 'onStreamAdded' or 'onTrackAdded'.
889
         logger.info(
888
         logger.info(
890
             `${this} ignored duplicated remote track added event for: `
889
             `${this} ignored duplicated remote track added event for: `
891
                 + `${ownerEndpointId}, ${mediaType}`);
890
                 + `${ownerEndpointId}, ${mediaType}`);
892
 
891
 
893
         return;
892
         return;
894
     } else if (existingTrack) {
893
     } else if (existingTrack) {
895
-        logger.error(`${this} overwriting remote track for ${ownerEndpointId} ${mediaType}`);
894
+        logger.error(`${this} received a second remote track for ${ownerEndpointId} ${mediaType}, `
895
+            + 'deleting the existing track.');
896
+
897
+        // The exisiting track needs to be removed here. We can get here when Jicofo reverses the order of source-add
898
+        // and source-remove messages. Ideally, when a remote endpoint changes source, like switching devices, it sends
899
+        // a source-remove (for old ssrc) followed by a source-add (for new ssrc) and Jicofo then should forward these
900
+        // two messages to all the other endpoints in the conference in the same order. However, sometimes, these
901
+        // messages arrive at the client in the reverse order resulting in two remote tracks (of same media type) being
902
+        // created and in case of video, a black strip (that of the first track which has ended) appears over the live
903
+        // track obscuring it. Removing the existing track when that happens will fix this issue.
904
+        this._remoteTrackRemoved(existingTrack.getOriginalStream(), existingTrack.getTrack());
896
     }
905
     }
897
 
906
 
898
     const remoteTrack
907
     const remoteTrack

Loading…
Cancel
Save