MQTT Client for the browser & React Native
This is an export of the MQTT.js library, but exported with Webpack as a CommonJS module for ease of use.
$ npm i --save wt-mqtt
import mqtt from 'wt-mqtt'
...
var client = mqtt.connect('ws://localhost:3000')
client.subscribe('mqtt/demo')
client.on('connect', () => {
console.log('mqtt connected')
})
client.on('message', (topic, payload) => {
console.log([topic, payload].join(': '))
client.end()
})
client.publish('mqtt/demo', 'hello world!')
We use Mosca as our MQTT broker. Read this wiki for a guide of setting up Mosca over WebSockets.