public override async Task OnConnectedAsync(HubConnectionContext connection) { await EnsureStreamSetup(); try { _connections.Add(connection); var client = _clusterClientProvider.GetClient().GetClientGrain(_hubName, connection.ConnectionId); await client.OnConnect(_serverId); _logger.LogInformation("Connected {connectionId} on hub {hubName} with userId {userId} (serverId: {serverId})", connection.ConnectionId, _hubName, connection.UserIdentifier, _serverId); if (connection.User.Identity.IsAuthenticated) { var user = _clusterClientProvider.GetClient().GetUserGrain(_hubName, connection.UserIdentifier); await user.Add(connection.ConnectionId); } } catch (Exception ex) { _logger.LogError(ex, "An error has occurred 'OnConnectedAsync' while adding connection {connectionId} on hub {hubName} with userId {userId} (serverId: {serverId})", connection?.ConnectionId, _hubName, connection?.UserIdentifier, _serverId); _connections.Remove(connection); throw; } }
/// <inheritdoc /> public override Task OnDisconnectedAsync(HubConnectionContext connection) { _connections.Remove(connection); var tasks = new List <Task>(); var connectionChannel = _channels.Connection(connection.ConnectionId); RedisLog.Unsubscribe(_logger, connectionChannel); tasks.Add(_bus !.UnsubscribeAsync(connectionChannel)); var feature = connection.Features.Get <IRedisFeature>() !; var groupNames = feature.Groups; if (groupNames != null) { // Copy the groups to an array here because they get removed from this collection // in RemoveFromGroupAsync foreach (var group in groupNames.ToArray()) { // Use RemoveGroupAsyncCore because the connection is local and we don't want to // accidentally go to other servers with our remove request. tasks.Add(RemoveGroupAsyncCore(connection, group)); } } if (!string.IsNullOrEmpty(connection.UserIdentifier)) { tasks.Add(RemoveUserAsync(connection)); } return(Task.WhenAll(tasks)); }
public override async Task OnDisconnectedAsync(HubConnectionContext connection) { await _wrappedHubLifetimeManager.OnDisconnectedAsync(connection); _connections.Remove(connection); await _userTracker.RemoveUser(connection.ConnectionId); }
public override async Task OnDisconnectedAsync(HubConnectionContext connection) { try { _logger.LogDebug("Handle disconnection {connectionId} on hub {hubName} (serverId: {serverId})", connection.ConnectionId, _hubName, _serverId); var client = _clusterClientProvider.GetClient().GetClientGrain(_hubName, connection.ConnectionId); await client.OnDisconnect("hub-disconnect"); } finally { _connections.Remove(connection); } }
/// <inheritdoc /> public override Task OnDisconnectedAsync(HubConnectionContext connection) { _connections.Remove(connection); var emptyGroups = _groups.RemoveDisconnectedConnection(connection.ConnectionId); var actions = new List <DirectoryAction>(); actions.Add(DirectoryAction.RemoveConnection(_hubName, connection.ConnectionId)); if (!string.IsNullOrEmpty(connection.UserIdentifier)) { actions.Add(DirectoryAction.RemoveUser(_hubName, connection.UserIdentifier)); } actions.AddRange(emptyGroups.Select(g => DirectoryAction.RemoveGroup(_hubName, g))); return(_localDirectory.PerformActions(actions)); }
/// <inheritdoc /> public override Task OnDisconnectedAsync(HubConnectionContext connection) { _connections.Remove(connection); _groups.RemoveDisconnectedConnection(connection.ConnectionId); return(Task.CompletedTask); }