using Microsoft.AspNetCore.SignalR;
using MoYu.InstantMessaging;
namespace SafeCampus.Web.Core.Hub;
///
/// 预警消息前端订阅
///
[MapHub("/hubs/chathub")]
public class SubscribeHub : Hub
{
// 定义一个方法供客户端调用
public async Task SendMessage(string user, string message)
{
// 触发客户端定义监听的方法
await Clients.All.ReceiveMessage(user, message);
}
///
/// 加入分组
///
///
///
public async Task JoinGroup(string groupName)
{
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
}
///
/// 给分组发送消息
///
///
///
///
///
public async Task SendMessageToGroup(string groupName, string user, string message)
{
await Clients.Group(groupName).ReceiveMessage(user,message);
}
}
public interface IChatClient
{
Task ReceiveMessage(string user, string message);
}