The socket cannot be reconnected after the applet background is hidden
- Event parameters of the fail callback function when connecting:
connectSocket:fail:jsapi has no permission,event=createSocketTask,runningState=suspend,permissionMsg=permission ok,detail=network api interrupted in suspend state
- Cause of the error: It takes time to switch the foreground in the background of the applet. This error indicates that the applet is not in the foreground and cannot be connected when connected
- Solution: Use recursion in the fail callback function to continuously reconnect until it succeeds
- Note: when recursive, the time difference should be set
fail: function (e) {
console.log('connect fail', e)
setTimeout(() => {
reconnect() // 重连函数
}, 300)
}