diff --git a/static/js/mediastream/peercall.js b/static/js/mediastream/peercall.js index 90bf2006..4380e5f8 100644 --- a/static/js/mediastream/peercall.js +++ b/static/js/mediastream/peercall.js @@ -39,6 +39,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection this.datachannels = {}; this.streams = {}; + this.negotiationNeeded = false; this.initiate = false; this.closed = false; @@ -67,14 +68,14 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection var constraints = utils.mergeConstraints(this.offerConstraints, this.sdpConstraints); console.log('Creating offer with constraints: \n' + - ' \'' + JSON.stringify(constraints, null, '\t') + '\'.') + ' \'' + JSON.stringify(constraints, null, '\t') + '\'.', this.negotiationNeeded); this.peerconnection.createOffer(_.bind(this.onCreateAnswerOffer, this, cb), _.bind(this.onErrorAnswerOffer, this), constraints); }; PeerCall.prototype.createAnswer = function(cb) { - console.log("Creating answer."); + console.log("Creating answer.", this.negotiationNeeded); this.peerconnection.createAnswer(_.bind(this.onCreateAnswerOffer, this, cb), _.bind(this.onErrorAnswerOffer, this), this.peerconnection.sdpConstraints); }; @@ -105,6 +106,11 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection this.e.triggerHandler("error", "failed_peerconnection_setup"); }, this)); + if (this.negotiationNeeded) { + this.negotiationNeeded = false; + console.log("Negotiation complete.", this); + } + }; PeerCall.prototype.onErrorAnswerOffer = function(event) { @@ -191,23 +197,9 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection PeerCall.prototype.onNegotiationNeeded = function(peerconnection) { - var remoteDescription = peerconnection.pc.remoteDescription; - console.log("Negotiation needed.", remoteDescription); - if (remoteDescription && remoteDescription.type === "offer") { - // Need to answer. - // XXX(longsleep): In cases where we are in answer state but need to - // negotiate again, createAnswer will do nothing. We might need to call - // createOffer and send it out as answer? Is that valid / makes sense? - this.createAnswer(_.bind(function(sessionDescription) { - console.log("Sending new negotiation answer with sessionDescription", sessionDescription, this.id); - this.webrtc.api.sendAnswer(this.to, sessionDescription); - }, this)); - } else { - // Send offer. - this.createOffer(_.bind(function(sessionDescription) { - console.log("Sending new negotiation offer with sessionDescription", sessionDescription, this.id); - this.webrtc.api.sendOffer(this.to, sessionDescription); - }, this)); + if (!this.negotiationNeeded) { + this.negotiationNeeded = true; + console.log("Negotiation needed.", this); } }; diff --git a/static/js/mediastream/peerconnection.js b/static/js/mediastream/peerconnection.js index 5047e0bd..4ea68e74 100644 --- a/static/js/mediastream/peerconnection.js +++ b/static/js/mediastream/peerconnection.js @@ -227,9 +227,9 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { // XXX(longsleep): Renegotiation seems to break video streams on Chrome 31. // XXX(longsleep): Renegotiation can happen from both sides, meaning this // could switch offer/answer side - oh crap. - if (false) { - var peerconnection = event.target; - console.log("Negotiation needed.", peerconnection.remoteDescription, peerconnection.iceConnectionState, peerconnection.signalingState, this); + var peerconnection = event.target; + if (peerconnection === this.pc) { + //console.log("Negotiation needed.", peerconnection.remoteDescription, peerconnection.iceConnectionState, peerconnection.signalingState, this); this.currentcall.onNegotiationNeeded(this); }