Browse Source

Merge pull request #283 from fancycode/conference_consistency

Make conferences more consistent
pull/285/head
Joachim Bauch 9 years ago
parent
commit
18df670928
  1. 19
      static/js/controllers/uicontroller.js
  2. 12
      static/js/directives/audiovideo.js
  3. 12
      static/js/mediastream/peercall.js
  4. 45
      static/js/mediastream/peerconference.js
  5. 21
      static/js/mediastream/webrtc.js

19
static/js/controllers/uicontroller.js

@ -577,6 +577,13 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web @@ -577,6 +577,13 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
mediaStream.webrtc.e.on("statechange", function(event, state, currentcall) {
console.info("P2P state changed", state, currentcall.id);
switch (state) {
case "closed":
if ($scope.getStatus() === "closed" || $scope.getStatus() === "waiting") {
return;
}
// This changes back from "conference" to "connected" if a
// conference is downgraded to p2p call.
/* falls through */
case "completed":
case "connected":
if ($scope.conference) {
@ -672,10 +679,14 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web @@ -672,10 +679,14 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
}
}()), true);
mediaStream.webrtc.e.on("done", function() {
if (mediaStream.connector.connected) {
$scope.setStatus("waiting");
}
mediaStream.webrtc.e.on("done stop", function() {
safeApply($scope, function(scope) {
if (mediaStream.connector.connected) {
scope.setStatus("waiting");
} else {
scope.setStatus("closed");
}
});
});
mediaStream.webrtc.e.on("busy", function(event, from) {

12
static/js/directives/audiovideo.js

@ -31,12 +31,6 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -31,12 +31,6 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
var streams = {};
var calls = {};
var getStreamId = function(stream, currentcall) {
var id = currentcall.id + "-" + stream.id;
//console.log("Created stream ID", id);
return id;
};
$scope.container = $element[0];
$scope.layoutparent = $element.parent();
@ -58,7 +52,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -58,7 +52,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.addRemoteStream = function(stream, currentcall) {
var id = getStreamId(stream, currentcall);
var id = currentcall.getStreamId(stream);
console.log("New stream", id);
if (streams.hasOwnProperty(id)) {
@ -76,7 +70,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -76,7 +70,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
callscope = calls[currentcall.id];
if (callscope.dummy) {
// Current call is marked as dummy. Use it directly.
var dummyId = getStreamId(callscope.dummy, currentcall);
var dummyId = currentcall.getStreamId(callscope.dummy);
subscope = streams[dummyId];
if (subscope) {
subscope.dummy = null;
@ -198,7 +192,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -198,7 +192,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.removeRemoteStream = function(stream, currentcall) {
var id = getStreamId(stream, currentcall);
var id = currentcall.getStreamId(stream);
console.log("Stream removed", id);
var subscope = streams[id];

12
static/js/mediastream/peercall.js

@ -52,6 +52,18 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -52,6 +52,18 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
//console.log("Set initiate", this.initiate, this);
};
PeerCall.prototype.getStreamId = function(stream) {
var streamid = stream.id;
var id = this.id + "-" + streamid;
if (!this.stream.hasOwnProperty(streamid) || this.streams[streamid] === stream) {
this.streams[streamid] = stream;
} else {
console.warn("A different stream is already registered, not replacing", stream, this.streams[stream.id])
}
//console.log("Created stream ID", id);
return id;
};
PeerCall.prototype.createPeerConnection = function(success_cb, error_cb) {
var peerconnection = this.peerconnection = new PeerConnection(this.webrtc, this);

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