/// <summary>
        /// 初始化实时消息客户端
        /// </summary>
        /// <param name="config"></param>
        public AVRealtime(Configuration config)
        {
            lock (mutex)
            {
                if ((int)config.OfflineMessageStrategy == 0)
                {
                    config.OfflineMessageStrategy = OfflineMessageStrategy.UnreadAck;
                }

                CurrentConfiguration = config;
                if (CurrentConfiguration.WebSocketClient != null)
                {
                    webSocketController = CurrentConfiguration.WebSocketClient;
                }
                if (CurrentConfiguration.SignatureFactory != null)
                {
                    this.SignatureFactory = CurrentConfiguration.SignatureFactory;
                }
                ReconnectOptions = new AVIMReconnectOptions()
                {
                    Interval = 5,
                    Retry    = 120
                };


                RegisterMessageType <AVIMMessage>();
                RegisterMessageType <AVIMTypedMessage>();
                RegisterMessageType <AVIMTextMessage>();
                RegisterMessageType <AVIMImageMessage>();
                RegisterMessageType <AVIMAudioMessage>();
                RegisterMessageType <AVIMVideoMessage>();
                RegisterMessageType <AVIMFileMessage>();
                RegisterMessageType <AVIMLocationMessage>();
                RegisterMessageType <AVIMRecalledMessage>();

                // 注册服务端 goaway 指令
                var goAwayListener = new GoAwayListener();
                goAwayListener.OnGoAway += () => {
                    RouterController.ClearCache().ContinueWith(_ => {
                        reborn = true;
                        // 关闭 WebSocket
                        AVWebSocketClient.Disconnect();
                    });
                };
                SubscribeNoticeReceived(goAwayListener);

                reconnectTimes = 0;
            }
        }
 void PrepareReconnect()
 {
     AVRealtime.PrintLog("Prepare Reconnect");
     Task.Delay(RECONNECT_DELAY).ContinueWith(_ => {
         // 开启重连
         AutoReconnect().ContinueWith(t => {
             if (t.IsFaulted)
             {
                 // 重连失败,延迟再次重连
                 reconnectTimes++;
                 AVRealtime.PrintLog(String.Format("reconnect {0} times", reconnectTimes));
                 if (reconnectTimes >= RECONNECT_FROM_APP_ROUTER)
                 {
                     // 如果大于当前服务地址的最大重连次数,则清空 Router 后重新重连
                     RouterController.ClearCache().ContinueWith(__ => {
                         reborn = true;
                         PrepareReconnect();
                     });
                 }
                 else if (reconnectTimes >= RECONNECT_USE_SECONDARY_TIMES)
                 {
                     // 如果大于单台 IM 服务器的重连次数,则启用备用服务器
                     useSecondary = true;
                     PrepareReconnect();
                 }
                 else
                 {
                     PrepareReconnect();
                 }
             }
             else
             {
                 // 重连成功
                 reconnectTimes = 0;
                 reborn         = false;
                 useSecondary   = false;
             }
         });
     });
 }