Files
Api/DouyinApi.Extensions/Middlewares/SignalRSendMiddleware.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2025-11-04 21:09:16 +08:00
using System.Threading.Tasks;
using DouyinApi.Common;
using DouyinApi.Common.LogHelper;
using DouyinApi.Hubs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
namespace DouyinApi.Extensions.Middlewares
{
/// <summary>
/// 中间件
/// SignalR发送数据
/// </summary>
public class SignalRSendMiddleware
{
/// <summary>
///
/// </summary>
private readonly RequestDelegate _next;
private readonly IHubContext<ChatHub> _hubContext;
/// <summary>
///
/// </summary>
/// <param name="next"></param>
/// <param name="hubContext"></param>
public SignalRSendMiddleware(RequestDelegate next, IHubContext<ChatHub> hubContext)
{
_next = next;
_hubContext = hubContext;
}
public async Task InvokeAsync(HttpContext context)
{
if (AppSettings.app("Middleware", "SignalR", "Enabled").ObjToBool())
{
//TODO 主动发送错误消息
await _hubContext.Clients.All.SendAsync("ReceiveUpdate", LogLock.GetLogData());
}
await _next(context);
}
}
}