2***@qq.com
2***@qq.com
  • 发布:2020-12-04 11:12
  • 更新:2020-12-04 15:46
  • 阅读:1214

【报Bug】 uni.onSocketMessage

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 2.9.8

第三方开发者工具版本号: 1.0.3.2011120

基础库版本号: 2.0.0-28920200927001

项目创建方式: HBuilderX

示例代码:

/* WebSocket 初始化 /
initWebSocket() {
uni.connectSocket({
url:
"~“,
});
// 监听WebSocket错误。
uni.onSocketError((res) => {
console.log(res, "onSocketError");
this.websocketonerror();
});
// 通过 WebSocket 连接发送数据,需要先 uni.connectSocket,并在 uni.onSocketOpen 回调之后才能发送。
// uni.sendSocketMessage((res) => {
// console.log(res.data, 'res.data')
// })
//监听WebSocket接收到服务器的消息事件。
uni.onSocketMessage((res) => {
console.log(res);
this.websocketonmessage(res);
});
// 监听WebSocket连接打开事件。
uni.onSocketOpen((res) => {
this.socketOpen = true;
console.log(res);
this.websocketonopen();
});
// 监听WebSocket连接关闭事件。
uni.onSocketClose((res) => {
this.socketOpen = false;
console.log(res);
});
},

操作步骤:

测试1
a端:uni-app b端: vue
1.a->b 成功

  1. b-》a 监听到连接中断 (失败)

预期结果:

接收到消息

实际结果:

a端监听接收消息没有反应,监听到连接中断

bug描述:

测试1
a端:uni-app b端: vue
1.a->b 成功

  1. b-》a 监听到连接中断 (失败)

a端部分代码```javascript

 /** WebSocket 初始化 */  
    initWebSocket() {  
      uni.connectSocket({  
        url:  
          ”~~~“,  
      });  
      // 监听WebSocket错误。  
      uni.onSocketError((res) => {  
        console.log(res, "onSocketError");  
        this.websocketonerror();  
      });  
      // 通过 WebSocket 连接发送数据,需要先 uni.connectSocket,并在 uni.onSocketOpen 回调之后才能发送。  
      // uni.sendSocketMessage((res) => {  
      //    console.log(res.data, 'res.data')  
      // })  
      //监听WebSocket接收到服务器的消息事件。  
      uni.onSocketMessage((res) => {  
        console.log(res);  
        this.websocketonmessage(res);  
      });  
      // 监听WebSocket连接打开事件。  
      uni.onSocketOpen((res) => {  
        this.socketOpen = true;  
        console.log(res);  
        this.websocketonopen();  
      });  
      // 监听WebSocket连接关闭事件。  
      uni.onSocketClose((res) => {  
        this.socketOpen = false;  
        console.log(res);  
      });  
    },

测试2
a端:vue 端 vue
a->b 成功
b-》a 成功

2020-12-04 11:12 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com (作者)

小程序可以了,H5不用uni 就好了

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