2025-11-16 19:33:01 +08:00

40 lines
1.1 KiB
C#

using Dto.SignalRNet;
using MessagePack;
using Microsoft.AspNetCore.SignalR;
using XPrintServer.Api.Net;
namespace XPrintServer.Api.Hubs
{
public class MsgHub : Hub
{
public override async Task OnDisconnectedAsync(Exception? exception)
{
//string? roomId = Context.Items["RoomID"] as string;
//string? uid = Context.Items["UID"] as string;
////Console.WriteLine("OnDisconnectedAsync");
//if (roomId != null && uid != null)
//{
//}
await base.OnDisconnectedAsync(exception);
}
public override async Task OnConnectedAsync()
{
await base.OnConnectedAsync();
}
public async Task Login(LoginMessage msg)
{
await Groups.AddToGroupAsync(Context.ConnectionId, msg.UserId);
await Groups.AddToGroupAsync(Context.ConnectionId, msg.RoomId);
await Clients.Caller.SendAsync(NetEventKeys.LOGIN_SUCCESS);
}
public async Task Heartbeat()
{
await Clients.Caller.SendAsync(NetEventKeys.HEARTBEAT_SUCCESS).ConfigureAwait(false);
}
}
}