33 lines
827 B
C#
33 lines
827 B
C#
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Blog3000.Client
|
|
{
|
|
public class NetworkStatus
|
|
{
|
|
public event EventHandler StatusChanged;
|
|
|
|
|
|
public NetworkStatus(IJSRuntime jsRuntime)
|
|
=> jsRuntime.InvokeVoidAsync("Network.Init", DotNetObjectReference.Create(this));
|
|
|
|
|
|
[JSInvokable("Network.StatusChanged")]
|
|
public void OnStatusChanged(bool isOnline)
|
|
{
|
|
if (IsOnline != isOnline)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"New net state ${isOnline}");
|
|
IsOnline = isOnline;
|
|
StatusChanged ?.Invoke(this,EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsOnline { get; protected set; } = true;
|
|
}
|
|
}
|