# How is the property 'type' property set in the Network plugin

**URL:** <https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248>\
**Category:** Ionic Native\
**Created:** [February 29, 2020, 8:48am UTC](https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248 "2020-02-29T08:48:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterjc](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterjc](https://forum.ionicframework.com/u/peterjc)\
**Post date:** [February 29, 2020, 8:48am UTC](https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248/1 "2020-02-29T08:48:44Z")

</div>

I am using the Ionic Network plugin to notify, and let me know when a device is online/offline.

Specifically I use the `type’ property…

```auto
public isOnline(): boolean {
    let netWorkType = this.network.type;
    this.logger.debug(`Network type: ${netWorkType}`);

    // Use this when running on browser (eg Ionic serve) where plugin does not work
    let isOnline = netWorkType == null ? navigator.onLine : netWorkType != "none"
     return isOnline;
  }

```

This has always seemed to have worked for me, and does always seem to work for my in my environment. However, I have a case, where a Windows version, on a particular corporate network I have `network.type;` return `none`.

Looking into at the[source](https://github.com/ionic-team/ionic-native/blob/8e9575b6aaba3a8ac3186cb40e6c397adb4621f6/src/%40ionic-native/plugins/network/index.ts), I see

```auto
@CordovaProperty() type: string;

```

but I cannot see where this is set anywhere.

Looking at the [plugin it wraps source](https://github.com/apache/cordova-plugin-network-information/blob/97a4967a2e0f0324db4a6d789477ec5f761f2770/src/windows/NetworkInfoProxy.js), I can see the

```auto
function getCurrrentConnectionType ()

```

but I cannot see how this is hooked up to the `type` property if the Ionic wrapper.

Does any one know how the `type` is set, and does is set by the above `getCurrrentConnectionType `?

I want to be able try and diagnose what why I am getting `none` where the device is actually connected (and `http` calls are working)

I have added logging code such as

```auto
 this.networkInfo = w.Windows.Networking.Connectivity.NetworkInformation;      

// get the ConnectionProfile that is currently used to connect to the Internet
const internetProfile = this.networkInfo.getInternetConnectionProfile();
 const message =
        "-- ***logInternetConnectionProfileInfo*** --\n\r"
        + " ------------ Log single profile -----------------\n\r"
        + this.getConnectionProfileInfo(internetProfile);
      this.logger.info(message);
      ...

 /**
   * Helper as per https://docs.microsoft.com/en-au/previous-versions/windows/apps/hh452990(v=win.10)   
   */
  private getConnectionProfileInfo(connectionProfile) {
    if (connectionProfile == null) {
      return "";
    }

    try {
      var returnString = "getConnectionProfileInfo" + "\n\r" + "ProfileName: " + connectionProfile.profileName + "\n\r";

      switch (connectionProfile.getNetworkConnectivityLevel()) {
        case NetworkConnectivityInfo.None:
          returnString += "Connectivity Level: None\n\r";
          break;
        case NetworkConnectivityInfo.LocalAccess:
          returnString += "Connectivity Level: Local Access\n\r";
          break;
        case NetworkConnectivityInfo.ConstrainedInternetAccess:
          returnString += "Connectivity Level: Constrained Internet Access\n\r";
          break;
        case NetworkConnectivityInfo.InternetAccess:
          returnString += "Connectivity Level: Internet Access\n\r";
          break;
      }
...

```

and the logging sent to me I see…

```auto
 ------------ Log single profile -----------------

getConnectionProfileInfo

ProfileName: .

Connectivity Level: Internet Access

Connection Cost Information:

===============

```

So I can see `Connectivity Level: Internet Access`.

So, just wondering first of all were `type` is set so I can start to try to see why I am not getting the correct value.

Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [February 29, 2020, 7:53pm UTC](https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248/2 "2020-02-29T19:53:12Z")

</div>

> [@peterjc](#):
>
> Does any one know how the `type` is set, and does is set by the above `getCurrrentConnectionType ` ?

This is an awesome question, which really exposes how horrendous a language JavaScript is.

The short answer to your question is “yes”.

The longer answer is [here](https://github.com/apache/cordova-plugin-network-information/blob/97a4967a2e0f0324db4a6d789477ec5f761f2770/www/network.js#L60), where `type` is set by the result of calling `getInfo` once Cordova is ready. `getInfo` is “defined” (scare quotes for the ability to “define” functions by hacking `Object.prototype`) [here](https://github.com/apache/cordova-plugin-network-information/blob/97a4967a2e0f0324db4a6d789477ec5f761f2770/www/network.js#L60) as sending the `getConnectionInfo` message across the barrier. On the native side of the barrier, Windows picks the ball up [here](https://github.com/apache/cordova-plugin-network-information/blob/97a4967a2e0f0324db4a6d789477ec5f761f2770/src/windows/NetworkInfoProxy.js#L70), which does indeed call `getCurrrentConnectionType`.

---

<div class="post-metadata">

**Author:** ![peterjc](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterjc](https://forum.ionicframework.com/u/peterjc)\
**Post date:** [March 1, 2020, 1:51am UTC](https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248/3 "2020-03-01T01:51:35Z")

</div>

@rapropos - thankyou very much! That all makes sense. I should have looked into the `www` folder for the missing bits/glue.

Now to find out why I am having problems, everything there (ie in `getCurrrentConnectionType`) looks correct from what I know so far.

Cheers .

---

<div class="post-metadata">

**Author:** ![peterjc](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@peterjc](https://forum.ionicframework.com/u/peterjc)\
**Post date:** [March 3, 2020, 12:25am UTC](https://forum.ionicframework.com/t/how-is-the-property-type-property-set-in-the-network-plugin/184248/4 "2020-03-03T00:25:48Z")

</div>

If anyone else interested, my problem was that the Windows API called by the [plugin](https://github.com/apache/cordova-plugin-network-information/blob/97a4967a2e0f0324db4a6d789477ec5f761f2770/src/windows/NetworkInfoProxy.js) at line 43, required NetworkConnectivityLevel.internetAccess to be considered online

```auto
    // since we use this to detect whether we are online or offline we do check agains InternetAccess
    // localAccess (airplane mode as an example) or constrainedInternetAccess mean there is no access to the internet available
    // https://msdn.microsoft.com/library/windows/apps/windows.networking.connectivity.networkconnectivitylevel.aspx
    if (conLevel !== Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) {
        return Connection.NONE;
    }

```

In my case, on a locked down corp network, I was only getting back NetworkConnectivityLevel.LocalAccess, but this was enough to get to the lock server. I have had to just wrap these calls myself rather than use Network.type (at least for Windows).

Logged an issue [here](https://github.com/apache/cordova-plugin-network-information/issues/100).
