private async Task DoWorkAsync(object state, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { _timer?.Change(Timeout.Infinite, Timeout.Infinite); return; } // Check follower count & publish to SignalR hub long followerCount = await _streamAnalytics.GetFollowerCountAsync(); if (followerCount != _followerCount) { _followerCount = followerCount; await _overlayHubContext.Clients.All.SendAsync("ReceiveFollowerCount", _followerCount); } // Check viewer count & publish to SignalR hub int viewerCount = await _streamAnalytics.GetViewerCountAsync(); if (viewerCount != _viewerCount) { _viewerCount = viewerCount; await _overlayHubContext.Clients.All.SendAsync("ReceiveViewerCount", _viewerCount); } StreamUserModel lastFollower = await _streamAnalytics.GetLastFollowerAsync(); if (lastFollower != _lastFollower) { _lastFollower = lastFollower; await _overlayHubContext.Clients.All.SendAsync("ReceiveNewFollower", _lastFollower); } }
private async Task UpdateViewerCountAsync() { _currentViewerCount = await _streamAnalytics.GetViewerCountAsync(); }