From 64258b8a68bedd3bcbc4e1bc99dedd870c442500 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Wed, 11 Jun 2014 18:03:34 +0200 Subject: [PATCH] Fixed bug that video got enabled on destroyed scope. --- static/js/directives/audiovideo.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/static/js/directives/audiovideo.js b/static/js/directives/audiovideo.js index 8b896391..160b12c1 100644 --- a/static/js/directives/audiovideo.js +++ b/static/js/directives/audiovideo.js @@ -48,12 +48,14 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ $scope.addRemoteStream = function(stream, currentcall) { //console.log("Add remote stream to scope", pc.id, stream); + // Create scope. var subscope = $scope.$new(true); var peerid = subscope.peerid = currentcall.id; buddyData.push(peerid); subscope.withvideo = false; subscope.onlyaudio = false; subscope.talking = false; + subscope.destroyed = false; subscope.applyTalking = function(talking) { subscope.talking = !! talking; safeApply(subscope); @@ -62,8 +64,16 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ console.log("Stream scope is now active", peerid); events.triggerHandler("active." + peerid, [subscope, currentcall, stream]); }); + subscope.$on("$destroy", function() { + console.log("Destroyed scope for audiovideo", subscope); + subscope.destroyed = true; + }); console.log("Created stream scope", peerid); + // Add created scope. + peers[peerid] = subscope; + + // Render template. peerTemplate(subscope, function(clonedElement, scope) { $($scope.remoteVideos).append(clonedElement); clonedElement.data("peerid", scope.peerid); @@ -72,7 +82,10 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ $window.attachMediaStream(video, stream); // Waiter callbacks also count as connected, as browser support (FireFox 25) is not setting state changes properly. videoWaiter.wait(video, stream, function(withvideo) { - peers[peerid] = scope; + if (scope.destroyed) { + console.log("Abort wait for video on destroyed scope."); + return; + } if (withvideo) { scope.$apply(function($scope) { $scope.withvideo = true; @@ -86,7 +99,10 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ scope.$emit("active", currentcall); $scope.redraw(); }, function() { - peers[peerid] = scope; + if (scope.destroyed) { + console.log("No longer wait for video on destroyed scope."); + return; + } console.warn("We did not receive video data for remote stream", currentcall, stream, video); scope.$emit("active", currentcall); $scope.redraw();