微信小游戏websocket切后台返回后,部分机型无法重连

代码是官方示例代码
let ws = new WebSocket(“ws://echo.websocket.org”);
ws.onopen = function (event) {
console.log(“Send Text WS was opened.”);
};
ws.onmessage = function (event) {
console.log("response text msg: " + event.data);
};
ws.onerror = function (event) {
console.log(“Send Text fired an error”);
};
ws.onclose = function (event) {
console.log(“WebSocket instance closed.”);
};

有的机型例如红米Note7, 切后台几秒后, 触发了onclose方法, 如果再执行一次上面的代码则触发onerror方法, 控制台输出Send Text fired an error.

检查你ws.send的ws用的是不是后来new的ws,有可能使用之前断链,所以发送的时候就报错了

我觉得不是, 因为有的手机是正常运行, 有的手机不行. ws都是新的ws

自己顶一下