< Summary - Jellyfin

Information
Class: Jellyfin.Api.WebSocketListeners.ActivityLogWebSocketListener
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs
Line coverage
37%
Covered lines: 6
Uncovered lines: 10
Coverable lines: 16
Total lines: 88
Line coverage: 37.5%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Type()100%210%
get_StartType()100%210%
get_StopType()100%210%
GetDataToSend()100%210%
Start(...)0%4260%
OnEntryCreated(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using Jellyfin.Data;
 4using Jellyfin.Data.Events;
 5using Jellyfin.Database.Implementations.Enums;
 6using MediaBrowser.Controller.Authentication;
 7using MediaBrowser.Controller.Net;
 8using MediaBrowser.Model.Activity;
 9using MediaBrowser.Model.Session;
 10using Microsoft.Extensions.Logging;
 11
 12namespace Jellyfin.Api.WebSocketListeners;
 13
 14/// <summary>
 15/// Class ActivityLogWebSocketListener.
 16/// </summary>
 17public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener<ActivityLogEntry[], WebSocketListenerState>
 18{
 19    /// <summary>
 20    /// The _kernel.
 21    /// </summary>
 22    private readonly IActivityManager _activityManager;
 23
 24    private bool _disposed;
 25
 26    /// <summary>
 27    /// Initializes a new instance of the <see cref="ActivityLogWebSocketListener"/> class.
 28    /// </summary>
 29    /// <param name="logger">Instance of the <see cref="ILogger{ActivityLogWebSocketListener}"/> interface.</param>
 30    /// <param name="activityManager">Instance of the <see cref="IActivityManager"/> interface.</param>
 31    public ActivityLogWebSocketListener(ILogger<ActivityLogWebSocketListener> logger, IActivityManager activityManager)
 1932        : base(logger)
 33    {
 1934        _activityManager = activityManager;
 1935        _activityManager.EntryCreated += OnEntryCreated;
 1936    }
 37
 38    /// <inheritdoc />
 039    protected override SessionMessageType Type => SessionMessageType.ActivityLogEntry;
 40
 41    /// <inheritdoc />
 042    protected override SessionMessageType StartType => SessionMessageType.ActivityLogEntryStart;
 43
 44    /// <inheritdoc />
 045    protected override SessionMessageType StopType => SessionMessageType.ActivityLogEntryStop;
 46
 47    /// <summary>
 48    /// Gets the data to send.
 49    /// </summary>
 50    /// <returns>Task{SystemInfo}.</returns>
 51    protected override Task<ActivityLogEntry[]> GetDataToSend()
 52    {
 053        return Task.FromResult(Array.Empty<ActivityLogEntry>());
 54    }
 55
 56    /// <inheritdoc />
 57    protected override async ValueTask DisposeAsyncCore()
 58    {
 59        if (!_disposed)
 60        {
 61            _activityManager.EntryCreated -= OnEntryCreated;
 62            _disposed = true;
 63        }
 64
 65        await base.DisposeAsyncCore().ConfigureAwait(false);
 66    }
 67
 68    /// <summary>
 69    /// Starts sending messages over an activity log web socket.
 70    /// </summary>
 71    /// <param name="message">The message.</param>
 72    protected override void Start(WebSocketMessageInfo message)
 73    {
 074        if (!message.Connection.AuthorizationInfo.IsApiKey
 075            && (message.Connection.AuthorizationInfo.User is null
 076                || !message.Connection.AuthorizationInfo.User.HasPermission(PermissionKind.IsAdministrator)))
 77        {
 078            throw new AuthenticationException("Only admin users can retrieve the activity log.");
 79        }
 80
 081        base.Start(message);
 082    }
 83
 84    private void OnEntryCreated(object? sender, GenericEventArgs<ActivityLogEntry> e)
 85    {
 3486        SendData(true);
 3487    }
 88}