using IM_API.Dtos; using IM_API.Interface.Services; using IM_API.Tools; using Microsoft.AspNetCore.SignalR; using System.Security.Claims; namespace IM_API.Hubs { public class ChatHub:Hub { private IJWTService _JWTService; public ChatHub(IJWTService jWTService) { _JWTService = jWTService; } public async override Task OnConnectedAsync() { var userIdStr = Context.User.FindFirstValue(ClaimTypes.NameIdentifier); if(userIdStr is null) { await Clients.Caller.SendAsync("ReceiveMessage",new BaseResponse(CodeDefine.AUTH_FAILED)); Context.Abort(); return; } int userId = int.Parse(userIdStr); await base.OnConnectedAsync(); } public async Task SendMessage(MessageBaseDto dto) { await Clients.Caller.SendAsync("ReceiveMessage", "qwfqwfqw","test"); } } }