代码之家  ›  专栏  ›  技术社区  ›  thelittlewozniak

试图在signar内的组中添加客户端,但不起作用

  •  3
  • thelittlewozniak  · 技术社区  · 6 年前

    以下是中心代码:

    public interface IActionClient
    {
        // User is in front of the cameras
        Task HighlightUser(Guid userId);
        // When users added or deleted
        Task UpdateGame(int gameId);
        Task JoinGroupAsync(string groupName);
        Task LeaveGroupAsync(string groupName);
    }
    
    // possible clients
    public enum ClientType
    {
        Leaderboard,
        Dashboard,
        Register
    }
    
    public class OneHub : Hub<IActionClient>
    {
        public OneHub()
        {
        }
    
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();
        }
    
        public async Task JoinGroupAsync(string groupName) => await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
    
        public async Task LeaveGroupAsync(string groupName) => await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
    
        // todo : groups 
    }
    

    当我试图把我的客户添加到组中时:

            // add client to group hub
            await _hubClients.Clients.All.JoinGroupAsync(groupName);
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   user4851087 user4851087    6 年前

        public override Task AddGroupAsync(string connectionId, string groupName)
        {
            if (connectionId == null)
            {
                throw new ArgumentNullException(nameof(connectionId));
            }
    
            if (groupName == null)
            {
                throw new ArgumentNullException(nameof(groupName));
            }
    
            var connection = _connections[connectionId];
            if (connection == null)
            {
                return Task.CompletedTask;
            }
    
            _groups.Add(connection, groupName);
    
            return Task.CompletedTask;
        }
    

    裁判 code

    希望有帮助

    推荐文章