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