Example #1
0
 public static void GetRoomsForChannelAsync(TwitchChannel channel, Action <bool, TwitchChannel> onCompleted)
 {
     Task.Run(() =>
     {
         bool success = GetRoomsForChannel(channel) != null;
         onCompleted?.Invoke(success, channel);
     });
 }
Example #2
0
        public static List <TwitchRoom> GetRoomsForChannel(TwitchChannel channel)
        {
            if (!TwitchWebSocketClient.LoggedIn)
            {
                return(null);
            }

            Plugin.Log($"Getting rooms for channel {channel.name}");

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://api.twitch.tv/kraken/chat/{channel.roomId}/rooms");
                request.Credentials = CredentialCache.DefaultCredentials;

                request.Method = "GET";
                request.Accept = "application/vnd.twitchtv.v5+json";
                request.Headers.Set("Authorization", $"OAuth {TwitchLoginConfig.Instance.TwitchOAuthToken.Replace("oauth:", "")}");
                request.Headers.Set("Client-ID", ClientId);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream       dataStream = response.GetResponseStream();
                    StreamReader reader     = new StreamReader(dataStream);

                    channel.rooms = TwitchRoom.FromJson(reader.ReadToEnd());

                    foreach (TwitchRoom r in channel.rooms)
                    {
                        Plugin.Log($"Room: {r.name}, ChannelName: {r.channelName}");
                    }

                    reader.Close();
                }
                response.Close();
            }
            catch (Exception ex)
            {
                Plugin.Log(ex.ToString());
            }
            return(channel.rooms);
        }