// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Threading.Tasks; namespace Microsoft.AspNetCore.SignalR.Internal { internal class UserProxy : IClientProxy where THub : Hub { private readonly string _userId; private readonly HubLifetimeManager _lifetimeManager; public UserProxy(HubLifetimeManager lifetimeManager, string userId) { _lifetimeManager = lifetimeManager; _userId = userId; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendUserAsync(_userId, method, args); } } internal class MultipleUserProxy : IClientProxy where THub : Hub { private readonly IReadOnlyList _userIds; private readonly HubLifetimeManager _lifetimeManager; public MultipleUserProxy(HubLifetimeManager lifetimeManager, IReadOnlyList userIds) { _lifetimeManager = lifetimeManager; _userIds = userIds; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendUsersAsync(_userIds, method, args); } } internal class GroupProxy : IClientProxy where THub : Hub { private readonly string _groupName; private readonly HubLifetimeManager _lifetimeManager; public GroupProxy(HubLifetimeManager lifetimeManager, string groupName) { _lifetimeManager = lifetimeManager; _groupName = groupName; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendGroupAsync(_groupName, method, args); } } internal class MultipleGroupProxy : IClientProxy where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; private readonly IReadOnlyList _groupNames; public MultipleGroupProxy(HubLifetimeManager lifetimeManager, IReadOnlyList groupNames) { _lifetimeManager = lifetimeManager; _groupNames = groupNames; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendGroupsAsync(_groupNames, method, args); } } internal class GroupExceptProxy : IClientProxy where THub : Hub { private readonly string _groupName; private readonly HubLifetimeManager _lifetimeManager; private readonly IReadOnlyList _excludedConnectionIds; public GroupExceptProxy(HubLifetimeManager lifetimeManager, string groupName, IReadOnlyList excludedConnectionIds) { _lifetimeManager = lifetimeManager; _groupName = groupName; _excludedConnectionIds = excludedConnectionIds; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendGroupExceptAsync(_groupName, method, args, _excludedConnectionIds); } } internal class AllClientProxy : IClientProxy where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; public AllClientProxy(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendAllAsync(method, args); } } internal class AllClientsExceptProxy : IClientProxy where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; private readonly IReadOnlyList _excludedConnectionIds; public AllClientsExceptProxy(HubLifetimeManager lifetimeManager, IReadOnlyList excludedConnectionIds) { _lifetimeManager = lifetimeManager; _excludedConnectionIds = excludedConnectionIds; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendAllExceptAsync(method, args, _excludedConnectionIds); } } internal class SingleClientProxy : IClientProxy where THub : Hub { private readonly string _connectionId; private readonly HubLifetimeManager _lifetimeManager; public SingleClientProxy(HubLifetimeManager lifetimeManager, string connectionId) { _lifetimeManager = lifetimeManager; _connectionId = connectionId; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendConnectionAsync(_connectionId, method, args); } } internal class MultipleClientProxy : IClientProxy where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; private readonly IReadOnlyList _connectionIds; public MultipleClientProxy(HubLifetimeManager lifetimeManager, IReadOnlyList connectionIds) { _lifetimeManager = lifetimeManager; _connectionIds = connectionIds; } public Task SendCoreAsync(string method, object[] args) { return _lifetimeManager.SendConnectionsAsync(_connectionIds, method, args); } } internal class GroupManager : IGroupManager where THub : Hub { private readonly HubLifetimeManager _lifetimeManager; public GroupManager(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; } public Task AddToGroupAsync(string connectionId, string groupName) { return _lifetimeManager.AddToGroupAsync(connectionId, groupName); } public Task RemoveFromGroupAsync(string connectionId, string groupName) { return _lifetimeManager.RemoveFromGroupAsync(connectionId, groupName); } } }