2021-12-19 13:44:22 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
using Selector.Web.Hubs;
|
2021-12-19 18:44:03 +00:00
|
|
|
|
using Selector.Events;
|
2023-01-22 10:28:52 +00:00
|
|
|
|
using Selector.SignalR;
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
|
|
|
|
namespace Selector.Web.Service
|
|
|
|
|
{
|
|
|
|
|
public class NowPlayingHubMapping: IEventHubMapping<NowPlayingHub, INowPlayingHubClient>
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<NowPlayingHubMapping> Logger;
|
|
|
|
|
private readonly UserEventBus UserEvent;
|
|
|
|
|
private readonly IHubContext<NowPlayingHub, INowPlayingHubClient> Hub;
|
|
|
|
|
|
|
|
|
|
public NowPlayingHubMapping(ILogger<NowPlayingHubMapping> logger,
|
|
|
|
|
UserEventBus userEvent,
|
|
|
|
|
IHubContext<NowPlayingHub, INowPlayingHubClient> hub)
|
|
|
|
|
{
|
|
|
|
|
Logger = logger;
|
|
|
|
|
UserEvent = userEvent;
|
|
|
|
|
Hub = hub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task ConstructMapping()
|
|
|
|
|
{
|
|
|
|
|
Logger.LogDebug("Forming now playing event mapping between event bus and SignalR hub");
|
|
|
|
|
|
|
|
|
|
UserEvent.CurrentlyPlaying += async (o, args) =>
|
|
|
|
|
{
|
2021-12-21 22:22:52 +00:00
|
|
|
|
Logger.LogDebug("Passing now playing event to SignalR hub [{userId}]", args.UserId);
|
2021-12-19 13:44:22 +00:00
|
|
|
|
|
2021-12-21 22:22:52 +00:00
|
|
|
|
await Hub.Clients.User(args.UserId).OnNewPlaying(args);
|
2021-12-19 13:44:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|