Browse Source

Add pc registry to usermedia to trigger media updates to all pcs where the usermedia stream is used.

pull/112/head
Simon Eisenmann 11 years ago
parent
commit
09eff1222b
  1. 2
      static/js/mediastream/peerconnection.js
  2. 32
      static/js/mediastream/usermedia.js

2
static/js/mediastream/peerconnection.js

@ -36,7 +36,7 @@ define(['jquery', 'underscore', 'webrtc.adapter'], function($, _) {
this.createPeerConnection(currentcall); this.createPeerConnection(currentcall);
} }
} };
PeerConnection.prototype.createPeerConnection = function(currentcall) { PeerConnection.prototype.createPeerConnection = function(currentcall) {

32
static/js/mediastream/usermedia.js

@ -22,6 +22,7 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _
// Create AudioContext singleton, if supported. // Create AudioContext singleton, if supported.
var context = AudioContext ? new AudioContext() : null; var context = AudioContext ? new AudioContext() : null;
var peerconnections = {};
var UserMedia = function(options) { var UserMedia = function(options) {
@ -62,7 +63,7 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _
// Connect stream to audio processor if supported. // Connect stream to audio processor if supported.
if (context.createMediaStreamSource) { if (context.createMediaStreamSource) {
this.e.bind("localstream", _.bind(function(event, stream) { this.e.on("localstream", _.bind(function(event, stream) {
if (this.audioSource) { if (this.audioSource) {
this.audioSource.disconnect(); this.audioSource.disconnect();
} }
@ -76,6 +77,17 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _
} }
this.e.on("localstream", _.bind(function(event, stream, oldstream) {
// Update stream support.
if (oldstream) {
_.each(peerconnections, function(pc) {
pc.removeStream(oldstream);
pc.addStream(stream);
console.log("Updated usermedia stream at peer connection", pc, stream);
});
}
}, this));
}; };
// Static. // Static.
@ -316,14 +328,13 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _
console.log("Add usermedia stream to peer connection", pc, this.localStream); console.log("Add usermedia stream to peer connection", pc, this.localStream);
if (this.localStream) { if (this.localStream) {
pc.addStream(this.localStream); pc.addStream(this.localStream);
this.e.on("localstream", _.bind(function(event, stream, oldstream) { var id = pc.id;
// Update stream support. if (!peerconnections.hasOwnProperty(id)) {
if (oldstream) { peerconnections[id] = pc;
pc.removeStream(oldstream); pc.currentcall.e.one("closed", function() {
pc.addStream(stream); delete peerconnections[id];
console.log("Updated usermedia stream at peer connection", pc, stream); });
} }
}, this))
} }
}; };
@ -333,6 +344,9 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _
console.log("Remove usermedia stream from peer connection", pc, this.localStream); console.log("Remove usermedia stream from peer connection", pc, this.localStream);
if (this.localStream) { if (this.localStream) {
pc.removeStream(this.localStream); pc.removeStream(this.localStream);
if (peerconnections.hasOwnProperty(pc.id)) {
delete peerconnections[pc.id];
}
} }
}; };

Loading…
Cancel
Save