Files
Kg.SeaTime/Service/Application.Web/Plug/ChatHub/ChatHub.cs
Putoo 8e1a6ff0ec 111
2026-04-25 18:11:21 +08:00

27 lines
856 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.AspNetCore.SignalR;
namespace Application.Web
{
public class ChatHub:Hub
{
// 客户端调用:发送消息给所有人
public async Task SendMessage(string user, string message)
{
// 推送给所有客户端Clients.All
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
// 可选:连接/断开事件
public override async Task OnConnectedAsync()
{
await Clients.All.SendAsync("UserConnected", Context.ConnectionId);
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
await Clients.All.SendAsync("UserDisconnected", Context.ConnectionId);
await base.OnDisconnectedAsync(exception);
}
}
}