Код: Выделить всё
using Microsoft.AspNetCore.SignalR;
using System.Collections;
using System.Diagnostics;
namespace BulletControls.Hub
{
public class ForumHub : Hub
{
public static Dictionary hubConnections = new Dictionary();
public override async Task OnConnectedAsync()
{
hubConnections.Add(Context.ConnectionId, "");
await Clients.Client(Context.ConnectionId).SendClientConnect(Context.ConnectionId);
}
public override async Task OnDisconnectedAsync(Exception? exception)
{
hubConnections.Remove(Context.ConnectionId);
await base.OnDisconnectedAsync(exception);
}
public async Task RecieveClientSessionGuid(string guid, string connectionId)
{
hubConnections[connectionId] = guid;
}
public async Task SendForumNotificationUpdateToClient(string guid, int commentId)
{
string connectionId = hubConnections.FirstOrDefault(x => x.Value == guid).Key;
await Clients.Client(connectionId).SendForumNotificationUpdateToClient($"{commentId}");
}
public string GetConnectionId(string guid)
{
string connectionId = hubConnections.FirstOrDefault(x => x.Value == guid).Key;
return connectionId;
}
}
public interface IComHub
{
Task SendClientConnect(string message);
Task SendForumNotificationUpdateToClient(string message);
}
}
Код: Выделить всё
[Route("/Forum/Threads/StoreThreadComment")]
public async Task StoreThreadComment(ThreadCommentInput threadComment)
{
forumHub.Clients.Client(??).SendForumNotificationUpdateToClient("");
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... oller-in-n