using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;

namespace Aurora.Core.Api
{
    public class TranslateRocketHub : Hub
    {
        private readonly ILogger<TranslateRocketHub> _logger;

        public TranslateRocketHub(ILogger<TranslateRocketHub> logger)
        {
            _logger = logger;
        }
        /// <summary>
        /// 客户端连接
        /// </summary>
        /// <returns></returns>
        public override async Task OnConnectedAsync()
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, "SignalR Users");
            await base.OnConnectedAsync();
        }
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");
            await base.OnDisconnectedAsync(exception);
        }

        public async Task SendMessage(string word)
        {
            await Clients.All.SendAsync("rocketWord", word);
        }

    }
}