Add SignalR integration for real-time weather updates
Implemented SignalR to enable real-time communication between the server and connected clients. Added a new hub (`WeatherUpdateHub`), a background service (`SignalRSendService`), and modified both the API backend and React frontend for seamless message broadcasting and handling.
This commit is contained in:
14
Api/SignalR/WeatherUpdateHub.cs
Normal file
14
Api/SignalR/WeatherUpdateHub.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace Api.SignalR
|
||||
{
|
||||
public class WeatherUpdateHub: Hub
|
||||
{
|
||||
// This method can be called by connected clients.
|
||||
public async Task SendMessage(string user, string message)
|
||||
{
|
||||
// Broadcast the message to all connected clients.
|
||||
await Clients.All.SendAsync("ReceiveMessage", user, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user