| | | 1 | | using System.Threading.Tasks; |
| | | 2 | | using MediaBrowser.Controller.Net; |
| | | 3 | | using Microsoft.AspNetCore.Http; |
| | | 4 | | |
| | | 5 | | namespace Jellyfin.Api.Middleware; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Handles WebSocket requests. |
| | | 9 | | /// </summary> |
| | | 10 | | public class WebSocketHandlerMiddleware |
| | | 11 | | { |
| | | 12 | | private readonly RequestDelegate _next; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="WebSocketHandlerMiddleware"/> class. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="next">The next delegate in the pipeline.</param> |
| | | 18 | | public WebSocketHandlerMiddleware(RequestDelegate next) |
| | | 19 | | { |
| | 21 | 20 | | _next = next; |
| | 21 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Executes the middleware action. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="httpContext">The current HTTP context.</param> |
| | | 27 | | /// <param name="webSocketManager">The WebSocket connection manager.</param> |
| | | 28 | | /// <returns>The async task.</returns> |
| | | 29 | | public async Task Invoke(HttpContext httpContext, IWebSocketManager webSocketManager) |
| | | 30 | | { |
| | | 31 | | if (!httpContext.WebSockets.IsWebSocketRequest) |
| | | 32 | | { |
| | | 33 | | await _next(httpContext).ConfigureAwait(false); |
| | | 34 | | return; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | await webSocketManager.WebSocketRequestHandler(httpContext).ConfigureAwait(false); |
| | | 38 | | } |
| | | 39 | | } |