I've created a new ASP.NET 6 web app. I want to periodically broadcast a message through a SignalR hub, from the server. How can I access the hub from the server? Other answers suggest using GlobalHost but it belongs to a deprecated version of SignalR
Example code from web app Program.cs:
app.MapHub<SiteLayoutHub>("hubs/site");
app.Run();
Task.Factory.StartNew(async () =>
{
var hub = GetSiteLayoutHub(); // How can I get this hub?
while (true)
{
var uiState = GetUIState();
await hub.SendUIUpdateMessage(uiState);
Thread.Sleep(500);
}
});
SiteLayoutHub.cs:
public class SiteLayoutHub : Hub
{
public async Task SendUIUpdateMessage(UIState uiState)
{
await Clients.All.SendAsync("UIUpdateMessage", uiState);
}
}