青梧
青梧
  • 发布:2019-12-03 19:01
  • 更新:2020-08-14 13:53
  • 阅读:2648

websocket onMessage 无法触发 网页版没问题

分类:HBuilderX

发送消息什么的都没问题

贴上我得代码
这是uniapp 的

var _this = this;
this.socketTask = socket.connectSocket({
url:'wss://im.xxx.com/websocket',
success: ()=> {
console.log('链接websocket成功')
},
fail:()=>{
console.log('websocket 链接失败');
}
});
this.socketTask.onOpen(function (res) {
_this.socketOpen = true;
for (var i = 0; i < _this.socketMsgQueue.length; i++) {
_this.send_msg(_this.socketMsgQueue[i]);
}
_this.socketMsgQueue = [];
console.log('WebSocket连接已打开!');
_this.php_connect();
// _this.rev_msg();
_this.socketTask.onMessage(function (res) {
console.log('收到服务器内容:' + res.data);
// _this.get_chat_list();
});
console.log(123);
});
_this.socketTask.onError(function (res) {
// _this.socketOpen = false;
console.log(res)
console.log('WebSocket连接打开失败,请检查!');
});

			_this.socketTask.onClose(function (res) {  
				_this.socketOpen = false;  
			  console.log('WebSocket 已关闭!');  
			});  
			uni.onSocketMessage(function (res) {  
			      console.log('收到服务器内容:' + res.data);  
			 });
2019-12-03 19:01 负责人:无 分享
已邀请:
清风袭来

清风袭来

一样问题,以前都没这个问题更新着更新着突然就有了

  • lovnie

    请问解决了吗


    2021-03-18 18:47

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