Browse Source

Added workaround for not called onaddstream callback in FireFox (see https://bugzilla.mozilla.org/show_bug.cgi?id=998546.).

pull/32/head
Simon Eisenmann 11 years ago
parent
commit
674428bc5c
  1. 20
      static/js/mediastream/peercall.js
  2. 24
      static/js/mediastream/peerconnection.js

20
static/js/mediastream/peercall.js

@ -37,6 +37,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -37,6 +37,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
this.peerconnection = null;
this.datachannels = {};
this.streams= {};
this.initiate = false;
this.closed = false;
@ -124,6 +125,20 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -124,6 +125,20 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
if (cb) {
cb(sessionDescription, this);
}
// NOTE(longsleep): There are several szenarios where onaddstream is never fired, when
// the peer does not provide a certain stream type (eg. has no camera). See
// for example https://bugzilla.mozilla.org/show_bug.cgi?id=998546. For this
// reason we always trigger onRemoteStream added for all streams which are available
// after the remote SDP was set successfully.
_.defer(_.bind(function() {
_.each(peerconnection.getRemoteStreams(), _.bind(function(stream) {
console.log("got stream after remote sdp", stream);
if (!this.streams.hasOwnProperty(stream)) {
console.log("adding stream", stream);
this.onRemoteStreamAdded(stream);
}
}, this));
}, this));
}, this), _.bind(function(err) {
console.error("Set remote session description failed", err);
this.close();
@ -161,6 +176,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -161,6 +176,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
PeerCall.prototype.onRemoteStreamAdded = function(stream) {
this.streams[stream] = true;
this.e.triggerHandler("remoteStreamAdded", [stream, this]);
};
@ -168,6 +184,9 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -168,6 +184,9 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
PeerCall.prototype.onRemoteStreamRemoved = function(stream) {
this.e.triggerHandler("remoteStreamRemoved", [stream, this]);
if (stream) {
delete this.streams[stream];
}
};
@ -281,6 +300,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection @@ -281,6 +300,7 @@ define(['jquery', 'underscore', 'mediastream/utils', 'mediastream/peerconnection
datachannel.close();
});
this.datachannels = {};
this.streams = {};
if (this.peerconnection) {
this.peerconnection.close();

24
static/js/mediastream/peerconnection.js

@ -31,7 +31,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { @@ -31,7 +31,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
this.pc = null;
this.datachannel = null;
this.datachannelReady = false;
this.streams = {};
if (currentcall) {
this.createPeerConnection(currentcall);
@ -66,6 +65,9 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { @@ -66,6 +65,9 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
// Bind peer connection events.
pc.onicecandidate = _.bind(currentcall.onIceCandidate, currentcall);
pc.oniceconnectionstatechange = _.bind(this.onIceConnectionStateChange, this)
// NOTE(longsleep): There are several szenarios where onaddstream is never fired, when
// the peer does not provide a certain stream type (eg. has no camera). See
// for example https://bugzilla.mozilla.org/show_bug.cgi?id=998546.
pc.onaddstream = _.bind(this.onRemoteStreamAdded, this);
pc.onremovestream = _.bind(this.onRemoteStreamRemoved, this);
pc.onnegotiationneeded = _.bind(this.onNegotiationNeeded, this);
@ -202,7 +204,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { @@ -202,7 +204,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
var stream = event.stream;
console.info('Remote stream added.', stream);
this.streams[stream] = true;
this.currentcall.onRemoteStreamAdded(stream);
};
@ -212,7 +213,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { @@ -212,7 +213,6 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
var stream = event.stream;
console.info('Remote stream removed.', stream);
this.currentcall.onRemoteStreamRemoved(stream);
delete this.streams[stream];
};
@ -281,6 +281,24 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) { @@ -281,6 +281,24 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
};
PeerConnection.prototype.getRemoteStreams = function() {
return this.pc.getRemoteStreams.apply(this.pc, arguments);
};
PeerConnection.prototype.getLocalStreams = function() {
return this.pc.getRemoteStreams.apply(this.pc, arguments);
};
PeerConnection.prototype.getStreamById = function() {
return this.pc.getStreamById.appy(this.pc, arguments);
};
return PeerConnection;
});

Loading…
Cancel
Save