mqttjs / mqtt-elements

Polymer elements for MQTT
http://mqttjs.github.io/mqtt-elements/
MIT License
27 stars 6 forks source link

Browserifying and subscriptions #17

Open edge0701 opened 7 years ago

edge0701 commented 7 years ago

I am looking to develop on your excellent work - I am looking to update the version of MQTT.js. But I am stuck at the first hurdle whilst trying to use browserify to create the bundle. I am missing something to do with the MQEmitter. I get the error: Error: Cannot find module 'MQEmitter' from '/home/edge/src/polymer/mqtt-wrapper/mqtt-elements'

The workaround I have found so far is to run browserify -r ./node_modules/mqtt/lib/store.js:Store -r mqtt -r ./node_modules/mqemitter/mqemitter.js > dist/mqtt-elements-bundle.js and then change the string in the bundle from ./node_modules/mqemitter/mqemitter.js to MQEmitter.

I have updated mqtt.js to the latest version and all seems to be working...except subscriptions. That is the reason I wanted to try an updated mqtt version.

Publishing works fine, but subscriptions don't seem to work. I am testing with Mosquitto and AWS IoT. Both fail to subscribe. But I do not disconnect from the server. I see the binary frames sent in Chrome browser debugger. I am using your example code "injecting-mqtt-connection". I see no messages and {{item.subscribed}} remains false.

Any help would be appreciated for A) how to browserify correctly, and B) why subscriptions don't work for me.

edge0701 commented 7 years ago

Another "Ah!" moment just after posting this. When I publish a message, a frame appears immediately in the browser debugger. So it seems I am receiving messages to the browser...but it never gets to...wait a second...

I get the message to "last-message" in but not to [[subscriptions.items[0].messages]]. [[subscriptions.items[0].topic]] is correct. But [[subscriptions.items[0].subscribed]] always remains false...

Sorry for my rambling!!

Edit: (I am not actually accessing the subscriptions exactly as above syntax; it's more psuedo-code to describe that the correct values in the subscription array.)

Is this an issue with the Polymer version?? I found the data in subscriptions[0].__data__ but topic is the only key available on the top level of the subscription element...

sandro-k commented 7 years ago

@edge0701 sorry for the delayed response. I will see if i can make an update to the current mqtt.js version.