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

32
static/js/mediastream/usermedia.js

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

Loading…
Cancel
Save