Browse Source

Changed offer generation to generate offer when negotiation is required and signaling state is stable.

pull/138/head
Simon Eisenmann 11 years ago
parent
commit
d20dd4e957
  1. 3
      static/js/mediastream/peercall.js
  2. 7
      static/js/mediastream/peerconference.js
  3. 2
      static/js/mediastream/peerconnection.js
  4. 45
      static/js/mediastream/webrtc.js

3
static/js/mediastream/peercall.js

@ -196,11 +196,12 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
}; };
PeerCall.prototype.onNegotiationNeeded = function(peerconnection) { PeerCall.prototype.onNegotiationNeeded = function() {
if (!this.negotiationNeeded) { if (!this.negotiationNeeded) {
this.negotiationNeeded = true; this.negotiationNeeded = true;
console.log("Negotiation needed.", this); console.log("Negotiation needed.", this);
this.e.triggerHandler("negotiationNeeded", [this]);
} }
}; };

7
static/js/mediastream/peerconference.js

@ -92,13 +92,16 @@ define(['underscore', 'mediastream/peercall'], function(_, PeerCall) {
console.log("Creating PeerConnection", call); console.log("Creating PeerConnection", call);
call.createPeerConnection(_.bind(function(peerconnection) { call.createPeerConnection(_.bind(function(peerconnection) {
// Success call. // Success call.
call.e.on("negotiationNeeded", _.bind(function(event, extracall) {
this.webrtc.sendOfferWhenNegotiationNeeded(extracall);
}, this));
if (this.webrtc.usermedia) { if (this.webrtc.usermedia) {
this.webrtc.usermedia.addToPeerConnection(peerconnection); this.webrtc.usermedia.addToPeerConnection(peerconnection);
} }
call.createOffer(_.bind(function(sessionDescription, extracall) { /*call.createOffer(_.bind(function(sessionDescription, extracall) {
console.log("Sending offer with sessionDescription", sessionDescription, extracall.id); console.log("Sending offer with sessionDescription", sessionDescription, extracall.id);
this.webrtc.api.sendOffer(extracall.id, sessionDescription); this.webrtc.api.sendOffer(extracall.id, sessionDescription);
}, this)); }, this));*/
}, this), _.bind(function() { }, this), _.bind(function() {
// Error call. // Error call.
console.error("Failed to create peer connection for conference call."); console.error("Failed to create peer connection for conference call.");

2
static/js/mediastream/peerconnection.js

@ -230,7 +230,7 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
var peerconnection = event.target; var peerconnection = event.target;
if (peerconnection === this.pc) { if (peerconnection === this.pc) {
//console.log("Negotiation needed.", peerconnection.remoteDescription, peerconnection.iceConnectionState, peerconnection.signalingState, this); //console.log("Negotiation needed.", peerconnection.remoteDescription, peerconnection.iceConnectionState, peerconnection.signalingState, this);
this.currentcall.onNegotiationNeeded(this); this.currentcall.onNegotiationNeeded();
} }
}; };

45
static/js/mediastream/webrtc.js

@ -280,7 +280,10 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
} }
// TODO(longsleep): In case of negotiation this could switch offer and answer // TODO(longsleep): In case of negotiation this could switch offer and answer
// and result in a offer sdp sent as answer data. We need to handle this. // and result in a offer sdp sent as answer data. We need to handle this.
targetcall.setRemoteDescription(new RTCSessionDescription(data)); targetcall.setRemoteDescription(new RTCSessionDescription(data), function() {
// Received remote description as answer.
console.log("Received answer after we sent offer", data);
});
break; break;
case "Bye": case "Bye":
targetcall = this.findTargetCall(from); targetcall = this.findTargetCall(from);
@ -482,12 +485,17 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
// Connect. // Connect.
xfer.setInitiate(true); xfer.setInitiate(true);
xfer.createPeerConnection(); xfer.createPeerConnection(_.bind(function() {
xfer.e.on("negotiationNeeded", _.bind(function(event, currentxfer) {
this.sendOfferWhenNegotiationNeeded(currentxfer, id);
}, this));
}, this));
/*
xfer.createOffer(_.bind(function(sessionDescription, currentxfer) { xfer.createOffer(_.bind(function(sessionDescription, currentxfer) {
console.log("Sending xfer offer with sessionDescription", sessionDescription, currentxfer.id); console.log("Sending xfer offer with sessionDescription", sessionDescription, currentxfer.id);
// TODO(longsleep): Support sending this through data channel too if we have one. // TODO(longsleep): Support sending this through data channel too if we have one.
this.api.sendOffer(id, sessionDescription); this.api.sendOffer(id, sessionDescription);
}, this)); }, this));*/
}; };
@ -553,12 +561,17 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
// Connect. // Connect.
peerscreenshare.setInitiate(true); //XXX(longsleep): This creates a data channel which is not needed. peerscreenshare.setInitiate(true); //XXX(longsleep): This creates a data channel which is not needed.
peerscreenshare.createPeerConnection(); peerscreenshare.createPeerConnection(_.bind(function() {
peerscreenshare.e.on("negotiationNeeded", _.bind(function(event, currentscreenshare) {
this.sendOfferWhenNegotiationNeeded(currentscreenshare, id);
}, this));
}, this));
/*
peerscreenshare.createOffer(_.bind(function(sessionDescription, currentscreenshare) { peerscreenshare.createOffer(_.bind(function(sessionDescription, currentscreenshare) {
console.log("Sending screen share offer with sessionDescription", sessionDescription, currentscreenshare.id); console.log("Sending screen share offer with sessionDescription", sessionDescription, currentscreenshare.id);
// TODO(longsleep): Support sending this through data channel too if we have one. // TODO(longsleep): Support sending this through data channel too if we have one.
this.api.sendOffer(id, sessionDescription); this.api.sendOffer(id, sessionDescription);
}, this)); }, this));*/
}; };
@ -637,13 +650,16 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
} }
this.started = true; this.started = true;
if (this.initiator) { if (this.initiator) {
currentcall.createOffer(_.bind(function(sessionDescription, currentcall) { /*currentcall.createOffer(_.bind(function(sessionDescription, currentcall) {
console.log("Sending offer with sessionDescription", sessionDescription, currentcall.id); console.log("Sending offer with sessionDescription", sessionDescription, currentcall.id);
this.api.sendOffer(currentcall.id, sessionDescription); this.api.sendOffer(currentcall.id, sessionDescription);
}, this)); }, this));*/
} else { } else {
this.calleeStart(); this.calleeStart();
} }
currentcall.e.on("negotiationNeeded", _.bind(function(event, currentcall) {
this.sendOfferWhenNegotiationNeeded(currentcall);
}, this));
}, this), _.bind(function() { }, this), _.bind(function() {
// Error call. // Error call.
this.e.triggerHandler("error", ["Failed to create peer connection. See log for details."]); this.e.triggerHandler("error", ["Failed to create peer connection. See log for details."]);
@ -664,6 +680,21 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
}; };
WebRTC.prototype.sendOfferWhenNegotiationNeeded = function(currentcall, to) {
if (currentcall.peerconnection.pc.signalingState === "stable") {
if (!to) {
to = currentcall.id;
}
currentcall.createOffer(_.bind(function(sessionDescription, currentcall) {
console.log("Sending offer with sessionDescription", sessionDescription, to, currentcall);
// TODO(longsleep): Support sending this through data channel too if we have one.
this.api.sendOffer(to, sessionDescription);
}, this));
}
};
WebRTC.prototype.onConnectionStateChange = function(iceConnectionState, currentcall) { WebRTC.prototype.onConnectionStateChange = function(iceConnectionState, currentcall) {
// Defer this to allow native event handlers to complete before running more stuff. // Defer this to allow native event handlers to complete before running more stuff.
_.defer(_.bind(function() { _.defer(_.bind(function() {

Loading…
Cancel
Save