using System;
using System.Threading.Tasks;
using Jellyfin.Data.Events;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Session;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.WebSocketListeners
{
///
/// Class SessionInfoWebSocketListener.
///
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener
{
///
/// The _kernel.
///
private readonly IActivityManager _activityManager;
///
/// Initializes a new instance of the class.
///
/// Instance of the interface.
/// Instance of the interface.
public ActivityLogWebSocketListener(ILogger logger, IActivityManager activityManager)
: base(logger)
{
_activityManager = activityManager;
_activityManager.EntryCreated += OnEntryCreated;
}
///
protected override SessionMessageType Type => SessionMessageType.ActivityLogEntry;
///
protected override SessionMessageType StartType => SessionMessageType.ActivityLogEntryStart;
///
protected override SessionMessageType StopType => SessionMessageType.ActivityLogEntryStop;
///
/// Gets the data to send.
///
/// Task{SystemInfo}.
protected override Task GetDataToSend()
{
return Task.FromResult(Array.Empty());
}
///
protected override void Dispose(bool dispose)
{
_activityManager.EntryCreated -= OnEntryCreated;
base.Dispose(dispose);
}
private void OnEntryCreated(object? sender, GenericEventArgs e)
{
SendData(true).GetAwaiter().GetResult();
}
}
}