예제 #1
0
 private static void PubSub_OnPongReceived(object sender, System.EventArgs e)
 {
     System.Console.WriteLine("PONG");
     Task.Run(async() =>
     {
         await Task.Delay(1000 * 60 * 3);
         await pubSub.Ping();
     });
 }
예제 #2
0
        public static void Main(string[] args)
        {
            Task.Run(async() =>
            {
                try
                {
                    Logger.SetLogLevel(LogLevel.Debug);
                    Logger.LogOccurred += Logger_LogOccurred;

                    System.Console.WriteLine("Connecting to Twitch...");

                    connection = TwitchConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes).Result;
                    if (connection != null)
                    {
                        System.Console.WriteLine("Twitch connection successful!");

                        user = await connection.NewAPI.Users.GetCurrentUser();
                        if (user != null)
                        {
                            System.Console.WriteLine("Logged in as: " + user.display_name);

                            System.Console.WriteLine("Connecting to PubSub...");

                            pubSub = new PubSubClient(connection);

                            pubSub.OnDisconnectOccurred += PubSub_OnDisconnectOccurred;
                            pubSub.OnSentOccurred       += PubSub_OnSentOccurred;
                            pubSub.OnReconnectReceived  += PubSub_OnReconnectReceived;
                            pubSub.OnResponseReceived   += PubSub_OnResponseReceived;
                            pubSub.OnMessageReceived    += PubSub_OnMessageReceived;
                            pubSub.OnWhisperReceived    += PubSub_OnWhisperReceived;
                            pubSub.OnPongReceived       += PubSub_OnPongReceived;

                            await pubSub.Connect();

                            await Task.Delay(1000);

                            List <PubSubListenTopicModel> topics = new List <PubSubListenTopicModel>();
                            foreach (PubSubTopicsEnum topic in EnumHelper.GetEnumList <PubSubTopicsEnum>())
                            {
                                topics.Add(new PubSubListenTopicModel(topic, user.id));
                            }

                            await pubSub.Listen(topics);

                            await Task.Delay(1000);

                            await pubSub.Ping();

                            while (true)
                            {
                                System.Console.ReadLine();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            }).Wait();

            System.Console.ReadLine();
        }