You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Net/Hubs/StatefulHub.cs

50 lines
1.1 KiB

using Connected.Net.Messaging;
using Connected.Security.Identity;
using Microsoft.AspNetCore.SignalR;
namespace Connected.Net.Hubs;
public abstract class StatefulHub<TArgs> : Hub<IEndpointClient<TArgs>>
{
protected StatefulHub(IServer<TArgs> server)
{
Server = server;
}
protected IServer<TArgs> Server { get; }
/// <summary>
/// This method is called by the client connection
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public async Task Notify(TArgs args)
{
await Server.Receive(args);
}
/// <summary>
/// This method is called by the client connection
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
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<TArgs>(Context.ConnectionId)
{
User = user,
Behavior = MessageClientBehavior.Reliable
});
await base.OnConnectedAsync();
}
}