public void ClearCache() { LiveStreams.Clear(); _nameBasedMonitor?.ClearCache(); _nameBasedMonitor = null; _idBasedMonitor = null; }
public async IAsyncEnumerable <string> WaitForStreamerOnline() { await FindChannelsIds(); List <string> streamerIds = _streamers.Values.ToList(); Dictionary <string, bool> liveStatus = new Dictionary <string, bool>(); foreach (string channelId in _streamers.Values) { liveStatus.Add(channelId, true); } while (true) { LiveStreams liveStreams = null; try { liveStreams = await _twitch.V5.Streams.GetLiveStreamsAsync(streamerIds); } catch (Exception e) { Console.WriteLine(e); continue; } var liveStreamsIds = liveStreams.Streams.Select(s => s.Channel.Id); foreach (string channelId in _streamers.Values) { if (!liveStreamsIds.Contains(channelId)) { liveStatus[channelId] = false; continue; } if (!liveStatus[channelId]) { liveStatus[channelId] = true; yield return(_streamers.First(kvp => kvp.Value == channelId).Key); } } await Task.Delay(30_000); } }
private void HandleOfflineStreamUpdate(string channel, bool callEvents) { var wasAlreadyLive = LiveStreams.TryGetValue(channel, out var cachedLiveStream); if (!wasAlreadyLive) { return; } LiveStreams.Remove(channel); if (!callEvents) { return; } OnStreamOffline?.Invoke(this, new OnStreamOfflineArgs { Channel = channel, Stream = cachedLiveStream }); }
private void HandleLiveStreamUpdate(string channel, Stream liveStream, bool callEvents) { var wasAlreadyLive = LiveStreams.ContainsKey(channel); LiveStreams[channel] = liveStream; if (!callEvents) { return; } if (!wasAlreadyLive) { OnStreamOnline?.Invoke(this, new OnStreamOnlineArgs { Channel = channel, Stream = liveStream }); } else { OnStreamUpdate?.Invoke(this, new OnStreamUpdateArgs { Channel = channel, Stream = liveStream }); } }