12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.SignalR;
- using OASystem.API.OAMethodLib.Hub.HubClients;
- using OASystem.API.OAMethodLib.Hub.Hubs;
- using OASystem.API.OAMethodLib.SignalR.Hubs;
- namespace OASystem.API.Controllers
- {
-
-
-
- [Route("api/[controller]/[action]")]
- public class ClientHubController : ControllerBase
- {
- private readonly ILogger<ClientHubController> _logger;
- private readonly IHubContext<ChatHub, IChatClient> _hubContext;
- public ClientHubController(ILogger<ClientHubController> logger, IHubContext<ChatHub, IChatClient> hubContext )
- {
- _logger = logger;
- _hubContext = hubContext;
- }
-
-
-
-
- [HttpGet("GetAllUserIds", Name = "GetAllUserIds")]
- public List<UserModel> GetAllUserIds()
- {
- return UserStore.OnlineUser;
- }
-
-
-
-
-
-
-
- [HttpPost("SendAllUserMessage", Name = "SendAllUserMessage")]
- public async Task<IActionResult> SendAllUserMessage( string msg)
- {
- await _hubContext.Clients.All.SendAll(msg);
- return Ok("Send Successful!");
- }
-
-
-
-
-
-
-
- [HttpPost("SendCustomUserMessage", Name = "SendCustomUserMessage")]
- public async Task<IActionResult> SendCustomUserMessage(int userid,string date )
- {
- string connId = string.Empty;
- UserModel user = UserStore.OnlineUser.Where(it => it.UserId == userid).FirstOrDefault();
- if (user != null)
- {
- connId = user.ConnectionId;
- }
- await _hubContext.Clients.Client(connId).SendCustomUserMessage(date);
- return Ok("Send Successful!");
- }
- }
- }
|