2019-11-01 10:38:54 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-06 13:50:43 -07:00
|
|
|
using System;
|
2016-06-07 23:21:13 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
2019-01-27 07:40:37 -07:00
|
|
|
using System.Threading.Tasks;
|
2020-05-12 19:10:35 -07:00
|
|
|
using Jellyfin.Data.Enums;
|
2020-08-13 17:48:28 -07:00
|
|
|
using Jellyfin.Data.Events;
|
2016-06-07 23:21:13 -07:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.LiveTv;
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
using MediaBrowser.Controller.Session;
|
2020-09-25 00:25:59 -07:00
|
|
|
using MediaBrowser.Model.Session;
|
2018-12-13 06:18:25 -07:00
|
|
|
using Microsoft.Extensions.Logging;
|
2016-06-07 23:21:13 -07:00
|
|
|
|
2016-11-03 15:06:00 -07:00
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-02-06 07:20:23 -07:00
|
|
|
public sealed class RecordingNotifier : IServerEntryPoint
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
|
|
|
private readonly ILiveTvManager _liveTvManager;
|
|
|
|
private readonly ISessionManager _sessionManager;
|
|
|
|
private readonly IUserManager _userManager;
|
2020-06-05 17:15:56 -07:00
|
|
|
private readonly ILogger<RecordingNotifier> _logger;
|
2016-06-07 23:21:13 -07:00
|
|
|
|
2020-03-03 15:07:10 -07:00
|
|
|
public RecordingNotifier(
|
|
|
|
ISessionManager sessionManager,
|
|
|
|
IUserManager userManager,
|
|
|
|
ILogger<RecordingNotifier> logger,
|
|
|
|
ILiveTvManager liveTvManager)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
|
|
|
_sessionManager = sessionManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
_logger = logger;
|
|
|
|
_liveTvManager = liveTvManager;
|
|
|
|
}
|
|
|
|
|
2020-02-19 13:04:28 -07:00
|
|
|
/// <inheritdoc />
|
2019-01-27 07:40:37 -07:00
|
|
|
public Task RunAsync()
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-02-19 13:04:28 -07:00
|
|
|
_liveTvManager.TimerCancelled += OnLiveTvManagerTimerCancelled;
|
|
|
|
_liveTvManager.SeriesTimerCancelled += OnLiveTvManagerSeriesTimerCancelled;
|
2020-02-06 07:20:23 -07:00
|
|
|
_liveTvManager.TimerCreated += OnLiveTvManagerTimerCreated;
|
|
|
|
_liveTvManager.SeriesTimerCreated += OnLiveTvManagerSeriesTimerCreated;
|
2019-01-27 07:40:37 -07:00
|
|
|
|
|
|
|
return Task.CompletedTask;
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:48:28 -07:00
|
|
|
private async void OnLiveTvManagerSeriesTimerCreated(object sender, GenericEventArgs<TimerEventInfo> e)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-09-25 00:25:59 -07:00
|
|
|
await SendMessage(SessionMessageType.SeriesTimerCreated, e.Argument).ConfigureAwait(false);
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:48:28 -07:00
|
|
|
private async void OnLiveTvManagerTimerCreated(object sender, GenericEventArgs<TimerEventInfo> e)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-09-25 00:25:59 -07:00
|
|
|
await SendMessage(SessionMessageType.TimerCreated, e.Argument).ConfigureAwait(false);
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:48:28 -07:00
|
|
|
private async void OnLiveTvManagerSeriesTimerCancelled(object sender, GenericEventArgs<TimerEventInfo> e)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-09-25 00:25:59 -07:00
|
|
|
await SendMessage(SessionMessageType.SeriesTimerCancelled, e.Argument).ConfigureAwait(false);
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2020-08-13 17:48:28 -07:00
|
|
|
private async void OnLiveTvManagerTimerCancelled(object sender, GenericEventArgs<TimerEventInfo> e)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-09-25 00:25:59 -07:00
|
|
|
await SendMessage(SessionMessageType.TimerCancelled, e.Argument).ConfigureAwait(false);
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
|
2020-09-25 00:25:59 -07:00
|
|
|
private async Task SendMessage(SessionMessageType name, TimerEventInfo info)
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-05-12 19:10:35 -07:00
|
|
|
var users = _userManager.Users.Where(i => i.HasPermission(PermissionKind.EnableLiveTvAccess)).Select(i => i.Id).ToList();
|
2016-06-07 23:21:13 -07:00
|
|
|
|
2016-08-20 11:43:13 -07:00
|
|
|
try
|
2016-06-07 23:21:13 -07:00
|
|
|
{
|
2020-02-06 07:20:23 -07:00
|
|
|
await _sessionManager.SendMessageToUserSessions(users, name, info, CancellationToken.None).ConfigureAwait(false);
|
2016-08-20 11:43:13 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2018-12-20 05:11:26 -07:00
|
|
|
_logger.LogError(ex, "Error sending message");
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 07:20:23 -07:00
|
|
|
/// <inheritdoc />
|
2016-06-07 23:21:13 -07:00
|
|
|
public void Dispose()
|
|
|
|
{
|
2020-02-19 13:04:28 -07:00
|
|
|
_liveTvManager.TimerCancelled -= OnLiveTvManagerTimerCancelled;
|
|
|
|
_liveTvManager.SeriesTimerCancelled -= OnLiveTvManagerSeriesTimerCancelled;
|
2020-02-06 07:20:23 -07:00
|
|
|
_liveTvManager.TimerCreated -= OnLiveTvManagerTimerCreated;
|
|
|
|
_liveTvManager.SeriesTimerCreated -= OnLiveTvManagerSeriesTimerCreated;
|
2016-06-07 23:21:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|