Skip to content

Commit

Permalink
Close recorder on switch away, only send after finish clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Oct 5, 2018
1 parent da29423 commit d1d7ab6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions js/views/recorder_view.js
Expand Up @@ -11,13 +11,20 @@
initialize: function() {
this.startTime = Date.now();
this.interval = setInterval(this.updateTime.bind(this), 1000);

this.onSwitchAwayBound = this.onSwitchAway.bind(this);
$(window).on('blur', this.onSwitchAwayBound);

this.start();
},
events: {
'click .close': 'close',
'click .finish': 'finish',
'close': 'close'
},
onSwitchAway: function() {
this.close();
},
updateTime: function() {
var duration = moment.duration(Date.now() - this.startTime, 'ms');
var minutes = '' + Math.trunc(duration.asMinutes());
Expand All @@ -44,25 +51,31 @@
}
this.remove();
this.trigger('closed');

$(window).off('blur', this.onSwitchAwayBound);
},
finish: function() {
this.clickedFinish = true;
this.recorder.finishRecording();
this.close();
},
handleBlob: function(recorder, blob) {
if (blob) {
if (blob && this.clickedFinish) {
this.trigger('send', blob);
} else {
this.close();
}
},
start: function() {
this.clickedFinish = false;
this.context = new AudioContext();
this.input = this.context.createGain();
this.recorder = new WebAudioRecorder(this.input, {
encoding: 'mp3',
workerDir: 'js/' // must end with slash
});
this.recorder.onComplete = this.handleBlob.bind(this);
this.recorder.onError = this.onError;
this.recorder.onError = this.onError.bind(this);
navigator.webkitGetUserMedia({ audio: true }, function(stream) {
this.source = this.context.createMediaStreamSource(stream);
this.source.connect(this.input);
Expand Down

0 comments on commit d1d7ab6

Please sign in to comment.