下面是代码:有经验的希望帮助一下小弟,感谢各位大神
qq:1437327989
connect() {
var self = this
var mqtt = require('../../common/mqtt/dist/mqtt.js')
const MqttOpt = {
clean: true, // 保留回话
connectTimeout: 4000, // 超时时间
// 认证信息
clientId: '15035450111111',
username: 'zhr2019',
password: 'XSzb0V2Pz4PTmAbGS7Gb3bzxx4RYXM9cCUGzp7E2y9o'
}
// #ifdef H5
var client = mqtt.connect('ws://mqtt.ctwing.cn:1883',MqttOpt)
// #endif
// #ifdef MP-WEIXIN||APP-PLUS
var client = mqtt.connect('wx://mqtt.ctwing.cn:1883',MqttOpt)
// #endif
console.info(client)
client.on('connect', function() {
self.logs.push('on connect')
client.subscribe('presence', function(err) {
if (!err) {
client.publish('presence', 'hello mqtt')
}
})
}).on('reconnect', function() {
self.logs.push('on reconnect')
}).on('error', function() {
self.logs.push('on error')
}).on('end', function() {
self.logs.push('on end')
}).on('message', function(topic, message) {
console.log(message)
self.logs.push(message.toString())
})
}
少点BUG
刚刚解决了
2023-02-25 10:28
n***@163.com
回复 少点BUG: 请问是如何解决的
2023-03-02 16:49
少点BUG
回复 n***@163.com: HbuilderX升级到3.7.3,就行了
2023-03-08 17:12
等待的风
回复 少点BUG: 为什么升级到3.7.3也是一直重连呢
2023-04-03 16:21