using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Sockets; using SocketsSample.Hubs; namespace SocketsSample.EndPoints.Hubs { public class UserProxy : IClientProxy { private readonly string _userId; private readonly HubLifetimeManager _lifetimeManager; public UserProxy(HubLifetimeManager lifetimeManager, string userId) { _lifetimeManager = lifetimeManager; _userId = userId; } public Task Invoke(string method, params object[] args) { return _lifetimeManager.InvokeUser(_userId, method, args); } } public class GroupProxy : IClientProxy { private readonly string _groupName; private readonly HubLifetimeManager _lifetimeManager; public GroupProxy(HubLifetimeManager lifetimeManager, string groupName) { _lifetimeManager = lifetimeManager; _groupName = groupName; } public Task Invoke(string method, params object[] args) { return _lifetimeManager.InvokeGroup(_groupName, method, args); } } public class AllClientProxy : IClientProxy { private readonly HubLifetimeManager _lifetimeManager; public AllClientProxy(HubLifetimeManager lifetimeManager) { _lifetimeManager = lifetimeManager; } public Task Invoke(string method, params object[] args) { // TODO: More than just chat return _lifetimeManager.InvokeAll(method, args); } } public class SingleClientProxy : IClientProxy { private readonly string _connectionId; private readonly HubLifetimeManager _lifetimeManager; public SingleClientProxy(HubLifetimeManager lifetimeManager, string connectionId) { _lifetimeManager = lifetimeManager; _connectionId = connectionId; } public Task Invoke(string method, params object[] args) { return _lifetimeManager.InvokeConnection(_connectionId, method, args); } } public class GroupManager : IGroupManager { private readonly Connection _connection; private HubLifetimeManager _lifetimeManager; public GroupManager(Connection connection, HubLifetimeManager lifetimeManager) { _connection = connection; _lifetimeManager = lifetimeManager; } public void Add(string groupName) { _lifetimeManager.AddGroup(_connection, groupName); } public void Remove(string groupName) { _lifetimeManager.RemoveGroup(_connection, groupName); } } }