private async Task OnUserMembershipChangedAsync(UserMembershipChanged userMembershipChanged, CancellationToken cancellationToken = default) { if (String.IsNullOrEmpty(userMembershipChanged?.OrganizationId)) { _logger.LogTrace("Ignoring User Membership Changed message: No organization id."); return; } // manage user organization group membership var userConnectionIds = await _connectionMapping.GetUserIdConnectionsAsync(userMembershipChanged.UserId); _logger.LogTrace("Attempting to update user {User} active groups for {UserConnectionCount} connections", userMembershipChanged.UserId, userConnectionIds.Count); foreach (string connectionId in userConnectionIds) { if (userMembershipChanged.ChangeType == ChangeType.Added) { await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId); } else if (userMembershipChanged.ChangeType == ChangeType.Removed) { await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId); } } await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged); }
protected override async Task OnDisconnected(IRequest request, string connectionId, bool stopCalled) { if (request.User.GetOrganizationId() != null) { await _connectionMapping.GroupRemoveAsync(request.User.GetOrganizationId(), connectionId).AnyContext(); } await _connectionMapping.UserIdRemoveAsync(request.User.GetUserId(), connectionId).AnyContext(); }
protected override async Task OnDisconnected(IRequest request, string connectionId, bool stopCalled) { try { foreach (var organizationId in request.User.GetOrganizationIds()) { await _connectionMapping.GroupRemoveAsync(organizationId, connectionId); } await _connectionMapping.UserIdRemoveAsync(request.User.GetUserId(), connectionId); } catch (Exception ex) { _logger.Error(ex, "OnDisconnected Error: {0}", ex.Message); throw; } }
private async Task OnDisconnected(HttpContext context, WebSocket socket, string connectionId) { _logger.LogTrace("WebSocket disconnected {ConnectionId} ({State})", connectionId, socket?.State); try { foreach (string organizationId in context.User.GetOrganizationIds()) { await _connectionMapping.GroupRemoveAsync(organizationId, connectionId); } await _connectionMapping.UserIdRemoveAsync(context.User.GetUserId(), connectionId); } catch (Exception ex) { _logger.LogError(ex, "OnDisconnected Error: {Message}", ex.Message); throw; } }
private async Task OnUserMembershipChangedAsync(UserMembershipChanged userMembershipChanged, CancellationToken cancellationToken = default(CancellationToken)) { if (String.IsNullOrEmpty(userMembershipChanged?.OrganizationId)) { return; } // manage user organization group membership foreach (var connectionId in await _connectionMapping.GetConnectionsAsync(userMembershipChanged.UserId)) { if (userMembershipChanged.ChangeType == ChangeType.Added) { await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId); } else if (userMembershipChanged.ChangeType == ChangeType.Removed) { await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId); } } await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged); }