Example #1
0
 /// <summary>
 /// 释放资源
 /// </summary>
 public void Dispose()
 {
     Console.WriteLine($"开始退出房间【{ROOM_ID}】");
     source.Cancel();
     AuthClient?.CloseAsync();
     DanmuClient?.CloseAsync();
     AuthClient  = null;
     DanmuClient = null;
     if (agent != null)
     {
         agent.RemoveRoom(ROOM_ID);
     }
     Console.WriteLine($"结束监控房间【{ROOM_ID}】");
 }
Example #2
0
        /// <summary>
        /// 初始化连接是否成功
        /// </summary>
        /// <returns></returns>
        public bool Initialization()
        {
            try
            {
                //取消之前正在运行的线程
                if (source != null)
                {
                    source.Cancel();
                }
                source = new CancellationTokenSource();

                agent?.RemoveRoom(ROOM_ID);
                var ips = AgentPool.GetAgentIp(ROOM_ID);
                if (ips.Count > 0)
                {
                    agent = ips[0];
                    Console.WriteLine($"{agent.Ip}:{agent.Port}");
                }
                else
                {
                    agent = null;
                }
                AuthClient?.CloseAsync();
                DanmuClient?.CloseAsync();
                //创建实例
                AuthClient = CreateAuthSocket(source.Token);

                //认证
                Authentication();
                //认证通过开启心跳
                AuthKeepAlive(source.Token);

                DanmuClient = CreateDanmuSocket(source.Token);
                //tcpClient = SocketHelper.InitTcp(agent.Ip, agent.Port);
                //ConnectProxyServer(SERVER_DOMAIN, SERVER_PORT, tcpClient);

                //登录房间
                RoomLogin();
                //心跳维持
                DanmmuKeepAlive(source.Token);
                AppLog.Debug($"监控房间【{ROOM_ID}】成功");
                return(true);
            }
            catch (Exception ex)
            {
                AppLog.Error($"【房间:{ROOM_ID}】【监控失败】", ex);
                return(false);
            }
        }