🐛 Fixes System.NotSupportedException: WebSockets are not supported
This commit is contained in:
parent
84a88222bd
commit
42b5129aa4
@ -8,7 +8,7 @@ namespace DysonNetwork.Sphere.Connection;
|
||||
|
||||
[ApiController]
|
||||
[Route("/ws")]
|
||||
public class WebSocketController : ControllerBase
|
||||
public class WebSocketController(ILogger<WebSocketContext> logger) : ControllerBase
|
||||
{
|
||||
private static readonly ConcurrentDictionary<
|
||||
(long AccountId, string DeviceId),
|
||||
@ -19,8 +19,6 @@ public class WebSocketController : ControllerBase
|
||||
[Authorize]
|
||||
[SwaggerIgnore]
|
||||
public async Task TheGateway()
|
||||
{
|
||||
if (HttpContext.WebSockets.IsWebSocketRequest)
|
||||
{
|
||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||
HttpContext.Items.TryGetValue("CurrentSession", out var currentSessionValue);
|
||||
@ -54,6 +52,9 @@ public class WebSocketController : ControllerBase
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogInformation(
|
||||
$"Connection established with user @{currentUser.Name}#{currentUser.Id} and device #{deviceId}");
|
||||
|
||||
try
|
||||
{
|
||||
await _ConnectionEventLoop(webSocket, connectionKey, cts.Token);
|
||||
@ -66,11 +67,8 @@ public class WebSocketController : ControllerBase
|
||||
{
|
||||
ActiveConnections.TryRemove(connectionKey, out _);
|
||||
cts.Dispose();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
logger.LogInformation(
|
||||
$"Connection disconnected with user @{currentUser.Name}#{currentUser.Id} and device #{deviceId}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,7 @@ app.UseCors(opts =>
|
||||
.AllowAnyMethod()
|
||||
);
|
||||
|
||||
app.UseWebSockets();
|
||||
app.UseRateLimiter();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
|
Loading…
x
Reference in New Issue
Block a user