-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[wasm] Support network status information #71941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
648a4a6
3fbd1d7
67bb6de
4919918
2b8856e
d314fca
7eb6f8d
2baf83f
2ee970e
1a1eca2
947d325
2afa020
dfa5a6c
1d71019
23c1eb8
febd72b
bc03544
5ccf469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Net.NetworkInformation | ||
| { | ||
| internal static class IPGlobalPropertiesPal | ||
| { | ||
| public static IPGlobalProperties GetIPGlobalProperties() => throw new PlatformNotSupportedException(); | ||
maraf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| using System.ComponentModel; | ||
| using System.Collections.Generic; | ||
| using System.Net.Sockets; | ||
| using System.Runtime.Versioning; | ||
| using System.Threading; | ||
|
|
||
| namespace System.Net.NetworkInformation | ||
| { | ||
| public partial class NetworkChange | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not do this like other platform specific partial classes like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what do you mean. Can you please give me a clue? |
||
| { | ||
| private static event NetworkAvailabilityChangedEventHandler? s_networkAvailabilityChanged; | ||
|
|
||
| [UnsupportedOSPlatform("illumos")] | ||
| [UnsupportedOSPlatform("solaris")] | ||
| public static event NetworkAvailabilityChangedEventHandler? NetworkAvailabilityChanged | ||
| { | ||
| add | ||
| { | ||
| if (s_networkAvailabilityChanged == null) | ||
pavelsavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| BrowserNetworkInterfaceInterop.AddChangeListener(OnNetworkChanged); | ||
|
|
||
| s_networkAvailabilityChanged += value; | ||
| } | ||
| remove | ||
| { | ||
| s_networkAvailabilityChanged -= value; | ||
maraf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| private static void OnNetworkChanged(bool isOnline) | ||
| { | ||
| if (s_networkAvailabilityChanged != null) | ||
| s_networkAvailabilityChanged?.Invoke(null, new NetworkAvailabilityEventArgs(isOnline)); | ||
| } | ||
|
|
||
| [UnsupportedOSPlatform("browser")] | ||
| [UnsupportedOSPlatform("illumos")] | ||
| [UnsupportedOSPlatform("solaris")] | ||
| public static event NetworkAddressChangedEventHandler? NetworkAddressChanged | ||
| { | ||
| add => throw new PlatformNotSupportedException(); | ||
| remove => throw new PlatformNotSupportedException(); | ||
| } | ||
|
|
||
| [EditorBrowsableAttribute(EditorBrowsableState.Never)] | ||
| [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] | ||
| public NetworkChange() | ||
| { | ||
| } | ||
|
|
||
| // Introduced for supporting design-time loading of System.Windows.dll | ||
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| [Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)] | ||
| public static void RegisterNetworkChange(NetworkChange nc) { } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ public partial class NetworkChange | |
| private static readonly AutoResetEvent s_runLoopStartedEvent = new AutoResetEvent(false); | ||
| private static readonly AutoResetEvent s_runLoopEndedEvent = new AutoResetEvent(false); | ||
|
|
||
| [UnsupportedOSPlatform("browser")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, this shouldn't be needed in platform specific implementation files, since they are included in the build only for the relevant platforms. Same for others.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure? If I hadn't have them, the ApiCompat was complaining.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to include the main .cs file also. What was the output from apicompat?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I just drop this one and try to compile with it fails with |
||
| [UnsupportedOSPlatform("illumos")] | ||
| [UnsupportedOSPlatform("solaris")] | ||
| public static event NetworkAddressChangedEventHandler? NetworkAddressChanged | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices.JavaScript; | ||
|
|
||
| namespace System.Net.NetworkInformation | ||
| { | ||
| internal static partial class BrowserNetworkInterfaceInterop | ||
| { | ||
| [JSImport("INTERNAL.network_wasm_online")] | ||
| public static partial bool IsOnline(); | ||
|
|
||
| [JSImport("INTERNAL.network_wasm_add_change_listener")] | ||
| public static partial void AddChangeListener([JSMarshalAs<JSType.Function<JSType.Boolean>>] Action<bool> handler); | ||
| } | ||
|
|
||
| internal static class NetworkInterfacePal | ||
| { | ||
| public static NetworkInterface[] GetAllNetworkInterfaces() => throw new PlatformNotSupportedException(); | ||
| public static int IPv6LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); | ||
| public static int LoopbackInterfaceIndex => throw new PlatformNotSupportedException(); | ||
maraf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public static bool GetIsNetworkAvailable() | ||
| { | ||
| return BrowserNetworkInterfaceInterop.IsOnline(); | ||
| } | ||
maraf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| export function network_wasm_online(): boolean { | ||
| return globalThis.navigator && globalThis.navigator.onLine; | ||
| } | ||
|
|
||
| export function network_wasm_add_change_listener(listener: (onLine: boolean) => void): void { | ||
| window.addEventListener("offline", () => listener(network_wasm_online())); | ||
| window.addEventListener("online", () => listener(network_wasm_online())); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.