first commit -push
This commit is contained in:
30
RobotNet.WebApp/Clients/DashboardHubClient.cs
Normal file
30
RobotNet.WebApp/Clients/DashboardHubClient.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using RobotNet.Script.Shares.Dashboard;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.WebApp.Clients;
|
||||
|
||||
public class DashboardHubClient : WebAssemblyHubClient
|
||||
{
|
||||
public event Action<DashboardDto>? DashboardDataUpdated;
|
||||
private IDisposable? disDashboardDataUpdated;
|
||||
|
||||
public DashboardHubClient(IAccessTokenProvider tokenProvider, Uri uri) : base(tokenProvider, uri)
|
||||
{
|
||||
disDashboardDataUpdated = Connection.On<DashboardDto>("DashboardDataUpdated", data => DashboardDataUpdated?.Invoke(data));
|
||||
}
|
||||
|
||||
public override async Task StopAsync()
|
||||
{
|
||||
if (disDashboardDataUpdated != null)
|
||||
{
|
||||
disDashboardDataUpdated.Dispose();
|
||||
disDashboardDataUpdated = null;
|
||||
}
|
||||
await base.StopAsync();
|
||||
}
|
||||
|
||||
public async Task<MessageResult<DashboardDto>> GetDashboardData()
|
||||
=> IsConnected ? await Connection.InvokeAsync<MessageResult<DashboardDto>>(nameof(GetDashboardData)) : new(false, "Kết nối thất bại");
|
||||
}
|
||||
Reference in New Issue
Block a user