Yes, Signal R Works
Setup:
Install Microsoft.AspNetCore.SignalR.Client
In your viewmodel or Page add:
using Microsoft.AspNetCore.SignalR.Client;
Declare:
private readonly HubConnection _hubConnection;
On Page or ViewModal creation/constructor:
_hubConnection = new HubConnectionBuilder().WithUrl(HUB_URL).WithAutomaticReconnect().Build();
_hubConnection.On<YourModel>("YOUR_EVENT", (item) =>
{
MainThread.BeginInvokeOnMainThread(async () =>
{
// Do a thing
});
});
Initialise the connection when required:
// Start signalr to get updates
MainThread.BeginInvokeOnMainThread(() =>
{
Task.Run(async () =>
{
try
{
var connected = _hubConnection.State == HubConnectionState.Connected;
if (!connected)
{
await _hubConnection.StartAsync();
await _hubConnection.InvokeAsync("Subscribe", YOUR_IDENTIFIER);
}
}
catch (Exception ex)
{
}
});
});
The url is something like:
SiteUrl + "hubs/Yourhub";
Where your site has something like:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<App.SignalR.Hubs.FilesHub>("hubs/Yourhub");
});