using EntrustSettle.Common.Const;
using EntrustSettle.Controllers;
using EntrustSettle.Hubs;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
namespace EntrustSettle.Api.Controllers;
///
/// SignalR测试
///
[ApiExplorerSettings(GroupName = ApiGroupNameConst.System)]
public class SignalRTestController : BaseApiController
{
private readonly IHubContext _hubContext;
public SignalRTestController(IHubContext hubContext)
{
_hubContext = hubContext;
}
///
/// 向指定用户发送消息
///
///
///
///
[HttpPost]
public async Task SendMessageToUser(string user, string message)
{
await _hubContext.Clients.Group(user).ReceiveMessage(user, message);
return Ok();
}
///
/// 向指定角色发送消息
///
///
///
///
[HttpPost]
public async Task SendMessageToRole(string role, string message)
{
await _hubContext.Clients.Group(role).ReceiveMessage(role, message);
return Ok();
}
}