From 313e0dd32a65d52068cf4343e158a9b7ad80cbdf Mon Sep 17 00:00:00 2001 From: Jaya Allamsetty <54324652+jallamsetty1@users.noreply.github.com> Date: Wed, 2 Mar 2022 09:30:31 -0500 Subject: [PATCH] fix(TPC) Avoid renegotiations for p2p for mute/unmute. --- modules/RTC/TPCUtils.js | 8 +++++++- modules/RTC/TraceablePeerConnection.js | 16 +++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/RTC/TPCUtils.js b/modules/RTC/TPCUtils.js index 0eb46e3373..52c7a97955 100644 --- a/modules/RTC/TPCUtils.js +++ b/modules/RTC/TPCUtils.js @@ -239,11 +239,17 @@ export class TPCUtils { const track = localTrack.getTrack(); if (isInitiator) { + const streams = []; + + if (localTrack.getOriginalStream()) { + streams.push(localTrack.getOriginalStream()); + } + // Use pc.addTransceiver() for the initiator case when local tracks are getting added // to the peerconnection before a session-initiate is sent over to the peer. const transceiverInit = { direction: MediaDirection.SENDRECV, - streams: [ localTrack.getOriginalStream() ], + streams, sendEncodings: [] }; diff --git a/modules/RTC/TraceablePeerConnection.js b/modules/RTC/TraceablePeerConnection.js index 83c3c569ee..d0b45d9f4c 100644 --- a/modules/RTC/TraceablePeerConnection.js +++ b/modules/RTC/TraceablePeerConnection.js @@ -1651,14 +1651,12 @@ TraceablePeerConnection.prototype.addTrack = function(track, isInitiator = false if (this._usesUnifiedPlan) { logger.debug(`${this} TPC.addTrack using unified plan`); - if (webrtcStream || !this.isP2P) { - try { - this.tpcUtils.addTrack(track, isInitiator); - } catch (error) { - logger.error(`${this} Adding track=${track} failed: ${error?.message}`); + try { + this.tpcUtils.addTrack(track, isInitiator); + } catch (error) { + logger.error(`${this} Adding track=${track} failed: ${error?.message}`); - return Promise.reject(error); - } + return Promise.reject(error); } } else { // Use addStream API for the plan-b case. @@ -1736,7 +1734,7 @@ TraceablePeerConnection.prototype.addTrackUnmute = function(track) { } if (this._usesUnifiedPlan) { - return this.tpcUtils.replaceTrack(null, track).then(() => this.isP2P); + return this.tpcUtils.replaceTrack(null, track).then(() => false); } this._addStream(webRtcStream); @@ -2020,7 +2018,7 @@ TraceablePeerConnection.prototype.removeTrackMute = function(localTrack) { } if (this._usesUnifiedPlan) { - return this.tpcUtils.replaceTrack(localTrack, null); + return this.tpcUtils.replaceTrack(localTrack, null).then(() => false); } if (webRtcStream) {