升级开发工具稳定版 (1.05.2103190)后, WEB SOCKET 发送数据报错,换回旧版开发工具(1.03.2012120)正常
出错代码
VM213 WAGame.js:2
Uncaught (in promise) FrameworkError
{errMsg: "SocketTask.send:fail SocketTask.readyState is not OPEN"}
errMsg: "SocketTask.send:fail SocketTask.readyState is not OPEN"
__proto__: Object
出错截图
老版本正常截图
//测试WSS的代码
testWss(){
let st = wx.connectSocket({
url: 'wss://xx.xxxxxxx.xxx/xxx-wss'
})
st.onOpen( (res)=> {
console.log('[wss opend]')
})
st.onMessage((data)=>{
console.log('[wss 接收]',data.data)
})
setTimeout(() => {
let data = 'wss你好'
console.log('[wss 发送]',data)
st.send({data})
}, 1000)
st.onError((err)=>{
console.log('[wss 错误]',err)
})
}
服务端代码
const wss = new WebSocket.Server({ 7777, path: '/game-wss' })
wss.on('connection', async (ws, req) => {
ws.on('message', async (message) => {
console.log('ws收: %s', message)
ws.send(message)
})
ws.on('close', async (message) => {
console.log('ws关闭: %s', message)
})
})
问题已复现,我们会尽快进行修复。