mcollina / mows

Using MQTT.js in the browser over WebSocket -- Built with browserify!
72 stars 12 forks source link

Issue with qos being null #17

Open imp-guru opened 10 years ago

imp-guru commented 10 years ago

Hi,

i was seeing a very strange issue with a version of mows that I recently got off of npm and then ran through browserify.

I was getting the error "Invalid subscriptions - invalid qos"

after much debugging, I finally found the root cause, for some reason, the browser was evaluating this statement as true:

if (toString.call(callback) == '[object Object]')

even though toString.call(callback) was actually '[object Function]'

anyway, I commented out the following and things are working great: //if (toString.call(callback) == '[object Object]') { // opts = callback; // callback = nop; //}

This is sort of a hack but at the moment, I do not plan using these arguments.

mcollina commented 10 years ago

Ahum. can you please send an example that shows the issue?

imp-guru commented 10 years ago

Broken example: http://jsfiddle.net/lgbeno/6d2akk1n/

Functional example: http://jsfiddle.net/lgbeno/85nw5teu/1/

See the console for errors. I am using Chrome Version 37.0.2062.120

mcollina commented 10 years ago

I see the error on both.

It seems a browserify issue. Which version of browserify are you using?

imp-guru commented 10 years ago

5.11.1

I think this is the latest

imp-guru commented 10 years ago

I updated the link, maybe after you read it. try this for a functional example: http://jsfiddle.net/lgbeno/85nw5teu/1/

mcollina commented 10 years ago

Can you point me to the exact line that is messing up with that?

imp-guru commented 10 years ago

314

mcollina commented 10 years ago

of what file? Can you point me to github-link?

imp-guru commented 10 years ago

Original Browserified version: https://github.com/imp-guru/mows_test/blob/gh-pages/mows_browserified.js

To avoid this issue, I just commented out lines 314-317 these changes are here: https://github.com/imp-guru/mows_test/blob/gh-pages/mows_fixed.js

mcollina commented 10 years ago

Got that. Can you assemble a pull-request against MQTT.js that keeps that behavior but in a browser-safe way?

imp-guru commented 10 years ago

I'm afraid that is a beyond my level of understanding of how this whole process is working.

Maybe this evening I can go through mqtt.js and find a correlation but I really don't know what is happening under the hood with browserify yet.

mcollina commented 10 years ago

So these are the lines in MQTT.js that are causing the issue: https://github.com/adamvr/MQTT.js/blob/master/lib/client.js#L301-L303