using Connected.Net.Messaging; using Connected.Security.Identity; using Microsoft.AspNetCore.SignalR; namespace Connected.Net.Hubs; public abstract class StatefulHub : Hub> { protected StatefulHub(IServer server) { Server = server; } protected IServer Server { get; } /// /// This method is called by the client connection /// /// /// public async Task Notify(TArgs args) { await Server.Receive(args); } /// /// This method is called by the client connection /// /// /// public async Task Acknowledge(MessageAcknowledgeArgs args) { await Server.Acknowledge(Context.ConnectionId, args); } public override async Task OnConnectedAsync() { var user = 0; if (Context.User?.Identity is UserIdentity identity && identity.User is not null) user = identity.User.Id; Server.Clients.AddOrUpdate(new Client(Context.ConnectionId) { User = user, Behavior = MessageClientBehavior.Reliable }); await base.OnConnectedAsync(); } }