2019-12-27 09:20:27 -05:00
|
|
|
using System;
|
2014-08-11 10:15:53 -04:00
|
|
|
using System.Threading.Tasks;
|
2020-08-13 20:48:28 -04:00
|
|
|
using Jellyfin.Data.Events;
|
2017-10-04 14:51:26 -04:00
|
|
|
using MediaBrowser.Controller.Net;
|
2019-01-13 14:24:58 -05:00
|
|
|
using MediaBrowser.Model.Activity;
|
2020-09-25 03:25:59 -04:00
|
|
|
using MediaBrowser.Model.Session;
|
2019-01-13 14:24:58 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2014-08-11 10:15:53 -04:00
|
|
|
|
2020-08-03 15:09:32 -04:00
|
|
|
namespace Jellyfin.Api.WebSocketListeners
|
2014-08-11 10:15:53 -04:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// Class SessionInfoWebSocketListener.
|
2014-08-11 10:15:53 -04:00
|
|
|
/// </summary>
|
2020-11-28 03:50:16 -05:00
|
|
|
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener<ActivityLogEntry[], WebSocketListenerState>
|
2014-08-11 10:15:53 -04:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-06-15 18:37:52 -04:00
|
|
|
/// The _kernel.
|
2014-08-11 10:15:53 -04:00
|
|
|
/// </summary>
|
|
|
|
private readonly IActivityManager _activityManager;
|
|
|
|
|
2020-08-03 15:09:32 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ActivityLogWebSocketListener"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="logger">Instance of the <see cref="ILogger{ActivityLogWebSocketListener}"/> interface.</param>
|
|
|
|
/// <param name="activityManager">Instance of the <see cref="IActivityManager"/> interface.</param>
|
|
|
|
public ActivityLogWebSocketListener(ILogger<ActivityLogWebSocketListener> logger, IActivityManager activityManager)
|
|
|
|
: base(logger)
|
2014-08-11 10:15:53 -04:00
|
|
|
{
|
|
|
|
_activityManager = activityManager;
|
2019-12-27 09:20:27 -05:00
|
|
|
_activityManager.EntryCreated += OnEntryCreated;
|
2014-08-11 10:15:53 -04:00
|
|
|
}
|
|
|
|
|
2020-09-25 03:25:59 -04:00
|
|
|
/// <inheritdoc />
|
|
|
|
protected override SessionMessageType Type => SessionMessageType.ActivityLogEntry;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override SessionMessageType StartType => SessionMessageType.ActivityLogEntryStart;
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
protected override SessionMessageType StopType => SessionMessageType.ActivityLogEntryStop;
|
2014-08-11 10:15:53 -04:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the data to send.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Task{SystemInfo}.</returns>
|
2019-12-27 09:20:27 -05:00
|
|
|
protected override Task<ActivityLogEntry[]> GetDataToSend()
|
2014-08-11 10:15:53 -04:00
|
|
|
{
|
2019-12-27 09:20:27 -05:00
|
|
|
return Task.FromResult(Array.Empty<ActivityLogEntry>());
|
2014-08-11 10:15:53 -04:00
|
|
|
}
|
2019-01-07 18:27:46 -05:00
|
|
|
|
2019-12-27 09:20:27 -05:00
|
|
|
/// <inheritdoc />
|
2014-08-11 10:15:53 -04:00
|
|
|
protected override void Dispose(bool dispose)
|
|
|
|
{
|
2019-12-27 09:20:27 -05:00
|
|
|
_activityManager.EntryCreated -= OnEntryCreated;
|
2014-08-11 10:15:53 -04:00
|
|
|
|
|
|
|
base.Dispose(dispose);
|
|
|
|
}
|
2020-08-03 15:09:32 -04:00
|
|
|
|
2020-11-13 11:04:31 -05:00
|
|
|
private void OnEntryCreated(object? sender, GenericEventArgs<ActivityLogEntry> e)
|
2020-08-03 15:09:32 -04:00
|
|
|
{
|
2020-11-27 18:04:13 -05:00
|
|
|
SendData(true).GetAwaiter().GetResult();
|
2020-08-03 15:09:32 -04:00
|
|
|
}
|
2014-08-11 10:15:53 -04:00
|
|
|
}
|
|
|
|
}
|