From 6af7364dc691911a56518819df5993d158ef805e Mon Sep 17 00:00:00 2001 From: Jamison Dance Date: Tue, 9 Sep 2014 09:11:19 -0600 Subject: [PATCH] [fixed] use self instead of this for worker to work with workerify --- recorder.js | 10 +++++----- recorderWorker.js | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/recorder.js b/recorder.js index f3ea3cfc..8502d5c9 100644 --- a/recorder.js +++ b/recorder.js @@ -8,6 +8,11 @@ var Recorder = function(source, cfg){ this.context.createJavaScriptNode).call(this.context, bufferLen, 2, 2); var worker = new Worker(WORKER_PATH); + worker.onmessage = function(e){ + var blob = e.data; + currCallback(blob); + } + worker.postMessage({ command: 'init', config: { @@ -63,11 +68,6 @@ var Recorder = function(source, cfg){ }); } - worker.onmessage = function(e){ - var blob = e.data; - currCallback(blob); - } - source.connect(this.node); this.node.connect(this.context.destination); //this should not be necessary }; diff --git a/recorderWorker.js b/recorderWorker.js index 08ad444c..0dd66c59 100644 --- a/recorderWorker.js +++ b/recorderWorker.js @@ -3,7 +3,8 @@ var recLength = 0, recBuffersR = [], sampleRate; -this.onmessage = function(e){ + +self.onmessage = function(e) { switch(e.data.command){ case 'init': init(e.data.config); @@ -40,14 +41,14 @@ function exportWAV(type){ var dataview = encodeWAV(interleaved); var audioBlob = new Blob([dataview], { type: type }); - this.postMessage(audioBlob); + self.postMessage(audioBlob); } function getBuffer() { var buffers = []; buffers.push( mergeBuffers(recBuffersL, recLength) ); buffers.push( mergeBuffers(recBuffersR, recLength) ); - this.postMessage(buffers); + self.postMessage(buffers); } function clear(){