更新记录
1.0.0(2025-04-25)
- 支持多端连接,插件内部管理连接
- 支持消息内容retained状态回调
- 支持断线消息、连接结果回调
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.31,Android:6.0,iOS:不支持,HarmonyNext:不支持 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
MQTT 客户端
con() {
let clientId = this.clientId
let host = "192.168.1.156"
let port:Int = 1883
let connectTimeout : Int = 4000 //毫秒
let reconnectPeriod : Int = 3000 //毫秒
let keepAliveInterval : Int = 2 //秒
const mqOptions = new MqOptions(connectTimeout, reconnectPeriod, keepAliveInterval, clientId, "user", "123456", true)
initMQTT(host, port, mqOptions,
(result, clientid, msg) => {
console.log(clientId, "连接结果:", msg)
if (result) {
//连接成功
// subscribe(clientId, this.topic, 1)
}
},
(clientid, topic, msg, isRetained, qos) => {
console.log("==>clientid:", clientid)
console.log("==>qos:", qos)
console.log("==>isRetained:", isRetained)
console.log("==>msg:", msg)
},
(clientid, msg) => {
console.log(clientid, "连接中断:", msg)
});
},
sub() {
let clientId = this.clientId
let qos : Int = 1
subscribe(clientId, this.topic, qos, (result, msg) => {
console.log(result, msg)
})
},
unSub() {
let clientId = this.clientId
unSubscribe(clientId, this.topic, (result, msg) => {
console.log(result, msg)
})
},
pub() {
let qos : Int = 1
let retained = false
let clientId = this.clientId
publish(clientId, this.pubTopic, "消息内容", qos, retained, (result, msg) => {
console.log(result, msg)
})
},
end() {
endMQ(clientId, (result, msg) => {
console.log(result, msg)
})
}