feat: 添加消息通知hub
This commit is contained in:
@@ -12,8 +12,8 @@ namespace Yi.Framework.Rbac.Application.Services.Monitor
|
|||||||
public class OnlineService : ApplicationService, IOnlineService
|
public class OnlineService : ApplicationService, IOnlineService
|
||||||
{
|
{
|
||||||
private ILogger<OnlineService> _logger;
|
private ILogger<OnlineService> _logger;
|
||||||
private IHubContext<OnlineUserHub> _hub;
|
private IHubContext<OnlineHub> _hub;
|
||||||
public OnlineService(ILogger<OnlineService> logger, IHubContext<OnlineUserHub> hub)
|
public OnlineService(ILogger<OnlineService> logger, IHubContext<OnlineHub> hub)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_hub = hub;
|
_hub = hub;
|
||||||
@@ -26,7 +26,7 @@ namespace Yi.Framework.Rbac.Application.Services.Monitor
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<PagedResultDto<OnlineUserModel>> GetListAsync([FromQuery] OnlineUserModel online)
|
public Task<PagedResultDto<OnlineUserModel>> GetListAsync([FromQuery] OnlineUserModel online)
|
||||||
{
|
{
|
||||||
var data = OnlineUserHub.clientUsers;
|
var data = OnlineHub.clientUsers;
|
||||||
IEnumerable<OnlineUserModel> dataWhere = data.AsEnumerable();
|
IEnumerable<OnlineUserModel> dataWhere = data.AsEnumerable();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(online.Ipaddr))
|
if (!string.IsNullOrEmpty(online.Ipaddr))
|
||||||
@@ -50,7 +50,7 @@ namespace Yi.Framework.Rbac.Application.Services.Monitor
|
|||||||
[Route("online/{connnectionId}")]
|
[Route("online/{connnectionId}")]
|
||||||
public async Task<bool> ForceOut(string connnectionId)
|
public async Task<bool> ForceOut(string connnectionId)
|
||||||
{
|
{
|
||||||
if (OnlineUserHub.clientUsers.Exists(u => u.ConnnectionId == connnectionId))
|
if (OnlineHub.clientUsers.Exists(u => u.ConnnectionId == connnectionId))
|
||||||
{
|
{
|
||||||
//前端接受到这个事件后,触发前端自动退出
|
//前端接受到这个事件后,触发前端自动退出
|
||||||
await _hub.Clients.Client(connnectionId).SendAsync("forceOut", "你已被强制退出!");
|
await _hub.Clients.Client(connnectionId).SendAsync("forceOut", "你已被强制退出!");
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Volo.Abp.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace Yi.Framework.Rbac.Application.SignalRHubs
|
||||||
|
{
|
||||||
|
[HubRoute("/hub/notice")]
|
||||||
|
public class NoticeHub : AbpHub
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 由于发布功能,主要是服务端项客户端主动推送
|
||||||
|
/// </summary>
|
||||||
|
public NoticeHub()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,14 +10,14 @@ namespace Yi.Framework.Rbac.Application.SignalRHubs
|
|||||||
{
|
{
|
||||||
[HubRoute("/hub/main")]
|
[HubRoute("/hub/main")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class OnlineUserHub : AbpHub
|
public class OnlineHub : AbpHub
|
||||||
{
|
{
|
||||||
public static readonly List<OnlineUserModel> clientUsers = new();
|
public static readonly List<OnlineUserModel> clientUsers = new();
|
||||||
private readonly static object objLock = new object();
|
private readonly static object objLock = new object();
|
||||||
|
|
||||||
private HttpContext? _httpContext;
|
private HttpContext? _httpContext;
|
||||||
private ILogger<OnlineUserHub> _logger => LoggerFactory.CreateLogger<OnlineUserHub>();
|
private ILogger<OnlineHub> _logger => LoggerFactory.CreateLogger<OnlineHub>();
|
||||||
public OnlineUserHub(IHttpContextAccessor httpContextAccessor)
|
public OnlineHub(IHttpContextAccessor httpContextAccessor)
|
||||||
{
|
{
|
||||||
_httpContext = httpContextAccessor?.HttpContext;
|
_httpContext = httpContextAccessor?.HttpContext;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user