From 054396d2422bd545c9f30aeb86d8c65f8289366c Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Wed, 17 Aug 2022 15:58:43 -0400 Subject: [PATCH] Add device status to hub service --- Hub/Service/.vscode/launch.json | 2 +- Hub/Service/Hubs/DeviceStatusHub.cs | 19 +++++++++++++++++++ Hub/Service/Startup.cs | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Hub/Service/Hubs/DeviceStatusHub.cs diff --git a/Hub/Service/.vscode/launch.json b/Hub/Service/.vscode/launch.json index e1c1bf8..5c2caea 100644 --- a/Hub/Service/.vscode/launch.json +++ b/Hub/Service/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ChrisKaczor.HomeMonitor.Hub.Service.dll", + "program": "${workspaceFolder}/bin/Debug/net5.0/ChrisKaczor.HomeMonitor.Hub.Service.dll", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, diff --git a/Hub/Service/Hubs/DeviceStatusHub.cs b/Hub/Service/Hubs/DeviceStatusHub.cs new file mode 100644 index 0000000..5ba3791 --- /dev/null +++ b/Hub/Service/Hubs/DeviceStatusHub.cs @@ -0,0 +1,19 @@ +using JetBrains.Annotations; +using Microsoft.AspNetCore.SignalR; +using System; +using System.Threading.Tasks; + +namespace ChrisKaczor.HomeMonitor.Hub.Service.Hubs +{ + [UsedImplicitly] + public class DeviceStatusHub : Microsoft.AspNetCore.SignalR.Hub + { + [UsedImplicitly] + public async Task SendLatestStatus(string message) + { + Console.WriteLine(message); + + await Clients.Others.SendAsync("LatestStatus", message); + } + } +} \ No newline at end of file diff --git a/Hub/Service/Startup.cs b/Hub/Service/Startup.cs index 78b6e9c..8fe3dc5 100644 --- a/Hub/Service/Startup.cs +++ b/Hub/Service/Startup.cs @@ -33,6 +33,7 @@ namespace ChrisKaczor.HomeMonitor.Hub.Service { endpoints.MapHub("/weather"); endpoints.MapHub("/power"); + endpoints.MapHub("/device-status"); endpoints.MapDefaultControllerRoute(); }); }