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
mediaStream.webrtc.e.on("statechange", function(event, state, currentcall) { mediaStream.webrtc.e.on("statechange", function(event, state, currentcall) {
console.info("P2P state changed", state, currentcall.id); console.info("P2P state changed", state, currentcall.id);
switch (state) { 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 "completed":
case "connected": case "connected":
if ($scope.conference) { if ($scope.conference) {
@ -672,10 +679,14 @@ define(['jquery', 'underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'web
} }
}()), true); }()), true);
mediaStream.webrtc.e.on("done", function() { mediaStream.webrtc.e.on("done stop", function() {
if (mediaStream.connector.connected) { safeApply($scope, function(scope) {
$scope.setStatus("waiting"); if (mediaStream.connector.connected) {
} scope.setStatus("waiting");
} else {
scope.setStatus("closed");
}
});
}); });
mediaStream.webrtc.e.on("busy", function(event, from) { 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/
var streams = {}; var streams = {};
var calls = {}; 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.container = $element[0];
$scope.layoutparent = $element.parent(); $scope.layoutparent = $element.parent();
@ -58,7 +52,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.addRemoteStream = function(stream, currentcall) { $scope.addRemoteStream = function(stream, currentcall) {
var id = getStreamId(stream, currentcall); var id = currentcall.getStreamId(stream);
console.log("New stream", id); console.log("New stream", id);
if (streams.hasOwnProperty(id)) { if (streams.hasOwnProperty(id)) {
@ -76,7 +70,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
callscope = calls[currentcall.id]; callscope = calls[currentcall.id];
if (callscope.dummy) { if (callscope.dummy) {
// Current call is marked as dummy. Use it directly. // Current call is marked as dummy. Use it directly.
var dummyId = getStreamId(callscope.dummy, currentcall); var dummyId = currentcall.getStreamId(callscope.dummy);
subscope = streams[dummyId]; subscope = streams[dummyId];
if (subscope) { if (subscope) {
subscope.dummy = null; subscope.dummy = null;
@ -198,7 +192,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.removeRemoteStream = function(stream, currentcall) { $scope.removeRemoteStream = function(stream, currentcall) {
var id = getStreamId(stream, currentcall); var id = currentcall.getStreamId(stream);
console.log("Stream removed", id); console.log("Stream removed", id);
var subscope = streams[id]; var subscope = streams[id];

12
static/js/mediastream/peercall.js

@ -52,6 +52,18 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
//console.log("Set initiate", this.initiate, this); //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) { PeerCall.prototype.createPeerConnection = function(success_cb, error_cb) {
var peerconnection = this.peerconnection = new PeerConnection(this.webrtc, this); 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
}; };
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) { PeerConference.prototype.createCall = function(id, from, to) {
var currentcall = new PeerCall(this.webrtc, id, from, to); var currentcall = new PeerCall(this.webrtc, id, from, to);
@ -59,10 +69,7 @@ define(['jquery', 'underscore', 'mediastream/peercall'], function($, _, PeerCall
delete this.callsIn[id]; delete this.callsIn[id];
} }
console.log("Cleaned up conference call", id); console.log("Cleaned up conference call", id);
if (_.isEmpty(this.calls)) { this.checkEmpty();
console.log("Conference is now empty -> cleaning up.");
this.e.triggerHandler("finished");
}
}, this)); }, this));
currentcall.e.on("connectionStateChange", _.bind(function(event, iceConnectionState, currentcall) { currentcall.e.on("connectionStateChange", _.bind(function(event, iceConnectionState, currentcall) {
this.onConnectionStateChange(iceConnectionState, currentcall); this.onConnectionStateChange(iceConnectionState, currentcall);
@ -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. if (call !== this.currentcall) {
var calls = _.keys(this.callsIn); // An arbitrary call of the conference hung up.
if (calls.length) { 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 id = calls[0];
var currentcall = this.currentcall = this.calls[id]; this.currentcall = this.calls[id];
delete this.calls[id]; delete this.calls[id];
delete this.callsIn[id]; delete this.callsIn[id];
console.log("Handed over conference to", id, currentcall); console.log("Handed over conference to", id, this.currentcall);
if (_.isEmpty(this.calls)) {
console.log("Conference is now empty -> cleaning up.");
this.e.triggerHandler("finished");
}
return currentcall;
} }
return null; return this.currentcall;
}; };
PeerConference.prototype.autoAnswer = function(from, rtcsdp) { PeerConference.prototype.autoAnswer = function(from, rtcsdp) {

21
static/js/mediastream/webrtc.js

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

Loading…
Cancel
Save