小程序
小游戏
企业微信
微信支付
扫描小程序码分享
- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
多次重连WebSocket,之后连接WebSocket ,wx.connectSocket有成功回调,但是wx.onSocketOpen没有被调用,最后返回的错误是errMsg:connect response time out
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
onClose之后WebSocket重新初始化
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
好的,谢谢
怎么重新初始化
initSocket() {
let that =
this
that.globalData.localSocket = wx.connectSocket({
url:
'wss://xxxx.com'
})
that.globalData.localSocket.onOpen(
function
(res) {
//console.log('WebSocket连接已打开!readyState=' + that.globalData.localSocket.readyState);
while
(socketMsgQueue.length > 0) {
var
msg = socketMsgQueue.shift();
that.sendSocketMessage(msg);
}
that.globalData.localSocket.onMessage(
that.globalData.callback(res)
that.globalData.localSocket.onError(
//console.log('readyState=' + that.globalData.localSocket.readyState)
that.globalData.localSocket.onClose(
//console.log('WebSocket连接已关闭!readyState=' + that.globalData.localSocket.readyState)
that.initSocket()
},
//统一发送消息
sendSocketMessage:
(msg) {
if
(
.globalData.localSocket.readyState === 1) {
.globalData.localSocket.send({
data: JSON.stringify(msg)
else
{
socketMsgQueue.push(msg)
我的代码片段
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
可以帮忙看看吗,急着上线
android 还是 iOS?
安卓,华为手机
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
onClose之后WebSocket重新初始化
好的,谢谢
怎么重新初始化
initSocket() {
let that =
this
that.globalData.localSocket = wx.connectSocket({
url:
'wss://xxxx.com'
})
that.globalData.localSocket.onOpen(
function
(res) {
//console.log('WebSocket连接已打开!readyState=' + that.globalData.localSocket.readyState);
while
(socketMsgQueue.length > 0) {
var
msg = socketMsgQueue.shift();
that.sendSocketMessage(msg);
}
})
that.globalData.localSocket.onMessage(
function
(res) {
that.globalData.callback(res)
})
that.globalData.localSocket.onError(
function
(res) {
//console.log('readyState=' + that.globalData.localSocket.readyState)
})
that.globalData.localSocket.onClose(
function
(res) {
//console.log('WebSocket连接已关闭!readyState=' + that.globalData.localSocket.readyState)
that.initSocket()
})
},
//统一发送消息
sendSocketMessage:
function
(msg) {
if
(
this
.globalData.localSocket.readyState === 1) {
this
.globalData.localSocket.send({
data: JSON.stringify(msg)
})
}
else
{
socketMsgQueue.push(msg)
}
},
我的代码片段
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
可以帮忙看看吗,急着上线
android 还是 iOS?
安卓,华为手机