2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2024-10-09 05:26:51 +03:00
parent 5745887b48
commit c477a11f4b
10 changed files with 107 additions and 26 deletions

View File

@ -0,0 +1,47 @@

using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Net.WebSockets;
namespace Esiur.AspNetCore
{
public class EsiurMiddleware
{
readonly DistributedServer server;
readonly RequestDelegate next;
readonly ILoggerFactory loggerFactory;
public async Task InvokeAsync(HttpContext context)
{
var buffer = new ArraySegment<byte>(new byte[10240]);
if (context.WebSockets.IsWebSocketRequest)
{
var webSocket = await context.WebSockets.AcceptWebSocketAsync("iip");
var socket = new FrameworkWebSocket(webSocket);
var iipConnection = new DistributedConnection();
server.Add(iipConnection);
iipConnection.Assign(socket);
socket.Begin();
while (webSocket.State == WebSocketState.Open) ;
}
else
{
await next(context);
}
}
public EsiurMiddleware(RequestDelegate next, IOptions<EsiurOptions> options, ILoggerFactory loggerFactory)
{
this.server = options.Value.Server;
this.loggerFactory = loggerFactory;
this.next = next;
}
}
}