jellyfin/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs
2020-08-03 13:09:32 -06:00

61 lines
2.0 KiB
C#

using System;
using System.Threading.Tasks;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.WebSocketListeners
{
/// <summary>
/// Class SessionInfoWebSocketListener.
/// </summary>
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener<ActivityLogEntry[], WebSocketListenerState>
{
/// <summary>
/// The _kernel.
/// </summary>
private readonly IActivityManager _activityManager;
/// <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)
{
_activityManager = activityManager;
_activityManager.EntryCreated += OnEntryCreated;
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
protected override string Name => "ActivityLogEntry";
/// <summary>
/// Gets the data to send.
/// </summary>
/// <returns>Task{SystemInfo}.</returns>
protected override Task<ActivityLogEntry[]> GetDataToSend()
{
return Task.FromResult(Array.Empty<ActivityLogEntry>());
}
/// <inheritdoc />
protected override void Dispose(bool dispose)
{
_activityManager.EntryCreated -= OnEntryCreated;
base.Dispose(dispose);
}
private void OnEntryCreated(object sender, GenericEventArgs<ActivityLogEntry> e)
{
SendData(true);
}
}
}