收藏
回答

游戏服务里。GameServerManager.onDisconnect 会不断重复的触发吗?

回答关注问题邀请回答
收藏

1 个回答

  • Niko
    Niko
    03-01
           this.server.onDisconnect((res) => {
                console.log('onDisconnect', res);
                this.isDisconnect = true;
                res.type !== "game" && wx.showToast({
                    title: "游戏已掉线...",
                    icon: "none",
                    duration: 2e3
                });
                res.type === "game" && function(that) {
                    function relink() {
                        that.server.reconnect().then(function(res) {
                            console.log("networkType change or onShow -> reconnect", res);
                            ++that.reconnectSuccess;
                        }).catch(relink);
                    }
                    relink();
                }(this);
            });
    
    
    03-01
    有用
    回复 1
    • Niko
      Niko
      03-01
      参考官方的代码处理。
      03-01
      回复
登录 后发表内容