wechat-mqtt
v1.1.0
Published
与官方mqtt包用法大致相同: [https://github.com/mqttjs/MQTT.js#readme](https://github.com/mqttjs/MQTT.js#readme)
Downloads
5
Maintainers
Readme
与官方mqtt包用法大致相同: https://github.com/mqttjs/MQTT.js#readme
你可以这样:
import mqtt from 'wechat-mqtt';
var client = mqtt.connect('wxs://mqtt.demo.com')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
也可以这样:
import { connect } from 'wechat-mqtt';
var client = connect('wxs://mqtt.demo.com')
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})