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…
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 thesource, I see
@CordovaProperty() type: string;
but I cannot see where this is set anywhere.
Looking at the plugin it wraps source, I can see the
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
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…
------------ 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!