Selector/Selector.Web/Hubs/NowPlayingHub.cs

46 lines
1.3 KiB
C#
Raw Normal View History

2021-10-31 19:55:00 +00:00
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using SpotifyAPI.Web;
using StackExchange.Redis;
2021-10-31 19:55:00 +00:00
using Selector.Cache;
using System.Text.Json;
2021-10-31 19:55:00 +00:00
namespace Selector.Web.Hubs
{
public interface INowPlayingHubClient
{
public Task OnNewPlaying(CurrentlyPlayingDTO context);
// public Task OnNewAudioFeature(TrackAudioFeatures features);
2021-10-31 19:55:00 +00:00
}
public class NowPlayingHub: Hub<INowPlayingHubClient>
{
private readonly IDatabaseAsync Cache;
// private readonly AudioFeaturePuller AudioFeaturePuller;
public NowPlayingHub(IDatabaseAsync cache)
{
Cache = cache;
}
public async Task OnConnected()
{
await SendNewPlaying();
}
public async Task SendNewPlaying()
2021-10-31 19:55:00 +00:00
{
var nowPlaying = await Cache.StringGetAsync(Key.CurrentlyPlaying(Context.UserIdentifier));
var deserialised = JsonSerializer.Deserialize<CurrentlyPlayingDTO>(nowPlaying);
await Clients.Caller.OnNewPlaying(deserialised);
2021-10-31 19:55:00 +00:00
}
// public async Task SendAudioFeatures(string trackId)
// {
// await Clients.Caller.OnNewAudioFeature(await AudioFeaturePuller.Get(trackId));
// }
2021-10-31 19:55:00 +00:00
}
}