8***@qq.com
8***@qq.com
  • 发布:2021-08-10 18:09
  • 更新:2021-08-10 18:09
  • 阅读:648

【报Bug】mqtt连接在H5下可以正常重连,在APP下无法重连

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10专业版

HBuilderX类型: 正式

HBuilderX版本号: 3.1.22

手机系统: Android

手机系统版本号: Android 11

手机厂商: 三星

手机机型: N20U

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

<template>
<view class="content">
<button @click="connect" type="primary">connect</button>
<view class="log">
<view v-for="(log,index) in logs" class="" :key="index">
{{log}}
</view>
</view>
</view>
</template>

<script>
export default {
data() {
return {
title: 'Hello',
logs: []
}
},
methods: {
connect() {
var self = this
self.logs.push('connect')
var mqtt = require('mqtt/dist/mqtt.js')
// #ifdef H5
var client = mqtt.connect('ws://myserver:8083/mqtt')
// #endif
// #ifdef MP-WEIXIN||APP-PLUS
var client = mqtt.connect('wx://myserver:8083/mqtt')
// #endif
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())
})
}
}
}
</script>

<style>
.content {
text-align: center;
height: 400upx;
word-break: break-all;
}
</style>

操作步骤:

可以直接导入 https://ext.dcloud.net.cn/plugin?id=854 到hbilderX中,发布在H5和APP,分别点击界面中的connect,而后在服务器端剔除新连接

预期结果:

正常情况下会有reconnect打印出来,说明重连成功

实际结果:

H5下可以正常打印log,但是在APP(安卓)下无法打印

bug描述:

使用mqtt库和示例代码,发布在h5时,
测试方式:
点击connect连接后,在MQTT服务器端主动剔除新连接名(模拟掉线的情况),H5下可以瞬间打出reconnect的log,但是在APP下没有任何反应。

2021-08-10 18:09 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复