diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 3fd2ad74..75e561b0 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -241,10 +242,15 @@ namespace Infrastructure.Web } public virtual void UseSignalR(IApplicationBuilder app) + { + this.UseSignalR(app); + } + + protected void UseSignalR(IApplicationBuilder app) where T : Hub { app.UseSignalR(routes => { - routes.MapHub("/hub", o => + routes.MapHub("/hub", o => { o.ApplicationMaxBufferSize = long.MaxValue; o.TransportMaxBufferSize = long.MaxValue; diff --git a/projects/Infrastructure/Web/SignalR/PageHub.cs b/projects/Infrastructure/Web/SignalR/BasePageHub.cs similarity index 80% rename from projects/Infrastructure/Web/SignalR/PageHub.cs rename to projects/Infrastructure/Web/SignalR/BasePageHub.cs index d71bb7dc..cbd6f86b 100644 --- a/projects/Infrastructure/Web/SignalR/PageHub.cs +++ b/projects/Infrastructure/Web/SignalR/BasePageHub.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace Infrastructure.Web.SignalR { - public class PageHub : Hub + public class BasePageHub : Hub { public override Task OnConnectedAsync() { @@ -25,10 +25,13 @@ namespace Infrastructure.Web.SignalR return base.OnDisconnectedAsync(exception); } - public Task Send(string group, string method, string message) + public virtual void ServerToClient(string group, string method, string message) + { + Clients.Group(group).SendAsync(method, message); + } + + public virtual void ClientToServer(string message) { - Console.WriteLine($"PageHub>Send {message} To {group}.{message}"); - return Clients.Group(group).SendAsync(method, message); } } } \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs b/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs index 6e0751ee..760ff7c8 100644 --- a/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs +++ b/projects/IoT/IoTServices/FBeeService/Infrastructure/ClientService.cs @@ -38,7 +38,8 @@ namespace FBeeService { try { - this.Connection.SendAsync("Notify", device.ToJson()); + Console.WriteLine("notify to server"); + this.Connection.SendAsync("ClientToServer", device.ToJson()); } catch (Exception ex) { @@ -49,7 +50,7 @@ namespace FBeeService public override void ConnectionOn() { - this.Connection.On("Request", (string path, string queryString) => + this.Connection.On("ServerToClient", (string path, string queryString) => { using (var scope = this.applicationServices.CreateScope()) { diff --git a/projects/IoT/IoTServices/FBeeService/Program.cs b/projects/IoT/IoTServices/FBeeService/Program.cs index 6178b166..05d6a8b1 100644 --- a/projects/IoT/IoTServices/FBeeService/Program.cs +++ b/projects/IoT/IoTServices/FBeeService/Program.cs @@ -26,7 +26,7 @@ namespace FBeeService new EFConfigurationValue { Id = "email:password", Value= "aA123456"}, new EFConfigurationValue { Id = "server.ip", Value= "" }, new EFConfigurationValue { Id = "server.urls", Value= "http://*:8008" }, - new EFConfigurationValue { Id = "notify:enabled", Value= "true"}, + new EFConfigurationValue { Id = "notify:enabled", Value= "false"}, new EFConfigurationValue { Id = "notify:host", Value= $"{host}:8001"}, new EFConfigurationValue { Id = "timer.seconds", Value="600"}, new EFConfigurationValue { Id = "connectId", Value= Guid.NewGuid().ToBase62() }, diff --git a/projects/IoTCenter/Services/PageHub.cs b/projects/IoTCenter/Services/PageHub.cs new file mode 100644 index 00000000..16ad57ba --- /dev/null +++ b/projects/IoTCenter/Services/PageHub.cs @@ -0,0 +1,13 @@ +using Infrastructure.Web.SignalR; +using System; + +namespace IoTCenter.Services +{ + public class PageHub : BasePageHub + { + public override void ClientToServer(string message) + { + Console.WriteLine(message); + } + } +} \ No newline at end of file diff --git a/projects/IoTCenter/Startup.cs b/projects/IoTCenter/Startup.cs index 064297aa..e7b7d1b0 100644 --- a/projects/IoTCenter/Startup.cs +++ b/projects/IoTCenter/Startup.cs @@ -2,6 +2,8 @@ using Application.Services; using Infrastructure.Email; using Infrastructure.Sms; using IoT.UI.Shard; +using IoTCenter.Services; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -23,9 +25,9 @@ namespace IoTCenter base.ConfigureServices(services); } - public override void OnModelCreating(ModelBuilder modelBuilder) + public override void UseSignalR(IApplicationBuilder app) { - base.OnModelCreating(modelBuilder); + this.UseSignalR(app); } } } \ No newline at end of file