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;
|
2025-12-26 15:24:31 +08:00
|
|
|
|
using System.Collections.Generic;
|
2025-08-25 09:56:57 +08:00
|
|
|
|
|
|
|
|
|
|
namespace APT.PF.WebApi.Utils
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class WebSokectHelper
|
|
|
|
|
|
{
|
2025-12-26 15:24:31 +08:00
|
|
|
|
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) =>
|
|
|
|
|
|
{
|
2025-12-26 15:24:31 +08:00
|
|
|
|
return WebSocketService.OnOpenWebSocket(clientInfo, WebSocketClientInfos);
|
2025-08-25 09:56:57 +08:00
|
|
|
|
},
|
|
|
|
|
|
(clientInfo, requestInfo) =>
|
|
|
|
|
|
{
|
2025-12-26 15:24:31 +08:00
|
|
|
|
return WebSocketService.OnMessageWebSocket(clientInfo, requestInfo, WebSocketClientInfos);
|
2025-08-25 09:56:57 +08:00
|
|
|
|
},
|
|
|
|
|
|
(userId, clientInfo) =>
|
|
|
|
|
|
{
|
2025-12-26 15:24:31 +08:00
|
|
|
|
WebSocketService.OnCloseWebSocket(userId, clientInfo, WebSocketClientInfos);
|
2025-08-25 09:56:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoggerManager.GetLogger("Application").Error("WebSocket初始化错误:" + ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|