const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
- 发布:2023-03-02 11:59
- 更新:2024-07-17 01:06
- 阅读:1079
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 19044.2604
HBuilderX类型: 正式
HBuilderX版本号: 3.6.18
手机系统: Android
手机系统版本号: Android 8.0
手机厂商: 华为
手机机型: evr-an00
页面类型: vue
vue版本: vue3
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
const client:mqtt.MqttClient=mqtt.connect("wx://124.221.166.114:8803/mqtt",{clientId: 'clientid', username: "user", password: "passw", });
预期结果:
TypeError: socketTask.onOpen is not a function
TypeError: socketTask.onOpen is not a function
实际结果:
TypeError: socketTask.onOpen is not a function
TypeError: socketTask.onOpen is not a function
bug描述:
个人认为socketTask = wx.connectSocket({
url: url,
protocols: [websocketSubProtocol]
})这个函数无法创建连接,导致TypeError: socketTask.onOpen is not a function出错,因该是这样,H5正常,APP出错
1***@qq.com - 河南信阳光山
Failed to execute the callback function:
Error: Connection refused: Not authorized
01:06:01.919 reportJSException >>>> exception function:WEEX_CALL_JAVASCRIPT, exception:JavaScript execute error!Uncaught Error: Connection refused: Not authorized
at MqttClient._handleConnack (app-service.js:860:27)
at MqttClient._handlePacket (app-service.js:374:24)
at work (app-service.js:301:24)
at writable._write (app-service.js:312:17)
at doWrite (app-service.js:9611:24)
at writeOrBuffer (app-service.js:9599:17)
at Writable.write (app-service.js:9513:23)
at ondata (app-service.js:8867:32)
at emitOne (app-service.js:3412:23)
at emit (app-service.js:3479:17)
1***@163.com
已解决,在mqtt.js 文件里
socketTask = wx.connectSocket({
url: url,
protocols: websocketSubProtocol,
success(){} //增加这行
})
2023-03-29 01:58
2***@qq.com
回复 1***@163.com: 我也遇到了这个问题,将Vue版本从3降为2也可以解决。请问一下你这个解决方法是怎么想到的呢?
2024-04-23 17:37
2***@qq.com
回复 2***@qq.com: 是因为这个吗?如果希望返回一个 socketTask 对象,需要至少传入 success / fail / complete 参数中的一个。https://uniapp.dcloud.net.cn/api/request/websocket.html#connectsocket
2024-04-23 17:40