Skip to content
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

[wasm] Support network status information #71941

Closed
wants to merge 18 commits into from

Conversation

maraf
Copy link
Member

@maraf maraf commented Jul 11, 2022

Support these network status related API on browser

  • NetworkInterface.GetIsNetworkAvailable
  • NetworkChange.NetworkAvailabilityChanged

TODO

  • Resolve how it should behave when the browser API is missing
  • Try to control a devtools network status in unit test
  • Try to use playwright and WBT for unit test
  • Try blazor sdk static assets test

Closes #38988

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Jul 11, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Support these network status related API on browser

  • NetworkInterface.GetIsNetworkAvailable
  • NetworkChange.NetworkAvailabilityChanged

Fixes #38988

Author: maraf
Assignees: maraf
Labels:

arch-wasm

Milestone: -

@ghost
Copy link

ghost commented Jul 11, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Support these network status related API on browser

  • NetworkInterface.GetIsNetworkAvailable
  • NetworkChange.NetworkAvailabilityChanged

Fixes #38988

Author: maraf
Assignees: maraf
Labels:

arch-wasm, area-System.Net, new-api-needs-documentation

Milestone: -

@maraf
Copy link
Member Author

maraf commented Jul 11, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maraf
Copy link
Member Author

maraf commented Jul 12, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maraf
Copy link
Member Author

maraf commented Jul 12, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maraf
Copy link
Member Author

maraf commented Jul 12, 2022

The browser API is not supported on V8 and NodeJS. I'm not sure how to deal with this in general, throw or let it fail in JS?

cc @pavelsavara @lewing @kg

@maraf maraf marked this pull request as ready for review July 12, 2022 14:45
@maraf maraf requested a review from lewing as a code owner July 12, 2022 14:45
@kg
Copy link
Contributor

kg commented Jul 12, 2022

The browser API is not supported on V8 and NodeJS. I'm not sure how to deal with this in general, throw or let it fail in JS?

cc @pavelsavara @lewing @kg

I would throw. Then tests can cleanly check for it

@maraf
Copy link
Member Author

maraf commented Jul 12, 2022

I would throw. Then tests can cleanly check for it

Throw when the API is not available at runtime or throw "statically" when running on V8/nodejs? Do we have any general guidance for optional browser APIs?


namespace System.Net.NetworkInformation
{
public partial class NetworkChange
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this like other platform specific partial classes like NetworkAddressChange.Unix.cs?

Copy link
Member Author

@maraf maraf Jul 14, 2022

Choose a reason for hiding this comment

The 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?

@@ -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")]
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

@maraf maraf Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I just drop this one and try to compile with

.\dotnet.cmd build /p:TargetOS=Browser /p:TargetArchitecture=wasm /p:Configuration=Debug .\src\libraries\System.Net.NetworkInformation\src\

it fails with

....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : Compat issues with assembly System.Net.NetworkInformation: [....\src\libraries\System.Net.NetworkInformation\src\Sy
stem.Net.NetworkInformation.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkChange
.NetworkAddressChanged' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("illumos")]' in the implementation. [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation
.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(66,5): error : ApiCompat failed for '....\artifacts\bin\System.Net.NetworkInformation\Debug\net7.0-tvos\System.Net.NetworkInformat
ion.dll' [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : Compat issues with assembly System.Net.NetworkInformation: [....\src\libraries\System.Net.NetworkInformation\src\Sy
stem.Net.NetworkInformation.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkChange
.NetworkAddressChanged' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("illumos")]' in the implementation. [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation
.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(66,5): error : ApiCompat failed for '....\artifacts\bin\System.Net.NetworkInformation\Debug\net7.0-ios\System.Net.NetworkInformati
on.dll' [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : Compat issues with assembly System.Net.NetworkInformation: [....\src\libraries\System.Net.NetworkInformation\src\Sy
stem.Net.NetworkInformation.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(52,5): error : CannotChangeAttribute : Attribute 'System.Runtime.Versioning.UnsupportedOSPlatformAttribute' on 'System.Net.NetworkInformation.NetworkChange
.NetworkAddressChanged' changed from '[UnsupportedOSPlatformAttribute("browser")]' in the contract to '[UnsupportedOSPlatformAttribute("illumos")]' in the implementation. [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation
.csproj]
....\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22358.3\build\Microsoft.DotNet.ApiCompat.targets(66,5): error : ApiCompat failed for '....\artifacts\bin\System.Net.NetworkInformation\Debug\net7.0-osx\System.Net.NetworkInformati
on.dll' [....\src\libraries\System.Net.NetworkInformation\src\System.Net.NetworkInformation.csproj]

Comment on lines +46 to +47
add => throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported);
remove => throw new System.PlatformNotSupportedException(System.SR.SystemNetNetworkInformation_PlatformNotSupported);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding tests should be run for browser, and check for PNSE.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, are we writing a test for every API that is not supported on any platform?
Because this is already not supported on illumos and solaris. Should I run the test also on these platforms?

# Conflicts:
#	src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs
#	src/libraries/apicompat/ApiCompatBaseline.NetCoreAppLatestStable.txt
#	src/mono/wasm/runtime/exports.ts
@maraf
Copy link
Member Author

maraf commented Aug 8, 2022

/azp run runtime-wasm

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maraf maraf added this to the 8.0.0 milestone Sep 7, 2022
@maraf maraf marked this pull request as draft September 7, 2022 09:07
@ghost ghost closed this Oct 7, 2022
@ghost
Copy link

ghost commented Oct 7, 2022

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@maraf maraf reopened this Oct 8, 2022
@ghost ghost closed this Nov 7, 2022
@ghost
Copy link

ghost commented Nov 7, 2022

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[wasm] Implement NetworkInterface.GetIsNetworkAvailable and NetworkChange.NetworkAvailabilityChanged
4 participants