From 6e23a692fe7cba6dd4a4c0d1863ff7245a9de9a7 Mon Sep 17 00:00:00 2001 From: Pedro Rodriguez Date: Thu, 7 Feb 2019 12:19:40 +0100 Subject: [PATCH] Fix negotiation problems in Single PeerConnection (#1355) --- .../erizoClient/src/webrtc-stacks/BaseStack.js | 13 +++++++++++-- erizo_controller/erizoJS/models/Connection.js | 9 +++++++-- .../erizoJS/models/SessionDescription.js | 7 +++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js b/erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js index 487a0ca93d..724dfe031d 100644 --- a/erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js +++ b/erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js @@ -94,7 +94,7 @@ const BaseStack = (specInput) => { const checkOfferQueue = () => { if (!isNegotiating && offerQueue.length > 0) { - const args = offerQueue.pop(); + const args = offerQueue.shift(); if (args[0] === 'local') { that.createOffer(args[1], args[2], args[3]); } else { @@ -145,8 +145,16 @@ const BaseStack = (specInput) => { offerQueue.push(['remote', message]); return; } - isNegotiating = true; remoteSdp = SemanticSdp.SDPInfo.processString(msg.sdp); + + const sessionVersion = remoteSdp && remoteSdp.origin && remoteSdp.origin.sessionVersion; + if (latestSessionVersion >= sessionVersion) { + Logger.warning(`message: processOffer discarding old sdp sessionVersion: ${sessionVersion}, latestSessionVersion: ${latestSessionVersion}`); + return; + } + isNegotiating = true; + latestSessionVersion = sessionVersion; + SdpHelpers.setMaxBW(remoteSdp, specBase); msg.sdp = remoteSdp.toString(); that.remoteSdp = remoteSdp; @@ -164,6 +172,7 @@ const BaseStack = (specInput) => { remoteSdp = SemanticSdp.SDPInfo.processString(msg.sdp); const sessionVersion = remoteSdp && remoteSdp.origin && remoteSdp.origin.sessionVersion; if (latestSessionVersion >= sessionVersion) { + Logger.warning(`processAnswer discarding old sdp, sessionVersion: ${sessionVersion}, latestSessionVersion: ${latestSessionVersion}`); return; } Logger.info('Set remote and local description'); diff --git a/erizo_controller/erizoJS/models/Connection.js b/erizo_controller/erizoJS/models/Connection.js index d9cd2a7b40..dc3948bd38 100644 --- a/erizo_controller/erizoJS/models/Connection.js +++ b/erizo_controller/erizoJS/models/Connection.js @@ -124,12 +124,17 @@ class Connection extends events.EventEmitter { if (!this.wrtc.localDescription) { return; } + this.wrtc.localDescription = new SessionDescription(this.wrtc.getLocalDescription()); const sdp = this.wrtc.localDescription.getSdp(this.sessionVersion); - this.sessionVersion += 1; const stream = sdp.getStream(label); if (stream && removeStream) { - sdp.removeStream(stream); + log.info(`resendLastAnswer: StreamId ${streamId} is stream and removeStream, label ${label}, sessionVersion ${this.sessionVersion}`); + setTimeout(() => { + this._resendLastAnswer(evt, streamId, label, forceOffer, removeStream); + }, 50); + return; } + this.sessionVersion += 1; let message = sdp.toString(); message = message.replace(this.options.privateRegexp, this.options.publicIP); diff --git a/erizo_controller/erizoJS/models/SessionDescription.js b/erizo_controller/erizoJS/models/SessionDescription.js index f052181160..1802f90392 100644 --- a/erizo_controller/erizoJS/models/SessionDescription.js +++ b/erizo_controller/erizoJS/models/SessionDescription.js @@ -191,6 +191,13 @@ class SessionDescription { getSdp(sessionVersion = 0) { if (this.sdp) { + this.sdp.setOrigin({ + username: '-', + sessionId: 0, + sessionVersion, + netType: 'IN', + ipVer: 4, + address: '127.0.0.1' }); return this.sdp; } const info = this.connectionDescription;