async Task <TwitchChannel> Connect(string channelName) { Debug.Assert(m_channel == null); var twitch = new TwitchConnection(ClientType.Full); var connection = twitch.ConnectAsync(m_options.User, m_options.Pass); var channel = JoinChannel(twitch, channelName); var result = await connection; if (result == ConnectResult.LoginFailed) { WriteStatus("Failed to login, please change options.ini and restart the application."); return(null); } while (result != ConnectResult.Connected) { if (result == ConnectResult.LoginFailed) { WriteStatus("Failed to login, please change options.ini and restart the application."); return(null); } else if (result == ConnectResult.NetworkError) { if (!NativeMethods.IsConnectedToInternet()) { WriteStatus("Not connected to the internet."); do { await Task.Delay(5000); } while (!NativeMethods.IsConnectedToInternet()); WriteStatus("Re-connected to the internet."); } else { WriteStatus("Failed to connect: network error"); } } await Task.Delay(5000); result = await twitch.ConnectAsync(m_options.User, m_options.Pass); } await channel.JoinAsync(); WriteStatus("Connected to channel {0}.", channel.Name); return(channel); }
public void ConnectAsync() { if (!string.IsNullOrEmpty(Settings.Default.UserName) && !string.IsNullOrEmpty(Settings.Default.AccessToken) && !string.IsNullOrEmpty(Settings.Default.Channel)) { client.ConnectAsync(); } else { throw new ArgumentException(); } }