feat: mqtt调试
This commit is contained in:
4
uni_modules/leliven-mqtt/changelog.md
Normal file
4
uni_modules/leliven-mqtt/changelog.md
Normal file
@ -0,0 +1,4 @@
|
||||
## 1.0.1(2023-10-18)
|
||||
更新使用文档
|
||||
## 1.0.0(2023-10-18)
|
||||
初始化mqtt
|
||||
3
uni_modules/leliven-mqtt/index.js
Normal file
3
uni_modules/leliven-mqtt/index.js
Normal file
@ -0,0 +1,3 @@
|
||||
import mqtt from './mqtt.min.js'
|
||||
|
||||
export default mqtt
|
||||
1
uni_modules/leliven-mqtt/mqtt.min.js
vendored
Normal file
1
uni_modules/leliven-mqtt/mqtt.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
85
uni_modules/leliven-mqtt/package.json
Normal file
85
uni_modules/leliven-mqtt/package.json
Normal file
@ -0,0 +1,85 @@
|
||||
{
|
||||
"id": "leliven-mqtt",
|
||||
"displayName": "leliven-mqtt",
|
||||
"version": "1.0.1",
|
||||
"description": "leliven-mqtt",
|
||||
"dependencies": {
|
||||
"mqtt": "^3.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"leliven-mqtt"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "sdk-js",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [
|
||||
],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "u",
|
||||
"vue3": "u"
|
||||
},
|
||||
"App": {
|
||||
"app-vue": "u",
|
||||
"app-nvue": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "u",
|
||||
"Android Browser": "u",
|
||||
"微信浏览器(Android)": "u",
|
||||
"QQ浏览器(Android)": "u"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "u",
|
||||
"IE": "u",
|
||||
"Edge": "u",
|
||||
"Firefox": "u",
|
||||
"Safari": "u"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "u",
|
||||
"阿里": "u",
|
||||
"百度": "u",
|
||||
"字节跳动": "u",
|
||||
"QQ": "u",
|
||||
"钉钉": "u",
|
||||
"快手": "u",
|
||||
"飞书": "u",
|
||||
"京东": "u"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
uni_modules/leliven-mqtt/readme.md
Normal file
40
uni_modules/leliven-mqtt/readme.md
Normal file
@ -0,0 +1,40 @@
|
||||
# leliven-mqtt
|
||||
|
||||
## 使用
|
||||
1. 依赖 [leliven-mqtt](https://ext.dcloud.net.cn/plugin?name=leliven-mqtt)
|
||||
3. 页面引用 ` import mqtt from '@/uni_modules/leliven-mqtt/index.js'`
|
||||
4. 详细使用说明:[MQTT.js](https://github.com/mqttjs/MQTT.js)
|
||||
|
||||
```js
|
||||
|
||||
// 初始化客户端连接地址
|
||||
// #ifdef H5
|
||||
let client = mqtt.connect('ws://test.mosquitto.org:8080')
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN||APP-PLUS
|
||||
let client = mqtt.connect('wx://test.mosquitto.org:8080')
|
||||
// #endif
|
||||
|
||||
// 连接MQ服务
|
||||
client.on('connect', function() {
|
||||
console.log('连接成功')
|
||||
|
||||
// 订阅主题
|
||||
client.subscribe('presence', function(err) {
|
||||
if (!err) {
|
||||
// 订阅成功
|
||||
client.publish('presence', 'hello mqtt')
|
||||
}
|
||||
})
|
||||
}).on('reconnect', function() {
|
||||
console.log('重新连接')
|
||||
}).on('error', function() {
|
||||
console.log('连接失败')
|
||||
}).on('end', function() {
|
||||
console.log('连接End')
|
||||
}).on('message', function(topic, message) {
|
||||
// 收到MQ消息
|
||||
console.log(message.toString())
|
||||
})
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user