jellyfin/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs

61 lines
2.0 KiB
C#
Raw Normal View History

2019-12-27 07:20:27 -07:00
using System;
2014-08-11 07:15:53 -07:00
using System.Threading.Tasks;
using Jellyfin.Data.Events;
2017-10-04 11:51:26 -07:00
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Activity;
using Microsoft.Extensions.Logging;
2014-08-11 07:15:53 -07:00
namespace Jellyfin.Api.WebSocketListeners
2014-08-11 07:15:53 -07:00
{
/// <summary>
/// Class SessionInfoWebSocketListener.
2014-08-11 07:15:53 -07:00
/// </summary>
2019-12-27 07:20:27 -07:00
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener<ActivityLogEntry[], WebSocketListenerState>
2014-08-11 07:15:53 -07:00
{
/// <summary>
/// The _kernel.
2014-08-11 07:15:53 -07:00
/// </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)
2014-08-11 07:15:53 -07:00
{
_activityManager = activityManager;
2019-12-27 07:20:27 -07:00
_activityManager.EntryCreated += OnEntryCreated;
2014-08-11 07:15:53 -07:00
}
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
protected override string Name => "ActivityLogEntry";
2014-08-11 07:15:53 -07:00
/// <summary>
/// Gets the data to send.
/// </summary>
/// <returns>Task{SystemInfo}.</returns>
2019-12-27 07:20:27 -07:00
protected override Task<ActivityLogEntry[]> GetDataToSend()
2014-08-11 07:15:53 -07:00
{
2019-12-27 07:20:27 -07:00
return Task.FromResult(Array.Empty<ActivityLogEntry>());
2014-08-11 07:15:53 -07:00
}
2019-01-07 16:27:46 -07:00
2019-12-27 07:20:27 -07:00
/// <inheritdoc />
2014-08-11 07:15:53 -07:00
protected override void Dispose(bool dispose)
{
2019-12-27 07:20:27 -07:00
_activityManager.EntryCreated -= OnEntryCreated;
2014-08-11 07:15:53 -07:00
base.Dispose(dispose);
}
private void OnEntryCreated(object sender, GenericEventArgs<ActivityLogEntry> e)
{
SendData(true);
}
2014-08-11 07:15:53 -07:00
}
}