Browse Source

Move stream id creation to PeerCall.

That way the streams can be registered internally and properly cleaned up on hangup.
pull/283/head
Joachim Bauch 9 years ago
parent
commit
2e7b51a15a
  1. 12
      static/js/directives/audiovideo.js
  2. 12
      static/js/mediastream/peercall.js

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);

Loading…
Cancel
Save