don't access dead objects

Some clean up to prevent the app from accessing the dead stream object.
This commit is contained in:
Jovan Gerodetti 2015-11-13 08:41:51 +01:00
parent ad66b39ff8
commit 49029b301b

View File

@ -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(){