I need to check if a specific user is all connected.
I have the following HashSet that tracks users:
public static class UserHandler
{
public static HashSet<string> ConnectedIds = new HashSet<string>();
}
So, disabled:
public override Task OnDisconnected()
{
UserHandler.ConnectedIds.Remove(this.Context.ConnectionId);
if (UserHandler.ConnectedIds.Count == 0)
{
}
return base.OnDisconnected();
}
and connected:
public override Task OnConnected()
{
Logger.Log.file.Info("[TaskActionStatus HUB => OnConnected] Start");
UserHandler.ConnectedIds.Add(this.Context.ConnectionId);
if (UserHandler.ConnectedIds.Count < 2)
{
}
return base.OnConnected();
}
Now the problem arises when users simply close their browser window. I have no way of knowing if it is disabled.
Therefore, based on some question here , I would call each client and get an answer. I do not know how to do that.
I think I would have this:
public static void CheckConnectedUsers()
{
var context = GlobalHost.ConnectionManager.GetHubContext<TaskActionStatus>();
foreach (var connection in UserHandler.ConnectedIds)
{
context.Clients.Client(connection).verifyConnected("online?");
}
}
BUT, how do I get a response from a client?
EDIT: steps taken:
, , . , , 2 ( ). : 2 , signalR. HashSet 2 . , /. (, , OnDisconnected, HashSet ConnectionId, , "", OnDisonnected, OnConnected, connectionId HashSet. 1 ConnectionId HashSet , HashSet 2 ( , / ), .