using Microsoft.AspNetCore.SignalR; using OASystem.API.OAMethodLib.Hub.HubClients; using OASystem.API.OAMethodLib.SignalR.HubService; namespace OASystem.API.OAMethodLib.Hub.Hubs { [Authorize] public class ChatHub : Hub { ILogger _logger; public ChatHub(ILogger logger, CommonService common) { _logger = logger; _common = common; } readonly CommonService _common; /// /// 客户端连接服务端 /// /// public override Task OnConnectedAsync() { var id = Context.ConnectionId; _logger.LogInformation($"Client ConnectionId=> [[{id}]] Already Connection Server!"); return base.OnConnectedAsync(); } /// /// 客户端断开连接 /// /// /// public override Task OnDisconnectedAsync(Exception exception) { var id = Context.ConnectionId; _logger.LogInformation($"Client ConnectionId=> [[{id}]] Already Close Connection Server!"); return base.OnDisconnectedAsync(exception); } /** * 测试 * */ /// /// 给所有客户端发送消息 /// /// public async Task SendMessage(string data) { Console.WriteLine("Have one Data!"); await Clients.All.SendAll(_common.SendAll(data)); } } }