Browse Source

Merge pull request #294 from fancycode/conference_error_handling

Various fixes to conference error handling
pull/296/head
Simon Eisenmann 9 years ago committed by GitHub
parent
commit
c1496fb782
  1. 5
      static/js/controllers/uicontroller.js
  2. 2
      static/js/directives/audiovideo.js
  3. 36
      static/js/mediastream/peerconference.js
  4. 48
      static/js/mediastream/webrtc.js

5
static/js/controllers/uicontroller.js

@ -634,8 +634,11 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web @@ -634,8 +634,11 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
$scope.setConnectedStatus();
break;
case "failed":
var wasConnected = !currentcall.closed;
mediaStream.webrtc.doHangup("failed", currentcall.id);
alertify.dialog.alert(translation._("Peer connection failed. Check your settings."));
if (!wasConnected) {
alertify.dialog.alert(translation._("Peer connection failed. Check your settings."));
}
break;
}
});

2
static/js/directives/audiovideo.js

@ -354,7 +354,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -354,7 +354,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
mediaStream.webrtc.e.on("statechange", function(event, iceConnectionState, currentcall) {
if (!$scope.haveStreams) {
if (!$scope.haveStreams || currentcall.closed) {
return;
}

36
static/js/mediastream/peerconference.js

@ -36,6 +36,9 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -36,6 +36,9 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
this.callsCount = 0;
this.callStates = {};
this.connectedCalls = {};
// Ids of calls that "seem" to be disconnected (i.e. had a p2p state
// change of "disconnected" without a "Bye").
this.disconnectedCalls = {};
this.conferenceMode = false;
this.e = $({});
@ -70,9 +73,13 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -70,9 +73,13 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
};
PeerConference.prototype._addCallWithState = function(id, call, state) {
if (this.calls.hasOwnProperty(id)) {
console.warn("Already has a call for", id);
return false;
var oldcall = this.calls[id];
if (oldcall) {
if (!this.disconnectedCalls[id]) {
console.warn("Already has a call for", id);
return false;
}
oldcall.close(); // This will remove the call from the conference.
}
this.calls[id] = call;
@ -101,6 +108,9 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -101,6 +108,9 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
};
PeerConference.prototype.getCall = function(id) {
if (this.disconnectedCalls[id]) {
return null;
}
return this.calls[id] || null;
};
@ -121,10 +131,23 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -121,10 +131,23 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
delete this.calls[id];
delete this.callStates[id];
delete this.connectedCalls[id];
delete this.disconnectedCalls[id];
this.callsCount -= 1;
return call;
};
PeerConference.prototype.markDisconnected = function(id) {
this.disconnectedCalls[id] = true;
};
PeerConference.prototype.isDisconnected = function(id) {
return this.disconnectedCalls[id] || false;
};
PeerConference.prototype.getDisconnectedIds = function(id) {
return _.keys(this.disconnectedCalls);
};
PeerConference.prototype.close = function() {
var api = this.webrtc.api;
@ -161,13 +184,18 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall @@ -161,13 +184,18 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
};
PeerConference.prototype.pushUpdate = function() {
PeerConference.prototype.pushUpdate = function(forceAll) {
if (this.webrtc.isConferenceRoom()) {
// Conference is managed on the server.
return;
}
var ids = _.keys(this.connectedCalls);
if (forceAll) {
// Include "disconnected" calls to try to recover from a previous
// lost connection.
ids = _.union(ids, this.getDisconnectedIds());
}
if (ids.length > 1) {
ids.push(this.webrtc.api.id);
console.log("Calls in conference:", ids);

48
static/js/mediastream/webrtc.js

@ -95,6 +95,7 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -95,6 +95,7 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
this.msgQueues = {};
this.usermediaReady = false;
this.pendingMediaCalls = [];
this.pendingMessages = [];
this.usermedia = null;
this.audioMute = false;
@ -161,8 +162,29 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -161,8 +162,29 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
};
WebRTC.prototype.receivedRoom = function(event, room) {
if (this.currentroom && room && this.currentroom.Name == room.Name) {
// No room change, usually happens on reconnect.
var ids = this.conference.getDisconnectedIds();
if (ids.length > 1 && this.conference.id) {
// User was in a conference before, try to re-establish.
console.log("Re-establishing conference", this.conference.id, ids);
this.conference.pushUpdate(true);
}
return;
}
if (this.isConferenceRoom()) {
// Switching from a conference room closes all current connections.
this.leavingConference = true;
this.e.one("stop", _.bind(function() {
_.defer(_.bind(function() {
this.leavingConference = false;
while (this.pendingMessages.length) {
var args = this.pendingMessages.shift();
this.processReceivedMessage.apply(this, args);
}
}, this));
}, this));
_.defer(_.bind(function() {
this.doHangup();
}, this));
@ -209,6 +231,13 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -209,6 +231,13 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
return;
}
if (this.leavingConference) {
// Defer evaluating of messages until the previous conference room
// has been left.
this.pendingMessages.push([to, data, type, to2, from]);
return;
}
this.processReceivedMessage(to, data, type, to2, from);
};
@ -288,7 +317,7 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -288,7 +317,7 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
// Clean own internal data before feeding into browser.
delete data._conference;
autoaccept = true;
} else if (this.conference.hasCalls()) {
} else if (this.conference.hasCalls() && !this.conference.isDisconnected(from)) {
// TODO(fancycode): support joining callers to currently active conference.
console.warn("Received Offer while already in a call -> busy.", from);
this.api.sendBye(from, "busy");
@ -360,8 +389,11 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -360,8 +389,11 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
console.warn("Received Conference for unknown call -> ignore.", to, data);
return;
} else if (ids.length == 1) {
// Peer-to-peer call will be upgraded to conference.
if (data.indexOf(ids[0]) === -1) {
// Peer-to-peer call will be upgraded to conference. Only is allowed
// if currently active call is in the list of conference participants
// and the "Conference" is received from him. Upgrading is always
// allowed for server-managed conference rooms.
if ((from !== ids[0] || data.indexOf(ids[0]) === -1) && !this.isConferenceRoom()) {
console.warn("Received Conference for unknown call -> ignore.", to, data);
return;
}
@ -450,6 +482,14 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -450,6 +482,14 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
call.e.on("closed", _.bind(function() {
this.conference.removeCall(id);
}, this));
call.e.on("connectionStateChange", _.bind(function(event, state, currentcall) {
switch (state) {
case "disconnected":
case "failed":
this.conference.markDisconnected(currentcall.id);
break;
}
}, this));
return call;
};
@ -755,6 +795,8 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u @@ -755,6 +795,8 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u
}, this));
this.stop();
} else if (calls.length === 1) {
// Downgraded to peer-to-peer again.
this.conference.id = null;
this.e.triggerHandler("peerconference", [null]);
this.e.triggerHandler("peercall", [calls[0]]);
}

Loading…
Cancel
Save