mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-28 04:51:54 +00:00
Removed Lazy implementation.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Events;
|
||||
using MediaBrowser.Controller.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="ISessionWebSocketListener" />.
|
||||
/// </summary>
|
||||
public interface ISessionWebSocketListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs processes due to a WebSocket connection event.
|
||||
/// </summary>
|
||||
/// <param name="websocketConnection">The <see cref="IWebSocketConnection"/> instance.</param>
|
||||
void ProcessWebSocketConnected(IWebSocketConnection websocketConnection);
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the object.
|
||||
/// </summary>
|
||||
void Dispose();
|
||||
|
||||
/// <summary>
|
||||
/// Processes a message.
|
||||
/// </summary>
|
||||
/// <param name="message">The <see cref="WebSocketMessageInfo"/>.</param>
|
||||
/// <returns>A <see cref="Task"/>.</returns>
|
||||
Task ProcessMessageAsync(WebSocketMessageInfo message);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <summary>
|
||||
/// Class SessionWebSocketListener.
|
||||
/// </summary>
|
||||
public sealed class SessionWebSocketListener : IWebSocketListener, IDisposable
|
||||
public sealed class SessionWebSocketListener : ISessionWebSocketListener, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The timeout in seconds after which a WebSocket is considered to be lost.
|
||||
@@ -45,15 +45,13 @@ namespace Emby.Server.Implementations.Session
|
||||
private readonly ILogger<SessionWebSocketListener> _logger;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
|
||||
private readonly IWebSocketManager _webSocketManager;
|
||||
|
||||
/// <summary>
|
||||
/// The KeepAlive cancellation token.
|
||||
/// </summary>
|
||||
private CancellationTokenSource _keepAliveCancellationToken;
|
||||
|
||||
/// <summary>
|
||||
/// Lock used for accesing the KeepAlive cancellation token.
|
||||
/// Lock used for accessing the KeepAlive cancellation token.
|
||||
/// </summary>
|
||||
private readonly object _keepAliveLock = new object();
|
||||
|
||||
@@ -63,7 +61,7 @@ namespace Emby.Server.Implementations.Session
|
||||
private readonly HashSet<IWebSocketConnection> _webSockets = new HashSet<IWebSocketConnection>();
|
||||
|
||||
/// <summary>
|
||||
/// Lock used for accesing the WebSockets watchlist.
|
||||
/// Lock used for accessing the WebSockets watchlist.
|
||||
/// </summary>
|
||||
private readonly object _webSocketsLock = new object();
|
||||
|
||||
@@ -73,32 +71,28 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="sessionManager">The session manager.</param>
|
||||
/// <param name="loggerFactory">The logger factory.</param>
|
||||
/// <param name="webSocketManager">The HTTP server.</param>
|
||||
public SessionWebSocketListener(
|
||||
ILogger<SessionWebSocketListener> logger,
|
||||
ISessionManager sessionManager,
|
||||
ILoggerFactory loggerFactory,
|
||||
IWebSocketManager webSocketManager)
|
||||
ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_sessionManager = sessionManager;
|
||||
_loggerFactory = loggerFactory;
|
||||
_webSocketManager = webSocketManager;
|
||||
|
||||
webSocketManager.WebSocketConnected += OnServerManagerWebSocketConnected;
|
||||
}
|
||||
|
||||
private async void OnServerManagerWebSocketConnected(object sender, GenericEventArgs<IWebSocketConnection> e)
|
||||
/// <inheritdoc/>
|
||||
public async void ProcessWebSocketConnected(IWebSocketConnection websocketConnection)
|
||||
{
|
||||
var session = GetSession(e.Argument.QueryString, e.Argument.RemoteEndPoint.ToString());
|
||||
var session = GetSession(websocketConnection.QueryString, websocketConnection.RemoteEndPoint.ToString());
|
||||
if (session != null)
|
||||
{
|
||||
EnsureController(session, e.Argument);
|
||||
await KeepAliveWebSocket(e.Argument).ConfigureAwait(false);
|
||||
EnsureController(session, websocketConnection);
|
||||
await KeepAliveWebSocket(websocketConnection).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Unable to determine session based on query string: {0}", e.Argument.QueryString);
|
||||
_logger.LogWarning("Unable to determine session based on query string: {Querystring}", websocketConnection.QueryString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +116,6 @@ namespace Emby.Server.Implementations.Session
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_webSocketManager.WebSocketConnected -= OnServerManagerWebSocketConnected;
|
||||
StopKeepAlive();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user