Browse Source

Fixed inconsistent PeerConference creation.

There was a case where a three-party conference got downgraded to a p2p
session and then upgraded to a three-party conference again, that the
two remaining participants created their own PeerConference object resulting
in a "split-brain" conference.
pull/283/head
Joachim Bauch 9 years ago
parent
commit
eb85b22da8
  1. 45
      static/js/mediastream/peerconference.js
  2. 21
      static/js/mediastream/webrtc.js

45
static/js/mediastream/peerconference.js

@ -50,6 +50,16 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -50,6 +50,16 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
};
PeerConference.prototype.checkEmpty = function() {
if (!_.isEmpty(this.calls)) {
return false;
}
console.log("Conference is now empty -> cleaning up.");
this.e.triggerHandler("finished");
return true;
};
PeerConference.prototype.createCall = function(id, from, to) {
var currentcall = new PeerCall(this.webrtc, id, from, to);
@ -59,10 +69,7 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -59,10 +69,7 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
delete this.callsIn[id];
}
console.log("Cleaned up conference call", id);
if (_.isEmpty(this.calls)) {
console.log("Conference is now empty -> cleaning up.");
this.e.triggerHandler("finished");
}
this.checkEmpty();
}, this));
currentcall.e.on("connectionStateChange", _.bind(function(event, iceConnectionState, currentcall) {
this.onConnectionStateChange(iceConnectionState, currentcall);
@ -113,24 +120,28 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -113,24 +120,28 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
};
PeerConference.prototype.handOver = function() {
PeerConference.prototype.callClosed = function(call) {
if (_.isEmpty(this.callsIn)) {
// No more calls in the conference
return null;
}
// Use a new call as currentcall and return this one.
var calls = _.keys(this.callsIn);
if (calls.length) {
if (call !== this.currentcall) {
// An arbitrary call of the conference hung up.
delete this.calls[call.id];
delete this.callsIn[call.id];
console.log("Conference call closed", call);
} else {
// The "initiator" call of the conference hung up, promote another
// call to "initator" and return it.
var calls = _.keys(this.callsIn);
var id = calls[0];
var currentcall = this.currentcall = this.calls[id];
this.currentcall = this.calls[id];
delete this.calls[id];
delete this.callsIn[id];
console.log("Handed over conference to", id, currentcall);
if (_.isEmpty(this.calls)) {
console.log("Conference is now empty -> cleaning up.");
this.e.triggerHandler("finished");
}
return currentcall;
console.log("Handed over conference to", id, this.currentcall);
}
return null;
return this.currentcall;
};
PeerConference.prototype.autoAnswer = function(from, rtcsdp) {

21
static/js/mediastream/webrtc.js

@ -297,26 +297,21 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -297,26 +297,21 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
return;
}
console.log("Bye process.");
if (targetcall === this.currentcall) {
var newcurrentcall;
if (this.currentconference) {
// Hand over current call to next conference call.
newcurrentcall = this.currentconference.handOver();
}
if (newcurrentcall) {
if (this.currentconference) {
// Hand over current call to next conference call.
var newcurrentcall = this.currentconference.callClosed(targetcall);
targetcall.close()
if (newcurrentcall && newcurrentcall != this.currentcall) {
this.currentcall = newcurrentcall;
targetcall.close()
//this.api.sendBye(targetcall.id, null);
this.e.triggerHandler("peercall", [newcurrentcall]);
}
if (this.currentconference && !this.currentconference.checkEmpty()) {
this.e.triggerHandler("peerconference", [this.currentconference]);
} else {
this.doHangup("receivedbye", targetcall.id);
this.e.triggerHandler("bye", [data.Reason, from, to, to2]);
}
} else {
this.doHangup("receivedbye", targetcall.id);
this.e.triggerHandler("bye", [data.Reason, from, to, to2]);
}
this.e.triggerHandler("bye", [data.Reason, from, to, to2]);
break;
case "Conference":
if (!this.currentcall || data.indexOf(this.currentcall.id) === -1) {

Loading…
Cancel
Save