Skip to content

Instantly share code, notes, and snippets.

@wehlutyk
Created September 15, 2015 02:44
Show Gist options
  • Save wehlutyk/eff0a904fb25ae38afb6 to your computer and use it in GitHub Desktop.
Save wehlutyk/eff0a904fb25ae38afb6 to your computer and use it in GitHub Desktop.
diff --git a/app/js/directives.js b/app/js/directives.js
index dcf758f..8d79172 100755
--- a/app/js/directives.js
+++ b/app/js/directives.js
@@ -1356,6 +1356,7 @@ angular.module('myApp.directives', ['myApp.filters'])
var stickerImageCompiled = $compile('<a class="composer_sticker_btn" data-sticker="{{::document.id}}" my-load-sticker document="document" thumb="true" img-class="composer_sticker_image"></a>');
var cachedStickerImages = {};
var audioRecorder = null;
+ var audioPromise = null;
var audioStream = null;
var emojiTooltip = new EmojiTooltip(emojiButton, {
@@ -1456,6 +1457,7 @@ angular.module('myApp.directives', ['myApp.filters'])
navigator.getUserMedia = ( navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
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;
@@ -1491,7 +1493,7 @@ angular.module('myApp.directives', ['myApp.filters'])
if (audioRecorder) {
$scope.$parent.$parent.voiceRecorder.processing = true;
- audioRecorder.ondataavailable = function(e){
+ audioPromise.then(function(e) {
var blob = e.data;
console.log(blob);
@@ -1500,12 +1502,16 @@ angular.module('myApp.directives', ['myApp.filters'])
audioRecorder = null;
$scope.$parent.$parent.voiceRecorder.processing = false;
- }
+ });
}
});
$($window).on('touchend', function(){
if (audioRecorder) {
+ audioPromise = new Promise(function(resolve) {
+ audioRecorder.ondataavailable = resolve;
+ });
+
audioRecorder.stop();
audioStream.stop();
@wehlutyk
Copy link
Author

L17 also prevents a new recording from being started when previous audio is being processed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment