Hi @mythz, yes I use AccountGuid
as the Id of the user. I have changed my OnAuthenticatedAsync
method to set the UserAuthId
to the AccountGuid
which has solved the roles issue.
I can also see that the OnUnsubscribeAsync
is now triggering. I’m hoping that this will resolve my original issue.
@layoric & @mythz do you think that I should still be looking into using Redis Sorted Set to record who is “online” instead of GetAllSubscriptionInfos()
? My new UnSubscribe code is:
OnUnsubscribeAsync = async (sub) =>
{
Guid accountGuid = sub.ServerArgs["AccountGuid"] != null && !String.IsNullOrWhiteSpace(sub.ServerArgs["AccountGuid"]) ? new Guid(sub.ServerArgs["AccountGuid"]) : Guid.Empty;
if (accountGuid != Guid.Empty)
{
using (var service = HostContext.Resolve<ServerEventsSubscribersService>())
{
bool isAccountOnline = service.ServerEvents.GetAllSubscriptionInfos().Any(x =>
x.ServerArgs["AccountGuid"] != null && !String.IsNullOrWhiteSpace(x.ServerArgs["AccountGuid"]) && new Guid(x.ServerArgs["AccountGuid"]) == accountGuid &&
x.SubscriptionId != sub.SubscriptionId);
if (!isAccountOnline)
{
//Send a ServerEvents message to other clients notifying this client has disconnected
}
}
}
}
I have not specified a CacheClient so I assume it will be using MemoryCacheClient. Do you recommend I change this to Redis? I have setup sticky connections at the gateway so clients should go back to the same web server for each request until the sticky connection times out.
Once again, thank you for your help.