Skip to content

Comments

Fix "TypeError: recBuffers.push is undefined"#37

Open
MotasemAghbar wants to merge 1 commit intohiguma:masterfrom
foundertherapy:bugs/recbuffer-undefined-error
Open

Fix "TypeError: recBuffers.push is undefined"#37
MotasemAghbar wants to merge 1 commit intohiguma:masterfrom
foundertherapy:bugs/recbuffer-undefined-error

Conversation

@MotasemAghbar
Copy link

@MotasemAghbar MotasemAghbar commented Nov 17, 2019

The function 'record' might throw a TypeError when executing recBuffers.push.

This happens when stopping the recorder, there is a chance for a race condition in the last 'record' event call and clean method, the clean method assigns the recBuffers to null, record event might be executing after the clean method, and then throw type error because recBuffers isn't defined.

The fix is to check if the recBuffers is undefined before accessing that var.

@andreszs
Copy link

Thanks for this PR, it works perfectly. Too bad the original developer has vanished and this won't be ever merged.

@maria-nedelkova
Copy link

I think that a better fix for this issue is to remove onaudioprocess event handler before processor has been deleted in cancelRecording function and finishRecording function (WevAudioRecorder.js):

    cancelRecording: function () {
      if (this.isRecording()) {
        this.input.disconnect();
        this.processor.disconnect();
        this.processor.onaudioprocess = null;
        delete this.processor;
        this.worker.postMessage({ command: 'cancel' });
      } else this.error('cancelRecording: no recording is running');
    },

    finishRecording: function () {
      if (this.isRecording()) {
        this.input.disconnect();
        this.processor.disconnect();
        this.processor.onaudioprocess = null;
        delete this.processor;
        this.worker.postMessage({ command: 'finish' });
      } else this.error('finishRecording: no recording is running');
    },

@a8568730
Copy link

@maria-nedelkova thank you for the fix, I add the line this.processor.onaudioprocess = null; before those functions and it fixes the error. :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants