The Free Software Media System - Server Backend & API
Use SessionMessageType for WebSocket messages
Niels van Velzen72534f9d667f
diff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.csindex 460ac2d8d1..d09a11930d 100644--- a/Emby.Dlna/PlayTo/PlayToController.cs+++ b/Emby.Dlna/PlayTo/PlayToController.cs@@ -811,7 +811,7 @@ namespace Emby.Dlna.PlayTo}/// <inheritdoc />- public Task SendMessage<T>(string name, Guid messageId, T data, CancellationToken cancellationToken)+ public Task SendMessage<T>(SessionMessageType name, Guid messageId, T data, CancellationToken cancellationToken){if (_disposed){@@ -823,17 +823,17 @@ namespace Emby.Dlna.PlayToreturn Task.CompletedTask;}- if (string.Equals(name, "Play", StringComparison.OrdinalIgnoreCase))+ if (name == SessionMessageType.Play){return SendPlayCommand(data as PlayRequest, cancellationToken);}- if (string.Equals(name, "PlayState", StringComparison.OrdinalIgnoreCase))+ if (name == SessionMessageType.PlayState){return SendPlaystateCommand(data as PlaystateRequest, cancellationToken);}- if (string.Equals(name, "GeneralCommand", StringComparison.OrdinalIgnoreCase))+ if (name == SessionMessageType.GeneralCommand){return SendGeneralCommand(data as GeneralCommand, cancellationToken);}diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.csindex c9d21d9638..ff64e217a0 100644--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs@@ -16,6 +16,7 @@ using MediaBrowser.Controller.Plugins;using MediaBrowser.Controller.Providers;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Entities;+using MediaBrowser.Model.Session;using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.EntryPoints@@ -105,7 +106,7 @@ namespace Emby.Server.Implementations.EntryPointstry{- _sessionManager.SendMessageToAdminSessions("RefreshProgress", dict, CancellationToken.None);+ _sessionManager.SendMessageToAdminSessions(SessionMessageType.RefreshProgress, dict, CancellationToken.None);}catch{@@ -123,7 +124,7 @@ namespace Emby.Server.Implementations.EntryPointstry{- _sessionManager.SendMessageToAdminSessions("RefreshProgress", collectionFolderDict, CancellationToken.None);+ _sessionManager.SendMessageToAdminSessions(SessionMessageType.RefreshProgress, collectionFolderDict, CancellationToken.None);}catch{@@ -345,7 +346,7 @@ namespace Emby.Server.Implementations.EntryPointstry{- await _sessionManager.SendMessageToUserSessions(new List<Guid> { userId }, "LibraryChanged", info, cancellationToken).ConfigureAwait(false);+ await _sessionManager.SendMessageToUserSessions(new List<Guid> { userId }, SessionMessageType.LibraryChanged, info, cancellationToken).ConfigureAwait(false);}catch (Exception ex){diff --git a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.csindex 44d2580d68..824bb85f44 100644--- a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs@@ -10,6 +10,7 @@ using MediaBrowser.Controller.Library;using MediaBrowser.Controller.LiveTv;using MediaBrowser.Controller.Plugins;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.EntryPoints@@ -46,25 +47,25 @@ namespace Emby.Server.Implementations.EntryPointsprivate async void OnLiveTvManagerSeriesTimerCreated(object sender, GenericEventArgs<TimerEventInfo> e){- await SendMessage("SeriesTimerCreated", e.Argument).ConfigureAwait(false);+ await SendMessage(SessionMessageType.SeriesTimerCreated, e.Argument).ConfigureAwait(false);}private async void OnLiveTvManagerTimerCreated(object sender, GenericEventArgs<TimerEventInfo> e){- await SendMessage("TimerCreated", e.Argument).ConfigureAwait(false);+ await SendMessage(SessionMessageType.TimerCreated, e.Argument).ConfigureAwait(false);}private async void OnLiveTvManagerSeriesTimerCancelled(object sender, GenericEventArgs<TimerEventInfo> e){- await SendMessage("SeriesTimerCancelled", e.Argument).ConfigureAwait(false);+ await SendMessage(SessionMessageType.SeriesTimerCancelled, e.Argument).ConfigureAwait(false);}private async void OnLiveTvManagerTimerCancelled(object sender, GenericEventArgs<TimerEventInfo> e){- await SendMessage("TimerCancelled", e.Argument).ConfigureAwait(false);+ await SendMessage(SessionMessageType.TimerCancelled, e.Argument).ConfigureAwait(false);}- private async Task SendMessage(string name, TimerEventInfo info)+ private async Task SendMessage(SessionMessageType name, TimerEventInfo info){var users = _userManager.Users.Where(i => i.HasPermission(PermissionKind.EnableLiveTvAccess)).Select(i => i.Id).ToList();diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.csindex 3618b88c5d..ff09cc81ed 100644--- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs+++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs@@ -116,7 +116,7 @@ namespace Emby.Server.Implementations.EntryPointsprivate Task SendNotifications(Guid userId, List<BaseItem> changedItems, CancellationToken cancellationToken){- return _sessionManager.SendMessageToUserSessions(new List<Guid> { userId }, "UserDataChanged", () => GetUserDataChangeInfo(userId, changedItems), cancellationToken);+ return _sessionManager.SendMessageToUserSessions(new List<Guid> { userId }, SessionMessageType.UserDataChanged, () => GetUserDataChangeInfo(userId, changedItems), cancellationToken);}private UserDataChangeInfo GetUserDataChangeInfo(Guid userId, List<BaseItem> changedItems)diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.csindex 7eae4e7646..fed2addf80 100644--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs@@ -11,6 +11,7 @@ using System.Threading.Tasks;using MediaBrowser.Common.Json;using MediaBrowser.Controller.Net;using MediaBrowser.Model.Net;+using MediaBrowser.Model.Session;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.Logging;@@ -227,7 +228,7 @@ namespace Emby.Server.Implementations.HttpServerConnection = this};- if (info.MessageType.Equals("KeepAlive", StringComparison.Ordinal))+ if (info.MessageType == SessionMessageType.KeepAlive){await SendKeepAliveResponse().ConfigureAwait(false);}@@ -244,7 +245,7 @@ namespace Emby.Server.Implementations.HttpServernew WebSocketMessage<string>{MessageId = Guid.NewGuid(),- MessageType = "KeepAlive"+ MessageType = SessionMessageType.KeepAlive}, CancellationToken.None);}diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.csindex e42d478533..df1b1e4525 100644--- a/Emby.Server.Implementations/Session/SessionManager.cs+++ b/Emby.Server.Implementations/Session/SessionManager.cs@@ -1064,10 +1064,10 @@ namespace Emby.Server.Implementations.SessionAssertCanControl(session, controllingSession);}- return SendMessageToSession(session, "GeneralCommand", command, cancellationToken);+ return SendMessageToSession(session, SessionMessageType.GeneralCommand, command, cancellationToken);}- private static async Task SendMessageToSession<T>(SessionInfo session, string name, T data, CancellationToken cancellationToken)+ private static async Task SendMessageToSession<T>(SessionInfo session, SessionMessageType name, T data, CancellationToken cancellationToken){var controllers = session.SessionControllers;var messageId = Guid.NewGuid();@@ -1078,7 +1078,7 @@ namespace Emby.Server.Implementations.Session}}- private static Task SendMessageToSessions<T>(IEnumerable<SessionInfo> sessions, string name, T data, CancellationToken cancellationToken)+ private static Task SendMessageToSessions<T>(IEnumerable<SessionInfo> sessions, SessionMessageType name, T data, CancellationToken cancellationToken){IEnumerable<Task> GetTasks(){@@ -1178,7 +1178,7 @@ namespace Emby.Server.Implementations.Session}}- await SendMessageToSession(session, "Play", command, cancellationToken).ConfigureAwait(false);+ await SendMessageToSession(session, SessionMessageType.Play, command, cancellationToken).ConfigureAwait(false);}/// <inheritdoc />@@ -1186,7 +1186,7 @@ namespace Emby.Server.Implementations.Session{CheckDisposed();var session = GetSessionToRemoteControl(sessionId);- await SendMessageToSession(session, "SyncPlayCommand", command, cancellationToken).ConfigureAwait(false);+ await SendMessageToSession(session, SessionMessageType.SyncPlayCommand, command, cancellationToken).ConfigureAwait(false);}/// <inheritdoc />@@ -1194,7 +1194,7 @@ namespace Emby.Server.Implementations.Session{CheckDisposed();var session = GetSessionToRemoteControl(sessionId);- await SendMessageToSession(session, "SyncPlayGroupUpdate", command, cancellationToken).ConfigureAwait(false);+ await SendMessageToSession(session, SessionMessageType.SyncPlayGroupUpdate, command, cancellationToken).ConfigureAwait(false);}private IEnumerable<BaseItem> TranslateItemForPlayback(Guid id, User user)@@ -1297,7 +1297,7 @@ namespace Emby.Server.Implementations.Session}}- return SendMessageToSession(session, "Playstate", command, cancellationToken);+ return SendMessageToSession(session, SessionMessageType.PlayState, command, cancellationToken);}private static void AssertCanControl(SessionInfo session, SessionInfo controllingSession)@@ -1322,7 +1322,7 @@ namespace Emby.Server.Implementations.Session{CheckDisposed();- return SendMessageToSessions(Sessions, "RestartRequired", string.Empty, cancellationToken);+ return SendMessageToSessions(Sessions, SessionMessageType.RestartRequired, string.Empty, cancellationToken);}/// <summary>@@ -1334,7 +1334,7 @@ namespace Emby.Server.Implementations.Session{CheckDisposed();- return SendMessageToSessions(Sessions, "ServerShuttingDown", string.Empty, cancellationToken);+ return SendMessageToSessions(Sessions, SessionMessageType.ServerShuttingDown, string.Empty, cancellationToken);}/// <summary>@@ -1348,7 +1348,7 @@ namespace Emby.Server.Implementations.Session_logger.LogDebug("Beginning SendServerRestartNotification");- return SendMessageToSessions(Sessions, "ServerRestarting", string.Empty, cancellationToken);+ return SendMessageToSessions(Sessions, SessionMessageType.ServerRestarting, string.Empty, cancellationToken);}/// <summary>@@ -1866,7 +1866,7 @@ namespace Emby.Server.Implementations.Session}/// <inheritdoc />- public Task SendMessageToAdminSessions<T>(string name, T data, CancellationToken cancellationToken)+ public Task SendMessageToAdminSessions<T>(SessionMessageType name, T data, CancellationToken cancellationToken){CheckDisposed();@@ -1879,7 +1879,7 @@ namespace Emby.Server.Implementations.Session}/// <inheritdoc />- public Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, Func<T> dataFn, CancellationToken cancellationToken)+ public Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, Func<T> dataFn, CancellationToken cancellationToken){CheckDisposed();@@ -1894,7 +1894,7 @@ namespace Emby.Server.Implementations.Session}/// <inheritdoc />- public Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, T data, CancellationToken cancellationToken)+ public Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, T data, CancellationToken cancellationToken){CheckDisposed();@@ -1903,7 +1903,7 @@ namespace Emby.Server.Implementations.Session}/// <inheritdoc />- public Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data, CancellationToken cancellationToken)+ public Task SendMessageToUserDeviceSessions<T>(string deviceId, SessionMessageType name, T data, CancellationToken cancellationToken){CheckDisposed();diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.csindex 15c2af220d..a5f8479537 100644--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs@@ -8,6 +8,7 @@ using Jellyfin.Data.Events;using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Net;+using MediaBrowser.Model.Session;using Microsoft.AspNetCore.Http;using Microsoft.Extensions.Logging;@@ -316,7 +317,7 @@ namespace Emby.Server.Implementations.Sessionreturn webSocket.SendAsync(new WebSocketMessage<int>{- MessageType = "ForceKeepAlive",+ MessageType = SessionMessageType.ForceKeepAlive,Data = WebSocketLostTimeout},CancellationToken.None);diff --git a/Emby.Server.Implementations/Session/WebSocketController.cs b/Emby.Server.Implementations/Session/WebSocketController.csindex 94604ca1e0..b986ffa1cd 100644--- a/Emby.Server.Implementations/Session/WebSocketController.cs+++ b/Emby.Server.Implementations/Session/WebSocketController.cs@@ -11,6 +11,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Net;+using MediaBrowser.Model.Session;using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.Session@@ -65,7 +66,7 @@ namespace Emby.Server.Implementations.Session/// <inheritdoc />public Task SendMessage<T>(- string name,+ SessionMessageType name,Guid messageId,T data,CancellationToken cancellationToken)diff --git a/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.csindex 849b3b7095..77d55828d1 100644--- a/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs+++ b/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs@@ -3,6 +3,7 @@ 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@@ -29,11 +30,14 @@ namespace Jellyfin.Api.WebSocketListeners_activityManager.EntryCreated += OnEntryCreated;}- /// <summary>- /// Gets the name.- /// </summary>- /// <value>The name.</value>- protected override string Name => "ActivityLogEntry";+ /// <inheritdoc />+ protected override SessionMessageType Type => SessionMessageType.ActivityLogEntry;++ /// <inheritdoc />+ protected override SessionMessageType StartType => SessionMessageType.ActivityLogEntryStart;++ /// <inheritdoc />+ protected override SessionMessageType StopType => SessionMessageType.ActivityLogEntryStop;/// <summary>/// Gets the data to send.diff --git a/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.csindex 8a966c1376..80314b9236 100644--- a/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs+++ b/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs@@ -3,6 +3,7 @@ using System.Linq;using System.Threading.Tasks;using Jellyfin.Data.Events;using MediaBrowser.Controller.Net;+using MediaBrowser.Model.Session;using MediaBrowser.Model.Tasks;using Microsoft.Extensions.Logging;@@ -33,11 +34,14 @@ namespace Jellyfin.Api.WebSocketListeners_taskManager.TaskCompleted += OnTaskCompleted;}- /// <summary>- /// Gets the name.- /// </summary>- /// <value>The name.</value>- protected override string Name => "ScheduledTasksInfo";+ /// <inheritdoc />+ protected override SessionMessageType Type => SessionMessageType.ScheduledTasksInfo;++ /// <inheritdoc />+ protected override SessionMessageType StartType => SessionMessageType.ScheduledTasksInfoStart;++ /// <inheritdoc />+ protected override SessionMessageType StopType => SessionMessageType.ScheduledTasksInfoStop;/// <summary>/// Gets the data to send.diff --git a/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.csindex 1fb5dc412c..1cf43a0053 100644--- a/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs+++ b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;using Microsoft.Extensions.Logging;namespace Jellyfin.Api.WebSocketListeners@@ -34,7 +35,13 @@ namespace Jellyfin.Api.WebSocketListeners}/// <inheritdoc />- protected override string Name => "Sessions";+ protected override SessionMessageType Type => SessionMessageType.Sessions;++ /// <inheritdoc />+ protected override SessionMessageType StartType => SessionMessageType.SessionsStart;++ /// <inheritdoc />+ protected override SessionMessageType StopType => SessionMessageType.SessionsStop;/// <summary>/// Gets the data to send.diff --git a/Jellyfin.Server.Implementations/Events/Consumers/System/TaskCompletedNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/System/TaskCompletedNotifier.csindex 80ed56cd8f..0993c6df7b 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/System/TaskCompletedNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/System/TaskCompletedNotifier.cs@@ -2,6 +2,7 @@using System.Threading.Tasks;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;using MediaBrowser.Model.Tasks;namespace Jellyfin.Server.Implementations.Events.Consumers.System@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.System/// <inheritdoc />public async Task OnEvent(TaskCompletionEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("ScheduledTaskEnded", eventArgs.Result, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.ScheduledTaskEnded, eventArgs.Result, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationCancelledNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationCancelledNotifier.csindex 1c600683a9..1d790da6b2 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationCancelledNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationCancelledNotifier.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Events.Updates;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Updates{@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Updates/// <inheritdoc />public async Task OnEvent(PluginInstallationCancelledEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("PackageInstallationCancelled", eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.PackageInstallationCancelled, eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationFailedNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationFailedNotifier.csindex ea0c878d42..a1faf18fc4 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationFailedNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallationFailedNotifier.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Common.Updates;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Updates{@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Updates/// <inheritdoc />public async Task OnEvent(InstallationFailedEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("PackageInstallationFailed", eventArgs.InstallationInfo, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.PackageInstallationFailed, eventArgs.InstallationInfo, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstalledNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstalledNotifier.csindex 3dda5a04c4..bd1a714045 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstalledNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstalledNotifier.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Events.Updates;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Updates{@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Updates/// <inheritdoc />public async Task OnEvent(PluginInstalledEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("PackageInstallationCompleted", eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.PackageInstallationCompleted, eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallingNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallingNotifier.csindex f691d11a7d..b513ac64ae 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallingNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginInstallingNotifier.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Events.Updates;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Updates{@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Updates/// <inheritdoc />public async Task OnEvent(PluginInstallingEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("PackageInstalling", eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.PackageInstalling, eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginUninstalledNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginUninstalledNotifier.csindex 709692f6bb..1fd7b9adfc 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginUninstalledNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Updates/PluginUninstalledNotifier.cs@@ -3,6 +3,7 @@ using System.Threading.Tasks;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Events.Updates;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Updates{@@ -25,7 +26,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Updates/// <inheritdoc />public async Task OnEvent(PluginUninstalledEventArgs eventArgs){- await _sessionManager.SendMessageToAdminSessions("PluginUninstalled", eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);+ await _sessionManager.SendMessageToAdminSessions(SessionMessageType.PackageUninstalled, eventArgs.Argument, CancellationToken.None).ConfigureAwait(false);}}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Users/UserDeletedNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Users/UserDeletedNotifier.csindex 10367a939b..303e886210 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Users/UserDeletedNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Users/UserDeletedNotifier.cs@@ -6,6 +6,7 @@ using System.Threading.Tasks;using Jellyfin.Data.Events.Users;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Users{@@ -30,7 +31,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Users{await _sessionManager.SendMessageToUserSessions(new List<Guid> { eventArgs.Argument.Id },- "UserDeleted",+ SessionMessageType.UserDeleted,eventArgs.Argument.Id.ToString("N", CultureInfo.InvariantCulture),CancellationToken.None).ConfigureAwait(false);}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Users/UserUpdatedNotifier.cs b/Jellyfin.Server.Implementations/Events/Consumers/Users/UserUpdatedNotifier.csindex 6081dd044f..a14911b94a 100644--- a/Jellyfin.Server.Implementations/Events/Consumers/Users/UserUpdatedNotifier.cs+++ b/Jellyfin.Server.Implementations/Events/Consumers/Users/UserUpdatedNotifier.cs@@ -6,6 +6,7 @@ using Jellyfin.Data.Events.Users;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Library;using MediaBrowser.Controller.Session;+using MediaBrowser.Model.Session;namespace Jellyfin.Server.Implementations.Events.Consumers.Users{@@ -33,7 +34,7 @@ namespace Jellyfin.Server.Implementations.Events.Consumers.Users{await _sessionManager.SendMessageToUserSessions(new List<Guid> { e.Argument.Id },- "UserUpdated",+ SessionMessageType.UserUpdated,_userManager.GetUserDto(e.Argument),CancellationToken.None).ConfigureAwait(false);}diff --git a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.csindex 916dea58be..28227603b2 100644--- a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs+++ b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs@@ -8,6 +8,7 @@ using System.Net.WebSockets;using System.Threading;using System.Threading.Tasks;using MediaBrowser.Model.Net;+using MediaBrowser.Model.Session;using Microsoft.Extensions.Logging;namespace MediaBrowser.Controller.Net@@ -28,10 +29,22 @@ namespace MediaBrowser.Controller.Netnew List<Tuple<IWebSocketConnection, CancellationTokenSource, TStateType>>();/// <summary>- /// Gets the name.+ /// Gets the type used for the messages sent to the client./// </summary>- /// <value>The name.</value>- protected abstract string Name { get; }+ /// <value>The type.</value>+ protected abstract SessionMessageType Type { get; }++ /// <summary>+ /// Gets the message type received from the client to start sending messages.+ /// </summary>+ /// <value>The type.</value>+ protected abstract SessionMessageType StartType { get; }++ /// <summary>+ /// Gets the message type received from the client to stop sending messages.+ /// </summary>+ /// <value>The type.</value>+ protected abstract SessionMessageType StopType { get; }/// <summary>/// Gets the data to send.@@ -66,12 +79,12 @@ namespace MediaBrowser.Controller.Netthrow new ArgumentNullException(nameof(message));}- if (string.Equals(message.MessageType, Name + "Start", StringComparison.OrdinalIgnoreCase))+ if (message.MessageType == StartType){Start(message);}- if (string.Equals(message.MessageType, Name + "Stop", StringComparison.OrdinalIgnoreCase))+ if (message.MessageType == StopType){Stop(message);}@@ -159,7 +172,7 @@ namespace MediaBrowser.Controller.Netnew WebSocketMessage<TReturnDataType>{MessageId = Guid.NewGuid(),- MessageType = Name,+ MessageType = Type,Data = data},cancellationToken).ConfigureAwait(false);@@ -176,7 +189,7 @@ namespace MediaBrowser.Controller.Net}catch (Exception ex){- Logger.LogError(ex, "Error sending web socket message {Name}", Name);+ Logger.LogError(ex, "Error sending web socket message {Name}", Type);DisposeConnection(tuple);}}diff --git a/MediaBrowser.Controller/Session/ISessionController.cs b/MediaBrowser.Controller/Session/ISessionController.csindex 22d6e2a04e..bc4ccd44ca 100644--- a/MediaBrowser.Controller/Session/ISessionController.cs+++ b/MediaBrowser.Controller/Session/ISessionController.cs@@ -3,6 +3,7 @@using System;using System.Threading;using System.Threading.Tasks;+using MediaBrowser.Model.Session;namespace MediaBrowser.Controller.Session{@@ -23,6 +24,6 @@ namespace MediaBrowser.Controller.Session/// <summary>/// Sends the message./// </summary>- Task SendMessage<T>(string name, Guid messageId, T data, CancellationToken cancellationToken);+ Task SendMessage<T>(SessionMessageType name, Guid messageId, T data, CancellationToken cancellationToken);}}diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.csindex 228b2331dc..04c3004ee6 100644--- a/MediaBrowser.Controller/Session/ISessionManager.cs+++ b/MediaBrowser.Controller/Session/ISessionManager.cs@@ -188,16 +188,16 @@ namespace MediaBrowser.Controller.Session/// <param name="data">The data.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task.</returns>- Task SendMessageToAdminSessions<T>(string name, T data, CancellationToken cancellationToken);+ Task SendMessageToAdminSessions<T>(SessionMessageType name, T data, CancellationToken cancellationToken);/// <summary>/// Sends the message to user sessions./// </summary>/// <typeparam name="T"></typeparam>/// <returns>Task.</returns>- Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, T data, CancellationToken cancellationToken);+ Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, T data, CancellationToken cancellationToken);- Task SendMessageToUserSessions<T>(List<Guid> userIds, string name, Func<T> dataFn, CancellationToken cancellationToken);+ Task SendMessageToUserSessions<T>(List<Guid> userIds, SessionMessageType name, Func<T> dataFn, CancellationToken cancellationToken);/// <summary>/// Sends the message to user device sessions.@@ -208,7 +208,7 @@ namespace MediaBrowser.Controller.Session/// <param name="data">The data.</param>/// <param name="cancellationToken">The cancellation token.</param>/// <returns>Task.</returns>- Task SendMessageToUserDeviceSessions<T>(string deviceId, string name, T data, CancellationToken cancellationToken);+ Task SendMessageToUserDeviceSessions<T>(string deviceId, SessionMessageType name, T data, CancellationToken cancellationToken);/// <summary>/// Sends the restart required message.diff --git a/MediaBrowser.Model/Net/WebSocketMessage.cs b/MediaBrowser.Model/Net/WebSocketMessage.csindex 660eebeda6..bffbbe612d 100644--- a/MediaBrowser.Model/Net/WebSocketMessage.cs+++ b/MediaBrowser.Model/Net/WebSocketMessage.cs@@ -2,6 +2,7 @@#pragma warning disable CS1591using System;+using MediaBrowser.Model.Session;namespace MediaBrowser.Model.Net{@@ -15,7 +16,7 @@ namespace MediaBrowser.Model.Net/// Gets or sets the type of the message./// </summary>/// <value>The type of the message.</value>- public string MessageType { get; set; }+ public SessionMessageType MessageType { get; set; }public Guid MessageId { get; set; }diff --git a/MediaBrowser.Model/Session/SessionMessageType.cs b/MediaBrowser.Model/Session/SessionMessageType.csnew file mode 100644index 0000000000..23c41026dc--- /dev/null+++ b/MediaBrowser.Model/Session/SessionMessageType.cs@@ -0,0 +1,50 @@+#pragma warning disable CS1591++namespace MediaBrowser.Model.Session+{+ /// <summary>+ /// The different kinds of messages that are used in the WebSocket api.+ /// </summary>+ public enum SessionMessageType+ {+ // Server -> Client+ ForceKeepAlive,+ GeneralCommand,+ UserDataChanged,+ Sessions,+ Play,+ SyncPlayCommand,+ SyncPlayGroupUpdate,+ PlayState,+ RestartRequired,+ ServerShuttingDown,+ ServerRestarting,+ LibraryChanged,+ UserDeleted,+ UserUpdated,+ SeriesTimerCreated,+ TimerCreated,+ SeriesTimerCancelled,+ TimerCancelled,+ RefreshProgress,+ ScheduledTaskEnded,+ PackageInstallationCancelled,+ PackageInstallationFailed,+ PackageInstallationCompleted,+ PackageInstalling,+ PackageUninstalled,+ ActivityLogEntry,+ ScheduledTasksInfo,++ // Client -> Server+ ActivityLogEntryStart,+ ActivityLogEntryStop,+ SessionsStart,+ SessionsStop,+ ScheduledTasksInfoStart,+ ScheduledTasksInfoStop,++ // Shared+ KeepAlive,+ }+}