- 当前 Bug 的表现(可附上截图)
在打开调试下 可以进行wx.connectSocket能连接上
非调试下wx.connectSocket连接不上
- 预期表现
在调试和非调试下 wx.connectSocket都能进行连接
- 复现路径
关闭调试 wx.connectSocket就连接不上
- 提供一个最简复现 Demo
connectTvSocket:function(){
console.log(‘connectTvSocket’)
var me = this;
wx.closeSocket();
console.log(‘当前要连地址’ + me.data.ipInputValue)
// me.data.ipInputValue
wx.connectSocket({
url: ‘ws://’ + me.data.ipInputValue + ‘:19110’,
data: {
x: ‘’,
y: ‘’
},
header: {
‘content-type’: ‘application/json’
},
// protocols: [‘Sec-WebSocket-Protocol’],
method: ‘GET’,
success: function (res) {
console.log(‘连接成功111’ + res)
},
fail: function (res) {
console.log(‘连接失败111’ + res)
}
});
wx.onSocketOpen(function (res) {
console.log(me.data.ipInputValue +‘连接已打开!’ )
// 对ip地址进行存储
wx.setStorage({
key: ‘ipKey’,
data: me.data.ipInputValue
})
wx.showToast({
title: ‘成功’,
icon: ‘success’,
duration: 2000
})
me.socketOpen = true
me.setData({
motto: me.data.ipInputValue + ‘连接已打开!’
});
})
wx.onSocketClose(function (callBack) {
console.log(‘websocket关闭’)
wx.showToast({
title: ‘失败’,
icon: ‘failure’,
duration: 2000
})
me.socketOpen = false
me.setData({ motto: ‘点击连接’ });
});
wx.onSocketError(function (res) {
console.log(‘WebSocket连接打开失败,请检查!’ + res)
me.setData({
motto: ‘点击’
});
})
wx.onSocketMessage(function (res) {
console.log(‘收到服务器内容:’ + res.data)
})
},
//控制键的处理事件///////////////////////////////////////////////////////////////////////
upTvEvent:function(){
console.log('top handling ')
// wx.vibrateLong()
wx.sendSocketMessage({
data: ‘{“CONTROLup”}’,
success: function(res) {
console.log(‘成功’)
},
fail: function(res) {
console.log(‘失败’)
},
complete: function(res) {},
})
},
letvTvEvent:function(){
console.log(‘muteTvEven’)
wx.sendSocketMessage({
data: ‘{“CONTROL_Aall_le”}’,
success: function (res) {
console.log(‘成功’)
},
fail: function (res) {
console.log(‘失败’)
},
complete: function (res) { },
})
},