using System; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Sockets { public class SocketRouteBuilder { private readonly HttpConnectionDispatcher _dispatcher; private readonly RouteBuilder _routes; public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher) { _routes = routes; _dispatcher = dispatcher; } public void MapSocket(string path, Action socketConfig) => MapSocket(path, new HttpSocketOptions(), socketConfig); public void MapSocket(string path, HttpSocketOptions options, Action socketConfig) { var socketBuilder = new SocketBuilder(_routes.ServiceProvider); socketConfig(socketBuilder); var socket = socketBuilder.Build(); _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); } public void MapEndPoint(string path) where TEndPoint : EndPoint { MapSocket(path, builder => { builder.UseEndPoint(); }); } } }