Skip to content

Commit

Permalink
fix(TPC) Avoid renegotiations for p2p for mute/unmute.
Browse files Browse the repository at this point in the history
  • Loading branch information
jallamsetty1 committed Mar 2, 2022
1 parent 7fcea13 commit 313e0dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 7 additions & 1 deletion modules/RTC/TPCUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
};

Expand Down
16 changes: 7 additions & 9 deletions modules/RTC/TraceablePeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 313e0dd

Please sign in to comment.