using System.Net.WebSockets; using DisplayCommands; using TanksServer.Graphics; namespace TanksServer.Interactivity; internal sealed class ClientScreenServer( ILogger logger, ILoggerFactory loggerFactory, IOptions hostConfig ) : WebsocketServer(logger), IFrameConsumer { private readonly TimeSpan _minFrameTime = TimeSpan.FromMilliseconds(hostConfig.Value.ClientDisplayMinFrameTimeMs); public Task HandleClientAsync(WebSocket socket, Guid? playerGuid) => base.HandleClientAsync(new( socket, loggerFactory.CreateLogger(), _minFrameTime, playerGuid )); public Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels) => ParallelForEachConnectionAsync(c => c.SendAsync(observerPixels, gamePixelGrid)); }