Fixes bug with allocation of new PeerConnection, before the conference has started. Closes PeerConnection for non focus participant on beforeunload.

This commit is contained in:
paweldomas 2014-03-24 16:55:33 +01:00
parent e90e37ef83
commit 4bb8c3c48c
5 changed files with 52 additions and 29 deletions

27
app.js
View File

@ -295,8 +295,7 @@ function handleVideoThumbClicked(videoSrc) {
updateLargeVideo(videoSrc, 1);
$('audio').each(function (idx, el) {
// We no longer mix so we check for local audio now
if(el.id != 'localAudio') {
if (el.id.indexOf('mixedmslabel') !== -1) {
el.volume = 0;
el.volume = 1;
}
@ -450,8 +449,6 @@ $(document).bind('callactive.jingle', function (event, videoelem, sid) {
$(document).bind('callterminated.jingle', function (event, sid, reason) {
// FIXME
focus = null;
activecall = null;
});
$(document).bind('setLocalDescription.jingle', function (event, sid) {
@ -575,15 +572,11 @@ $(document).bind('left.muc', function (event, jid) {
}
else if (focus && Object.keys(connection.emuc.members).length === 0) {
console.log('everyone left');
if (focus !== null) {
// FIXME: closing the connection is a hack to avoid some
// problemswith reinit
if (focus.peerconnection !== null) {
focus.peerconnection.close();
}
disposeConference();
focus = new ColibriFocus(connection, config.hosts.bridge);
}
}
if (connection.emuc.getPrezi(jid)) {
$(document).trigger('presentationremoved.muc', [jid, connection.emuc.getPrezi(jid)]);
}
@ -967,8 +960,24 @@ $(window).bind('beforeunload', function () {
}
});
}
disposeConference();
});
function disposeConference() {
var handler = getConferenceHandler();
if(handler) {
if(connection.jingle.localAudio) {
handler.peerconnection.removeStream(connection.jingle.localAudio);
}
if(connection.jingle.localVideo) {
handler.peerconnection.removeStream(connection.jingle.localVideo);
}
handler.peerconnection.close();
}
focus = null;
activecall = null;
}
function dump(elem, filename){
elem = elem.parentNode;
elem.download = filename || 'meetlog.json';

View File

@ -75,11 +75,16 @@ ColibriFocus.prototype.makeConference = function (peers) {
self.channels.push([]);
});
if(connection.jingle.localAudio) {
this.peerconnection.addStream(connection.jingle.localAudio);
this.peerconnection
= new TraceablePeerConnection(
this.connection.jingle.ice_config,
this.connection.jingle.pc_constraints );
if(this.connection.jingle.localAudio) {
this.peerconnection.addStream(this.connection.jingle.localAudio);
}
if(connection.jingle.localVideo) {
this.peerconnection.addStream(connection.jingle.localVideo);
if(this.connection.jingle.localVideo) {
this.peerconnection.addStream(this.connection.jingle.localVideo);
}
this.peerconnection.oniceconnectionstatechange = function (event) {
console.warn('ice connection state changed to', self.peerconnection.iceConnectionState);

View File

@ -328,6 +328,12 @@ TraceablePeerConnection.prototype.modifySources = function(successCallback) {
sdp.raw = sdp.session + sdp.media.join('');
this.setRemoteDescription(new RTCSessionDescription({type: 'offer', sdp: sdp.raw}),
function() {
if(self.signalingState == 'closed') {
console.error("createAnswer attempt on closed state");
return;
}
self.createAnswer(
function(modifiedAnswer) {
// change video direction, see https://github.com/jitsi/jitmeet/issues/41

View File

@ -53,6 +53,12 @@ JingleSession.prototype.initiate = function (peerjid, isInitiator) {
this.hadstuncandidate = false;
this.hadturncandidate = false;
this.lasticecandidate = false;
this.peerconnection
= new TraceablePeerConnection(
this.connection.jingle.ice_config,
this.connection.jingle.pc_constraints );
this.peerconnection.onicecandidate = function (event) {
self.sendIceCandidate(event.candidate);
};

View File

@ -8,10 +8,6 @@ function SessionBase(connection, sid){
this.connection = connection;
this.sid = sid;
this.peerconnection
= new TraceablePeerConnection(
connection.jingle.ice_config,
connection.jingle.pc_constraints);
}
@ -48,26 +44,27 @@ SessionBase.prototype.switchStreams = function (new_stream, oldStream, success_c
var self = this;
// Remember SDP to figure out added/removed SSRCs
var oldSdp = null;
if(self.peerconnection.localDescription) {
oldSdp = new SDP(self.peerconnection.localDescription.sdp);
}
// Stop the stream to trigger onended event for old stream
oldStream.stop();
// Remember SDP to figure out added/removed SSRCs
var oldSdp = null;
if(self.peerconnection) {
if(self.peerconnection.localDescription) {
oldSdp = new SDP(self.peerconnection.localDescription.sdp);
}
self.peerconnection.removeStream(oldStream);
self.peerconnection.addStream(new_stream);
}
self.connection.jingle.localVideo = new_stream;
self.peerconnection.addStream(self.connection.jingle.localVideo);
self.connection.jingle.localStreams = [];
self.connection.jingle.localStreams.push(self.connection.jingle.localAudio);
self.connection.jingle.localStreams.push(self.connection.jingle.localVideo);
// Conference is not active
if(!oldSdp) {
if(!oldSdp || !self.peerconnection) {
success_callback();
return;
}