using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace CrazyStudio.Core.Common.Tools.Extensions
{
    public static class WebSocketExtension
    {
        ///// <summary>
        ///// 添加TouchSocket WebSocket服务
        ///// </summary>
        ///// <param name="services"></param>
        ///// <param name="configuration"></param>
        //public static WebSocketServer AddWebSocketServer(this IServiceCollection services, IConfiguration configuration, string domain)
        //{
        //    var wssv = new WebSocketServer(domain);

        //    // 获取内部的TcpClient对象并设置NoDelay为true
        //    var tcpClient = wssv.GetType().GetField("_listener", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.GetValue(wssv) as TcpListener;
        //    if (tcpClient != null)
        //    {
        //        tcpClient.Server.NoDelay = true; // 启用NoDelay以减少延迟
        //    }

        //    return wssv;
        //}

        //public static void AddWebSocketService<T>(this IServiceCollection services, WebSocketServer wssv, string path) where T : WebSocketBehavior, new()
        //{
        //    wssv.AddWebSocketService<T>(path);
        //}

        //public static void StartWebSocketServer(this IServiceCollection services, WebSocketServer wssv)
        //{
        //    wssv.Start();
        //}
    }
}
