From 1a0d8aef80a066fdefec4d757d5dcba0dfe0a03c Mon Sep 17 00:00:00 2001 From: cvium Date: Sat, 28 Nov 2020 09:50:16 +0100 Subject: Revert "Removed Lazy implementation." --- .../Session/ISessionWebSocketListener.cs | 30 ---------------------- .../Session/SessionWebSocketListener.cs | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 40 deletions(-) delete mode 100644 Emby.Server.Implementations/Session/ISessionWebSocketListener.cs (limited to 'Emby.Server.Implementations/Session') diff --git a/Emby.Server.Implementations/Session/ISessionWebSocketListener.cs b/Emby.Server.Implementations/Session/ISessionWebSocketListener.cs deleted file mode 100644 index 9b0b28e6e..000000000 --- a/Emby.Server.Implementations/Session/ISessionWebSocketListener.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace Emby.Server.Implementations.Session -{ - using System.Threading.Tasks; - using Jellyfin.Data.Events; - using MediaBrowser.Controller.Net; - - /// - /// Defines the . - /// - public interface ISessionWebSocketListener - { - /// - /// Runs processes due to a WebSocket connection event. - /// - /// The instance. - void ProcessWebSocketConnected(IWebSocketConnection websocketConnection); - - /// - /// Disposes the object. - /// - void Dispose(); - - /// - /// Processes a message. - /// - /// The . - /// A . - Task ProcessMessageAsync(WebSocketMessageInfo message); - } -} diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs index 8f81ee194..a5f847953 100644 --- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs +++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs @@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.Session /// /// Class SessionWebSocketListener. /// - public sealed class SessionWebSocketListener : ISessionWebSocketListener, IDisposable + public sealed class SessionWebSocketListener : IWebSocketListener, IDisposable { /// /// The timeout in seconds after which a WebSocket is considered to be lost. @@ -45,13 +45,15 @@ namespace Emby.Server.Implementations.Session private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; + private readonly IWebSocketManager _webSocketManager; + /// /// The KeepAlive cancellation token. /// private CancellationTokenSource _keepAliveCancellationToken; /// - /// Lock used for accessing the KeepAlive cancellation token. + /// Lock used for accesing the KeepAlive cancellation token. /// private readonly object _keepAliveLock = new object(); @@ -61,7 +63,7 @@ namespace Emby.Server.Implementations.Session private readonly HashSet _webSockets = new HashSet(); /// - /// Lock used for accessing the WebSockets watchlist. + /// Lock used for accesing the WebSockets watchlist. /// private readonly object _webSocketsLock = new object(); @@ -71,28 +73,32 @@ namespace Emby.Server.Implementations.Session /// The logger. /// The session manager. /// The logger factory. + /// The HTTP server. public SessionWebSocketListener( ILogger logger, ISessionManager sessionManager, - ILoggerFactory loggerFactory) + ILoggerFactory loggerFactory, + IWebSocketManager webSocketManager) { _logger = logger; _sessionManager = sessionManager; _loggerFactory = loggerFactory; + _webSocketManager = webSocketManager; + + webSocketManager.WebSocketConnected += OnServerManagerWebSocketConnected; } - /// - public async void ProcessWebSocketConnected(IWebSocketConnection websocketConnection) + private async void OnServerManagerWebSocketConnected(object sender, GenericEventArgs e) { - var session = GetSession(websocketConnection.QueryString, websocketConnection.RemoteEndPoint.ToString()); + var session = GetSession(e.Argument.QueryString, e.Argument.RemoteEndPoint.ToString()); if (session != null) { - EnsureController(session, websocketConnection); - await KeepAliveWebSocket(websocketConnection).ConfigureAwait(false); + EnsureController(session, e.Argument); + await KeepAliveWebSocket(e.Argument).ConfigureAwait(false); } else { - _logger.LogWarning("Unable to determine session based on query string: {Querystring}", websocketConnection.QueryString); + _logger.LogWarning("Unable to determine session based on query string: {0}", e.Argument.QueryString); } } @@ -116,6 +122,7 @@ namespace Emby.Server.Implementations.Session /// public void Dispose() { + _webSocketManager.WebSocketConnected -= OnServerManagerWebSocketConnected; StopKeepAlive(); } -- cgit v1.2.3