Skip to content

Commit

Permalink
[fixed] use self instead of this for worker to work with workerify
Browse files Browse the repository at this point in the history
  • Loading branch information
jergason committed Sep 9, 2014
1 parent b1fe90c commit 6af7364
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
};
Expand Down
7 changes: 4 additions & 3 deletions recorderWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(){
Expand Down

0 comments on commit 6af7364

Please sign in to comment.