Beispiel #1
0
        private static void TwitchConnect()
        {
            string oAuthKey = iniFile.Section("Twitch").Get("OAuthKey");
            string clientID = iniFile.Section("Twitch").Get("ClientID");

            try
            {
                var    tempClient = new TwitchAuthenticatedClient(oAuthKey, clientID);
                string username   = tempClient.GetMyChannel().Name;
                client = new TwitchNamedClient(username, oAuthKey, clientID);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        private void ConnectStreamer()
        {
            try
            {
                streamerChat.Abort();
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception)
            {
            }

            // Twitch Credentials
            accountStreamer = new TwitchCredentials(Config.StreamerUsername, Config.StreamerOAuthKey);

            // Start Streamer connection and login
            streamerChatConnection = new TwitchChatConnection(accountStreamer, false);
            streamerChatConnection.JoinChannel(Config.ChannelName);

            // Create threads for the chat connections
            streamerChat = new Thread(new ThreadStart(streamerChatConnection.Run))
            {
                IsBackground = true
            };

            // Start the chat connection threads
            streamerChat.Start();

            // TODO check on success login/connection
            if (true)
            {
                // Disable Settings UI elements
                textBoxStreamerName.IsEnabled   = false;
                buttonStreamerConnect.IsEnabled = false;
                cbAutoConnectStreamer.IsEnabled = false;
                btnStreamerConnect.Content      = "Disconnect";

                // Enable Twitch Dashboard tab
                tabMainDashboard.IsEnabled = true;

                try
                {
                    client             = new TwitchAuthenticatedClient(Config.StreamerOAuthKey, Config.TwitchClientID);
                    txtTitle.Text      = Utils.GetClient().GetMyChannel().Status;
                    cbGame.Text        = Utils.GetClient().GetMyChannel().Game;
                    tbStreamDelay.Text = Utils.GetClient().GetMyChannel().Delay.ToString();

                    // Get Streamers Avatar
                    using (WebClient wc = new WebClient())
                    {
                        BitmapImage logo = new BitmapImage();
                        logo.BeginInit();
                        logo.StreamSource = wc.OpenRead(client.GetMyChannel().Logo);
                        logo.CacheOption  = BitmapCacheOption.OnLoad;
                        logo.EndInit();
                        imgLogo.Source = logo;
                    }

                    // Enable partnered elements when partnered
                    if (client.GetMyUser().Partnered)
                    {
                        // Stream delay
                        tbStreamDelay.IsEnabled = true;

                        // Manual Commercials
                        gbManualCommercials.IsEnabled = true;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }