messenger.js icon indicating copy to clipboard operation
messenger.js copied to clipboard

Should there be a ready event?

Open bijoutrouvaille opened this issue 14 years ago • 3 comments

Hi,

I've been having a problem with this kind of code:


var s = msr.createSpeaker(port);

s.request('test', {}, function(respData){
   console.log(respData)
})

the respData comes back as {error:-1} unless I wrap the first request in a timeout of a few milliseconds. It seems like it takes some time for the speaker to get created but, using the documented API, I see no way of catching the moment it does. Am I missing something?

my setup: osx 10.6.6 node v0.6.14

bijoutrouvaille avatar Apr 23 '12 12:04 bijoutrouvaille

I think that ideally you should be handling that error event to re-try the request.

weixiyen avatar Apr 24 '12 18:04 weixiyen

You are probably right to leave the handling of this to the consumer. I'm experimenting with adding a config object to the global messenger to allow for these reconnection attempts to be more automatic and avoid having recursive timeouts in the main code. I'll post back here if anything elegant comes of it. Cheers!

bijoutrouvaille avatar Apr 26 '12 20:04 bijoutrouvaille

I had the same problem. I've fixed it, see my pull request https://github.com/weixiyen/messenger.js/pull/6

PatrickG avatar Oct 17 '12 03:10 PatrickG