feat(battle-node): WebSocket endpoint at /socket.io/ + DI extension methods

This commit is contained in:
gamer147
2026-05-31 22:34:54 -04:00
parent f19da481c3
commit 1dd6a70e8d
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
// SVSim.BattleNode/Hosting/BattleNodeExtensions.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SVSim.BattleNode.Bridge;
using SVSim.BattleNode.Sessions;
namespace SVSim.BattleNode.Hosting;
public static class BattleNodeExtensions
{
public static IServiceCollection AddBattleNode(this IServiceCollection services, Action<BattleNodeOptions>? configure = null)
{
var options = new BattleNodeOptions();
configure?.Invoke(options);
services.AddSingleton(options);
services.AddSingleton<IBattleSessionStore, InMemoryBattleSessionStore>();
services.AddSingleton<IMatchingBridge, MatchingBridge>();
services.AddSingleton<BattleNodeWebSocketHandler>();
return services;
}
public static IApplicationBuilder UseBattleNode(this IApplicationBuilder app)
{
app.UseWebSockets();
app.Map("/socket.io", branch => branch.Run(async ctx =>
{
var handler = ctx.RequestServices.GetRequiredService<BattleNodeWebSocketHandler>();
await handler.HandleAsync(ctx);
}));
return app;
}
}