init
This commit is contained in:
47
DouyinApi.Extensions/Middlewares/SignalRSendMiddleware.cs
Normal file
47
DouyinApi.Extensions/Middlewares/SignalRSendMiddleware.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user