Merge pull request #4210 from nielsvanvelzen/typed-websocket-message
Use enum for WebSocket message types
This commit is contained in:
commit
e011659186
|
@ -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.PlayTo
|
|||
return 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);
|
||||
}
|
||||
|
|
|
@ -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.EntryPoints
|
|||
|
||||
try
|
||||
{
|
||||
_sessionManager.SendMessageToAdminSessions("RefreshProgress", dict, CancellationToken.None);
|
||||
_sessionManager.SendMessageToAdminSessions(SessionMessageType.RefreshProgress, dict, CancellationToken.None);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -123,7 +124,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
|||
|
||||
try
|
||||
{
|
||||
_sessionManager.SendMessageToAdminSessions("RefreshProgress", collectionFolderDict, CancellationToken.None);
|
||||
_sessionManager.SendMessageToAdminSessions(SessionMessageType.RefreshProgress, collectionFolderDict, CancellationToken.None);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -345,7 +346,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
|||
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -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.EntryPoints
|
|||
|
||||
private 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();
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Emby.Server.Implementations.EntryPoints
|
|||
|
||||
private 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)
|
||||
|
|
|
@ -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.HttpServer
|
|||
Connection = 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.HttpServer
|
|||
new WebSocketMessage<string>
|
||||
{
|
||||
MessageId = Guid.NewGuid(),
|
||||
MessageType = "KeepAlive"
|
||||
MessageType = SessionMessageType.KeepAlive
|
||||
}, CancellationToken.None);
|
||||
}
|
||||
|
||||
|
|
|
@ -1064,10 +1064,10 @@ namespace Emby.Server.Implementations.Session
|
|||
AssertCanControl(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>
|
||||
|
@ -1874,7 +1874,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();
|
||||
|
||||
|
@ -1887,7 +1887,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();
|
||||
|
||||
|
@ -1902,7 +1902,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();
|
||||
|
||||
|
@ -1911,7 +1911,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();
|
||||
|
||||
|
|
|
@ -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.Session
|
|||
return webSocket.SendAsync(
|
||||
new WebSocketMessage<int>
|
||||
{
|
||||
MessageType = "ForceKeepAlive",
|
||||
MessageType = SessionMessageType.ForceKeepAlive,
|
||||
Data = WebSocketLostTimeout
|
||||
},
|
||||
CancellationToken.None);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.Net
|
|||
new 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.Net
|
|||
throw 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.Net
|
|||
new 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#pragma warning disable CS1591
|
||||
|
||||
using 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; }
|
||||
|
||||
|
|
50
MediaBrowser.Model/Session/SessionMessageType.cs
Normal file
50
MediaBrowser.Model/Session/SessionMessageType.cs
Normal file
|
@ -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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user