mirror of
https://gitee.com/xiarenalofs/squad-rain-ops-mini.git
synced 2026-08-12 07:35:38 +08:00
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Microsoft.AspNetCore.SignalR;
|
|
using RainOpsMini.Services;
|
|
using System;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RainOpsMini.Hubs
|
|
{
|
|
public class PresenceHub : Hub
|
|
{
|
|
private readonly OnlineUserService _onlineUserService;
|
|
|
|
public PresenceHub(OnlineUserService onlineUserService)
|
|
{
|
|
_onlineUserService = onlineUserService;
|
|
}
|
|
|
|
public override async Task OnConnectedAsync()
|
|
{
|
|
var username = Context.User?.Identity?.Name;
|
|
if (!string.IsNullOrEmpty(username))
|
|
{
|
|
_onlineUserService.UserConnected(username);
|
|
}
|
|
await base.OnConnectedAsync();
|
|
}
|
|
|
|
public override async Task OnDisconnectedAsync(Exception? exception)
|
|
{
|
|
var username = Context.User?.Identity?.Name;
|
|
if (!string.IsNullOrEmpty(username))
|
|
{
|
|
_onlineUserService.UserDisconnected(username);
|
|
}
|
|
await base.OnDisconnectedAsync(exception);
|
|
}
|
|
}
|
|
}
|