-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathPlatform.cs
More file actions
83 lines (69 loc) · 2.57 KB
/
Platform.cs
File metadata and controls
83 lines (69 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using IO.Ably.Push;
using IO.Ably.Realtime;
using IO.Ably.Transport;
namespace IO.Ably
{
internal class Platform : IPlatform
{
private static readonly object Lock = new object();
private Agent.PlatformRuntime? _platformId;
static Platform()
{
Initialize();
}
internal static bool HookedUpToNetworkEvents { get; private set; }
// Use runtime detection via RuntimeInformation.FrameworkDescription
// This detects the actual runtime version, not the compile-time target framework
// This is important because netstandard2.0 assemblies can run on .NET 6/7/8/9+
// and we want to report the actual runtime being used
public Agent.PlatformRuntime PlatformId
{
get
{
if (_platformId.HasValue)
{
return _platformId.Value;
}
// Default fallback for netstandard2.0 or unknown runtimes
_platformId = Agent.PlatformRuntime.Netstandard20;
try
{
var frameworkDescription = RuntimeInformation.FrameworkDescription;
if (frameworkDescription.StartsWith(".NET 6.", System.StringComparison.OrdinalIgnoreCase))
{
_platformId = Agent.PlatformRuntime.Net6;
}
if (frameworkDescription.StartsWith(".NET 7.", System.StringComparison.OrdinalIgnoreCase))
{
_platformId = Agent.PlatformRuntime.Net7;
}
}
catch
{
// fall back to Netstandard20
}
return _platformId.Value;
}
}
public ITransportFactory TransportFactory => null;
public IMobileDevice MobileDevice { get; set; }
internal static void Initialize()
{
HookedUpToNetworkEvents = false;
}
public void RegisterOsNetworkStateChanged()
{
lock (Lock)
{
if (HookedUpToNetworkEvents == false)
{
NetworkChange.NetworkAvailabilityChanged += (sender, eventArgs) =>
Connection.NotifyOperatingSystemNetworkState(eventArgs.IsAvailable ? NetworkState.Online : NetworkState.Offline);
}
HookedUpToNetworkEvents = true;
}
}
}
}