From f8018831b42fa9f534494babcd496f77e4709166 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Thu, 27 Sep 2018 17:43:56 +0200 Subject: added SignalR --- DSACore/Hubs/ChatHub.cs | 16 ++++++++++++++++ DSACore/Startup.cs | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 DSACore/Hubs/ChatHub.cs (limited to 'DSACore') diff --git a/DSACore/Hubs/ChatHub.cs b/DSACore/Hubs/ChatHub.cs new file mode 100644 index 0000000..44d86e1 --- /dev/null +++ b/DSACore/Hubs/ChatHub.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.SignalR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace DSACore.Hubs +{ + public class ChatHub : Hub + { + public async Task SendMessage(string user, string message) + { + await Clients.All.SendAsync("ReciveMessage", user, message); + } + } +} diff --git a/DSACore/Startup.cs b/DSACore/Startup.cs index 2d0c2a3..1745ea4 100644 --- a/DSACore/Startup.cs +++ b/DSACore/Startup.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DSACore.Hubs; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; @@ -26,6 +27,8 @@ namespace DSACore public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + + services.AddSignalR(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -41,6 +44,7 @@ namespace DSACore } app.UseHttpsRedirection(); + app.UseSignalR(routes => { routes.MapHub("/chatHub"); }); app.UseMvc(); } } -- cgit v1.2.3-54-g00ecf