less locking for screen connection, force more concurrency

This commit is contained in:
Vinzenz Schroeter 2024-04-30 23:49:39 +02:00 committed by RobbersDaughter
parent 0b10695e07
commit 0e93b1356f
10 changed files with 143 additions and 93 deletions

View file

@ -48,14 +48,18 @@ internal sealed class Endpoints(
return TypedResults.Empty;
}
private async Task<Results<BadRequest, EmptyHttpResult>> ConnectScreenAsync(HttpContext context,
private async Task<Results<BadRequest, EmptyHttpResult, NotFound>> ConnectScreenAsync(HttpContext context,
[FromQuery] string? playerName)
{
if (!context.WebSockets.IsWebSocketRequest)
return TypedResults.BadRequest();
Player? player = null;
if (!string.IsNullOrWhiteSpace(playerName) && !playerService.TryGet(playerName, out player))
return TypedResults.NotFound();
using var ws = await context.WebSockets.AcceptWebSocketAsync();
await clientScreenServer.HandleClientAsync(ws, playerName);
await clientScreenServer.HandleClientAsync(ws, player);
return TypedResults.Empty;
}