重新设计了Libray.Json Api以及 WebSocket 的交互处理方式

This commit is contained in:
fengjiayi
2025-08-02 10:48:31 +08:00
parent 1bccccc835
commit 6fc57458a7
29 changed files with 883 additions and 348 deletions

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetWebSocket = System.Net.WebSockets.WebSocket;
namespace Serein.Proto.WebSocket
{
/// <summary>
/// WebSocket服务
/// </summary>
public interface ISereinWebSocketService
{
/// <summary>
/// 目前有多少个连接
/// </summary>
int ConcetionCount { get; }
/// <summary>
/// 添加处理模块
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
ISereinWebSocketService AddHandleModule<T>() where T : ISocketHandleModule, new();
/// <summary>
/// 添加处理模块
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="instanceFactory">使用指定的实例</param>
/// <returns></returns>
ISereinWebSocketService AddHandleModule<T>(Func<ISocketHandleModule> instanceFactory) where T : ISocketHandleModule;
/// <summary>
/// 跟踪未处理的异常
/// </summary>
/// <param name="onExceptionTrackingAsync"></param>
/// <returns></returns>
ISereinWebSocketService TrackUnhandledExceptions(Func<Exception, Func<object, Task>, Task> onExceptionTrackingAsync);
/// <summary>
/// 添加新的 WebSocket 连接进行处理消息
/// </summary>
/// <param name="webSocket"></param>
Task AddWebSocketHandleAsync(NetWebSocket webSocket);
/// <summary>
/// 推送消息
/// </summary>
/// <param name="latestData"></param>
/// <returns></returns>
Task PushDataAsync(object latestData);
}
}