mqtt client base on mqttws for the websocket connection
mqtt的websocket长链接客户端
- Equip with ES6 & Babel 6
- Build with gulp
First, you should clone the repo and install the dependencies.
$ git clone https://github.com/ccba/mqttclient.git <foldername>
$ cd <foldername>
$ npm install
Then, build the source to the disk
$ gulp
finally, use the mqttclient like this
- subscribe a topic(订阅一个topic)
let mqtt = new MqttClient("127.0.0.1", "8080", '');
mqtt.connect(() => {
mqtt.subscribe("topic", (message) => {
console.log(message);
});
});
- publish a message by a topic(发送消息到topic)
mqtt.publish("topic", "publish to a message");
MIT