Kagami / vmsg

:musical_note: Library for creating voice messages
https://kagami.github.io/vmsg/
Creative Commons Zero v1.0 Universal
348 stars 58 forks source link

Cannot read property 'vmsg_flush' of null #28

Closed bknill closed 5 years ago

bknill commented 5 years ago

Hi,

I get this error randomly.. often on short recordings.

Uncaught TypeError: Cannot read property 'vmsg_flush' of null
    at vmsg_flush (blob:https://localhost:3000/d90fc477-de7d-45da-a372-6707d7cb41bf:77)
    at onmessage (blob:https://localhost:3000/d90fc477-de7d-45da-a372-6707d7cb41bf:166)
vmsg_flush @ blob:https://localhost:3000/d90fc477-de7d-45da-a372-6707d7cb41bf:77
onmessage @ blob:https://localhost:3000/d90fc477-de7d-45da-a372-6707d7cb41bf:166
Kagami commented 5 years ago

Sounds like race condition between init and stop messages in a Worker. Are you waiting for the initWorker() Promise before starting the recording? Could you please show your code?

bknill commented 5 years ago

Thanks. This is from a Redux action.

import vmsg from 'vmsg'
const recorder = new vmsg.Recorder({
  wasmURL: "https://unpkg.com/vmsg@0.3.0/vmsg.wasm"
})

      startWebRecorder()

const startWebRecorder = async () => {
  await recorder.initAudio()
  await recorder.initWorker()
  recorder.startRecording()
}

Then on stop

recorder.stopRecording().then(res => upload(res, type, id))

bknill commented 5 years ago

I'm not waiting for the initWorker promise, how would i add that to the start function?

Kagami commented 5 years ago

Is it possible you're calling stopRecording before startWebRecorder() Promise fulfilled?

I'm not waiting for the initWorker promise, how would i add that to the start function?

You may make yout buttons disabled by default and activate with e.g.

startWebRecorder().then(() => {
  this.setState({recording: true});
});

and then use disabled={!this.state.recording} for your stop button.

You need to init worker only once btw, don't create a new one for every record. Probably API should disallow this...

bknill commented 5 years ago

thanks I've done a check to see if it's been initialised and it works better