// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once #include #include #include #include #include #include "NativeModules.h" namespace winrt::ReactNativeNetInfo::implementation { REACT_STRUCT(NetInfoDetails); struct NetInfoDetails { REACT_FIELD(isConnectionExpensive); bool isConnectionExpensive; REACT_FIELD(cellularGeneration); std::optional cellularGeneration; REACT_FIELD(wifiGeneration); std::optional wifiGeneration; REACT_FIELD(ssid); std::optional ssid; REACT_FIELD(bssid); std::optional bssid; REACT_FIELD(strength); std::optional strength; REACT_FIELD(frequency); std::optional frequency; }; REACT_STRUCT(NetInfoState); struct NetInfoState { /// /// The type of the active network connection /// /// REACT_FIELD(type); std::string type; /// /// Is there an active network connection /// /// REACT_FIELD(isConnected); bool isConnected; /// /// IP Address of the current connection if available /// /// REACT_FIELD(ipAddress); std::string ipAddress; /// /// Is the internet reachable with the active network /// /// REACT_FIELD(isInternetReachable); std::optional isInternetReachable; REACT_FIELD(details); std::optional details; }; REACT_MODULE(RNCNetInfo); struct RNCNetInfo { public: REACT_INIT(Initialize); void Initialize(winrt::Microsoft::ReactNative::ReactContext const& reactContext) noexcept; REACT_METHOD(getCurrentState); winrt::fire_and_forget getCurrentState(std::string requestedInterface, winrt::Microsoft::ReactNative::ReactPromise promise) noexcept; REACT_EVENT(NetworkStatusChanged, L"netInfo.networkStatusDidChange"); std::function NetworkStatusChanged; static std::future GetNetworkStatus(std::string const& requestedInterface = ""); private: winrt::Windows::Networking::Connectivity::NetworkInformation::NetworkStatusChanged_revoker m_networkStatusChangedRevoker{}; }; }