mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-16 10:58:32 -05:00
Tweak SignalR
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using ChrisKaczor.HomeMonitor.Environment.Service.Data;
|
using ChrisKaczor.HomeMonitor.Environment.Service.Data;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
using MQTTnet;
|
using MQTTnet;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
using Microsoft.AspNetCore.SignalR.Client;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace ChrisKaczor.HomeMonitor.Environment.Service;
|
namespace ChrisKaczor.HomeMonitor.Environment.Service;
|
||||||
|
|
||||||
@@ -12,10 +11,10 @@ public class MessageHandler : IHostedService
|
|||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly Database _database;
|
private readonly Database _database;
|
||||||
private readonly IMqttClient _mqttClient;
|
private readonly IMqttClient _mqttClient;
|
||||||
private HubConnection _hubConnection;
|
|
||||||
|
|
||||||
private readonly MqttFactory _mqttFactory;
|
private readonly MqttFactory _mqttFactory;
|
||||||
private readonly string _topic;
|
private readonly string _topic;
|
||||||
|
private readonly HubConnection _hubConnection;
|
||||||
|
|
||||||
public MessageHandler(IConfiguration configuration, Database database)
|
public MessageHandler(IConfiguration configuration, Database database)
|
||||||
{
|
{
|
||||||
@@ -69,10 +68,10 @@ public class MessageHandler : IHostedService
|
|||||||
|
|
||||||
await _database.StoreMessageAsync(message);
|
await _database.StoreMessageAsync(message);
|
||||||
|
|
||||||
await SendLatestReading(message);
|
await SendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendLatestReading(Message message)
|
private async Task SendMessage(Message message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -81,7 +80,7 @@ public class MessageHandler : IHostedService
|
|||||||
|
|
||||||
var json = JsonSerializer.Serialize(message);
|
var json = JsonSerializer.Serialize(message);
|
||||||
|
|
||||||
await _hubConnection.InvokeAsync("SendLatestReading", json);
|
await _hubConnection.InvokeAsync("SendMessage", json);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ namespace ChrisKaczor.HomeMonitor.Hub.Service.Hubs
|
|||||||
public class EnvironmentHub : Microsoft.AspNetCore.SignalR.Hub
|
public class EnvironmentHub : Microsoft.AspNetCore.SignalR.Hub
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public async Task SendLatestReading(string message)
|
public async Task SendMessage(string message)
|
||||||
{
|
{
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
|
|
||||||
await Clients.Others.SendAsync("LatestReading", message);
|
await Clients.Others.SendAsync("Message", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user