From 49029b301be0c7a512bc418c086939e5d6036f2d Mon Sep 17 00:00:00 2001 From: Jovan Gerodetti Date: Fri, 13 Nov 2015 08:41:51 +0100 Subject: [PATCH] don't access dead objects Some clean up to prevent the app from accessing the dead stream object. --- app/js/directives.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/js/directives.js b/app/js/directives.js index 90cdd715..b86e3b62 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -1562,10 +1562,12 @@ angular.module('myApp.directives', ['myApp.filters']) voiceRecord.on('touchstart', function(e) { if ($scope.$parent.$parent.voiceRecorder.processing) { return; } + navigator.getUserMedia({audio : true}, function(stream){ var start = Date.now(); var touch = null; + audioPromise = null; audioStream = stream; audioRecorder = new MediaRecorder(stream); @@ -1594,7 +1596,7 @@ angular.module('myApp.directives', ['myApp.filters']) }); voiceRecord.on('click', function(){ - if (audioRecorder) { + if (audioPromise) { $scope.$parent.$parent.voiceRecorder.processing = true; audioPromise.then(function(e) { @@ -1604,14 +1606,15 @@ angular.module('myApp.directives', ['myApp.filters']) $scope.draftMessage.files = [blob]; $scope.draftMessage.isMedia = true; - audioRecorder = null; $scope.$parent.$parent.voiceRecorder.processing = false; + + audioPromise = null; }); } }); $($window).on('touchend', function(){ - if (audioRecorder) { + if (audioStream && audioRecorder) { audioPromise = new Promise(function(resolve) { audioRecorder.ondataavailable = resolve; }); @@ -1619,6 +1622,9 @@ angular.module('myApp.directives', ['myApp.filters']) audioRecorder.stop(); audioStream.stop(); + audioRecorder = null; + audioStream = null; + clearInterval($scope.$parent.$parent.voiceRecorder.recording); $scope.$apply(function(){