Precompiled version of mqtt for browser
npm install precompiled-mqtt!mqtt.js
=======
npm install -g webpack // Install webpack globally
npm install mqtt // Install MQTT library
cd node_modules/mqtt
npm install . // Install dev deps at current dir
webpack mqtt.js --output-library mqtt // Build
`
This package had been tested only with React 17. But it should work with other frontend library as well.
NOTE : This package is replacement of mqtt@4.3.7
Installation
`
npm i precompiled-mqtt
`
Example
This is a piece of peudo-code, please raise a issue if you find any
`
import mqtt from "precompiled-mqtt";
// mosquitto test broker
const URL = "mqtt://test.mosquitto.org:8081";
// Local broker
const URL = "ws://192.168.43.xx:1234";
const client = mqtt.connect(URL);
client.on('connect', () => {
console.log("CONNECTED to broker");
});
const onMessage = (callBack) => {
client.on("message", (topic, message, packet) => {
callBack(JSON.parse(new TextDecoder("utf-8").decode(message)));
});
}
``