Skip to content

Commit

Permalink
Fix addStream not triggering createOffer (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Nov 23, 2020
1 parent 7529cda commit 98f86e2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const BaseStack = (specInput) => {
if (specBase.forceTurn === true) {
that.pcConfig.iceTransportPolicy = 'relay';
}
that.tracksToBeNegotiated = 0;
that.audio = specBase.audio;
that.video = specBase.video;
if (that.audio === undefined) {
Expand All @@ -71,18 +72,18 @@ const BaseStack = (specInput) => {
};

that.peerConnection = new RTCPeerConnection(that.pcConfig, that.con);
let negotiationneededCount = 0;
that.peerConnection.onnegotiationneeded = () => { // one per media which is added
let medias = that.audio ? 1 : 0;
medias += that.video ? 1 : 0;
if (negotiationneededCount % medias === 0) {
that.tracksToBeNegotiated -= 1;

if (that.tracksToBeNegotiated === 0) {
logSDP('onnegotiationneeded - createOffer');
const promise = that.peerConnectionFsm.createOffer(false);
if (promise) {
promise.catch(onFsmError.bind(this));
}
} else if (that.tracksToBeNegotiated < 0) {
log.warning(`message: Negative tracks to be negotiated in connection, ${that.tracksToBeNegotiated}`);
}
negotiationneededCount += 1;
};

const configureLocalSdpAsAnswer = () => {
Expand Down Expand Up @@ -231,6 +232,7 @@ const BaseStack = (specInput) => {

addStream: negotiationQueue.protectFunction((stream) => {
logSDP('queue - addStream');
that.tracksToBeNegotiated += stream.getTracks().length;
negotiationQueue.startEnqueuing('addStream');
const promise = that.peerConnectionFsm.addStream(stream);
if (promise) {
Expand All @@ -242,6 +244,7 @@ const BaseStack = (specInput) => {
}),

removeStream: negotiationQueue.protectFunction((stream) => {
that.tracksToBeNegotiated += stream.getTracks().length;
logSDP('queue - removeStream');
negotiationQueue.startEnqueuing('removeStream');
const promise = that.peerConnectionFsm.removeStream(stream);
Expand Down

0 comments on commit 98f86e2

Please sign in to comment.