Browse Source

Fixed stream vs call clash.

pull/206/head
Simon Eisenmann 10 years ago committed by Simon Eisenmann
parent
commit
0c9b34f57c
  1. 57
      static/js/directives/audiovideo.js

57
static/js/directives/audiovideo.js

@ -33,7 +33,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
var getStreamId = function(stream, currentcall) { var getStreamId = function(stream, currentcall) {
var id = currentcall.id + "-" + stream.id; var id = currentcall.id + "-" + stream.id;
console.log("Created stream ID", id); //console.log("Created stream ID", id);
return id; return id;
}; };
@ -63,33 +63,42 @@ 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 = getStreamId(stream, currentcall);
console.log("New stream", id);
if (streams.hasOwnProperty(id)) { if (streams.hasOwnProperty(id)) {
console.warn("Cowardly refusing to add stream id twice", id, currentcall); console.warn("Cowardly refusing to add stream id twice", id);
return; return;
} }
var subscope; var callscope;
// Dummy replacement support.
if (calls.hasOwnProperty(currentcall.id)) { if (calls.hasOwnProperty(currentcall.id)) {
subscope = calls[currentcall.id]; //console.log("xxx has call", id, currentcall.id);
callscope = calls[currentcall.id];
if (stream === dummy) { if (stream === dummy) {
return; return;
} }
if (subscope.dummy) { if (callscope.dummy) {
subscope.$apply(function() { // Current call has a dummy target. Use it directly.
subscope.attachStream(stream); callscope.dummy.$apply(function() {
console.log("Replacing dummy with stream", id);
callscope.dummy.attachStream(stream);
}); });
callscope.dummy = null;
return; return;
} }
} else { } else {
//console.log("xxx create call scope", currentcall.id, id);
// Create scope. // Create scope.
subscope = $scope.$new(); callscope = $scope.$new();
calls[currentcall.id] = subscope; calls[currentcall.id] = callscope;
callscope.streams = 0;
console.log("Created call scope", id);
} }
//console.log("Add remote stream to scope", stream.id, stream, currentcall); // Create scope for this stream.
var subscope;
subscope = callscope.$new();
callscope.streams++;
var peerid = subscope.peerid = currentcall.id; var peerid = subscope.peerid = currentcall.id;
buddyData.push(peerid); buddyData.push(peerid);
subscope.unattached = true; subscope.unattached = true;
@ -100,15 +109,26 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
console.log("Stream scope is now active", id, peerid); console.log("Stream scope is now active", id, peerid);
}); });
subscope.$on("$destroy", function() { subscope.$on("$destroy", function() {
if (subscope.destroyed) {
return;
}
console.log("Destroyed scope for stream", id, peerid); console.log("Destroyed scope for stream", id, peerid);
subscope.destroyed = true; subscope.destroyed = true;
callscope.streams--;
if (callscope.streams < 1) {
callscope.$destroy();
delete calls[peerid];
console.log("Destroyed scope for call", peerid, id);
}
}); });
console.log("Created stream scope", id, peerid); console.log("Created stream scope", id);
// Add created scope. // If stream is a dummy, mark us in callscope.
if (stream === dummy) { if (stream === dummy) {
subscope.dummy = true; callscope.dummy = subscope;
} }
// Add created scope.
streams[id] = subscope; streams[id] = subscope;
// Render template. // Render template.
@ -165,21 +185,16 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
$scope.removeRemoteStream = function(stream, currentcall) { $scope.removeRemoteStream = function(stream, currentcall) {
//console.log("remove stream", stream, stream.id, currentcall);
var id = getStreamId(stream, currentcall); var id = getStreamId(stream, currentcall);
console.log("Stream removed", id);
var subscope = streams[id]; var subscope = streams[id];
if (subscope) { if (subscope) {
buddyData.pop(currentcall.id); buddyData.pop(currentcall.id);
delete streams[id]; delete streams[id];
//console.log("remove scope", subscope);
if (subscope.element) { if (subscope.element) {
subscope.element.remove(); subscope.element.remove();
} }
var callscope = calls[currentcall.id];
if (subscope === callscope) {
delete calls[currentcall.id];
}
subscope.$destroy(); subscope.$destroy();
$scope.redraw(); $scope.redraw();
} }

Loading…
Cancel
Save