Ejemplo n.º 1
0
        public void ClearCache()
        {
            LiveStreams.Clear();

            _nameBasedMonitor?.ClearCache();

            _nameBasedMonitor = null;
            _idBasedMonitor   = null;
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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
            });
        }
Ejemplo n.º 4
0
        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
                });
            }
        }