更新记录
1.0.0(2025-05-21)
初版
平台兼容性
uni-app
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
√ |
√ |
- |
- |
- |
- |
7.0 |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
7.0 |
- |
- |
- |
jjc-mqtt
开发文档
1.0.0(2025-05-21)
初版
引入插件
import {
getClient,
connectMQ,
subscribe,
unSubscribe,
MqOptions,
publish,
endMQ
} from "@/uni_modules/jjc-mqtt"
创建mqttClient
let client = getClient(IP, 1883, getApp().globalData.clientId)
建立连接
!!!autoReconnect参数请设置成false
!!!reconnectPeriod参数无效
let options = {
"connectTimeout": parseInt((uni.getStorageSync('connectTimeout') || 4000) / 1000),
"reconnectPeriod": parseInt((uni.getStorageSync('reconnectPeriod') || 3000) / 1000),
"keepAliveInterval": parseInt(uni.getStorageSync('keepalive') || 2),
"clientId": getApp().globalData.clientId,
"user": "user",
"password": "123456",
"autoReconnect": false,
}
connectMQ(getApp().globalData.clientId, options, (result, clientid, msg) => {
console.log(clientid, result, msg)
if (result == 1 || result == 2) {
//连接成功
}} else if (result == 3 || result == 4) {
//TODO
//连接失败
}
订阅主题
subscribe(客户端ID——string,主题-string,qos-int, callback-void)
subscribe(clientId, "/service/face/address", 0, (result, msg) => {
})
取消订阅主题
subscribe(客户端ID——string,主题-string,callback-void)
unsubscribe(clientId, "/service/face/address", (result, msg) => {
})
发布主题
publish(客户端ID——string,主题-string,消息-string,qos-int,retained-boolean,callback-void)
publish(clientId, topic, msg, qos, retained,(result, msg) => {
})
断开连接
publish(客户端ID——string,主题-string,qos-int, callback-void)
endMQ(clientId, (result, msg) => {
})