mh_jy_safe/APT.MicroApi/APT.PF.WebApi/Utils/WebSokectHelper.cs

43 lines
1.7 KiB
C#
Raw Normal View History

2025-08-25 09:56:57 +08:00
using APT.Infrastructure.Core;
using APT.BaseData.Domain.IServices.EX;
using System;
using APT.BaseData.Domain.IServices.Platform;
using APT.BaseData.Services.Services.EX;
using APT.Infrastructure.Api;
using System.Collections.Generic;
2025-08-25 09:56:57 +08:00
namespace APT.PF.WebApi.Utils
{
public static class WebSokectHelper
{
public static List<WebSocketClientInfo> WebSocketClientInfos = new List<WebSocketClientInfo>();
2025-08-25 09:56:57 +08:00
public static void Init()
{
//var webSocketService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<IWebSocketService>();
//var versionService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<IPFLastVersionService>();
var webSocketPort = LibUtils.ToInt(
ConfigurationManager.AppSettings["WebSocketPort"]);
try
{
WebSocketServiceHelper.InitService(webSocketPort,
(clientInfo) =>
{
return WebSocketService.OnOpenWebSocket(clientInfo, WebSocketClientInfos);
2025-08-25 09:56:57 +08:00
},
(clientInfo, requestInfo) =>
{
return WebSocketService.OnMessageWebSocket(clientInfo, requestInfo, WebSocketClientInfos);
2025-08-25 09:56:57 +08:00
},
(userId, clientInfo) =>
{
WebSocketService.OnCloseWebSocket(userId, clientInfo, WebSocketClientInfos);
2025-08-25 09:56:57 +08:00
});
}
catch (Exception ex)
{
LoggerManager.GetLogger("Application").Error("WebSocket初始化错误" + ex.Message);
}
}
}
}