mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
61 lines
1.5 KiB
JavaScript
61 lines
1.5 KiB
JavaScript
|
/**
|
||
|
* This class contains information about any NetworkStatus.
|
||
|
* @constructor
|
||
|
*/
|
||
|
function NetworkStatus() {
|
||
|
this.code = null;
|
||
|
this.message = "";
|
||
|
}
|
||
|
|
||
|
NetworkStatus.NOT_REACHABLE = 0;
|
||
|
NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
|
||
|
NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
|
||
|
|
||
|
/**
|
||
|
* This class provides access to device Network data (reachability).
|
||
|
* @constructor
|
||
|
*/
|
||
|
function Network() {
|
||
|
/**
|
||
|
* The last known Network status.
|
||
|
* { hostName: string, ipAddress: string,
|
||
|
remoteHostStatus: int(0/1/2), internetConnectionStatus: int(0/1/2), localWiFiConnectionStatus: int (0/2) }
|
||
|
*/
|
||
|
this.lastReachability = null;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @param {Function} successCallback
|
||
|
* @param {Function} errorCallback
|
||
|
* @param {Object} options (isIpAddress:boolean)
|
||
|
*/
|
||
|
Network.prototype.isReachable = function(hostName, successCallback, options) {
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Called by the geolocation framework when the reachability status has changed.
|
||
|
* @param {Reachibility} reachability The current reachability status.
|
||
|
*/
|
||
|
Network.prototype.updateReachability = function(reachability) {
|
||
|
this.lastReachability = reachability;
|
||
|
};
|
||
|
|
||
|
PhoneGap.addConstructor(function() {
|
||
|
if (typeof navigator.network == "undefined") navigator.network = new Network();
|
||
|
});
|
||
|
Network.prototype.isReachable = function(uri, win, options)
|
||
|
{
|
||
|
var status = new NetworkStatus();
|
||
|
if(NetworkManager.isReachable(uri))
|
||
|
{
|
||
|
if (NetworkManager.isWifiActive)
|
||
|
status.code = 2;
|
||
|
else
|
||
|
status.code = 1;
|
||
|
}
|
||
|
else
|
||
|
status.code = 0;
|
||
|
win(status);
|
||
|
}
|