wanggang
1 year ago
5 changed files with 59 additions and 18 deletions
@ -1,14 +1,29 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using SettleAccount.Job.SignalR; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Controllers |
|||
{ |
|||
public class HomeController : AbpController |
|||
{ |
|||
private readonly IHubContext<PageHub> _hubContext; |
|||
|
|||
public HomeController(IHubContext<PageHub> hubContext) |
|||
{ |
|||
this._hubContext = hubContext; |
|||
} |
|||
|
|||
[ResponseCache(NoStore = true)] |
|||
public ActionResult Index() |
|||
{ |
|||
return File("~/index.html", "text/html"); |
|||
} |
|||
|
|||
public IActionResult Test() |
|||
{ |
|||
this._hubContext.Clients.All.ServerToClient("test", "hello", ""); |
|||
return Json("ok"); |
|||
} |
|||
} |
|||
} |
|||
|
@ -0,0 +1,22 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
|
|||
namespace SettleAccount.Job.SignalR |
|||
{ |
|||
public class PageHub : Hub |
|||
{ |
|||
public override async Task OnConnectedAsync() |
|||
{ |
|||
await this.Groups.AddToGroupAsync(this.Context.ConnectionId, this.Context.ConnectionId).ConfigureAwait(false); |
|||
await Clients.Group(Context.ConnectionId).SendAsync("Connected", Context.ConnectionId).ConfigureAwait(false); |
|||
} |
|||
} |
|||
|
|||
public static class HubExtensions |
|||
{ |
|||
public static void ServerToClient(this IClientProxy clientProxy, string method, string message, string toClient, string? fromClient = null) |
|||
{ |
|||
clientProxy.SendAsync(nameof(ServerToClient), method, message, toClient, fromClient); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue