js/network.js
changeset 0 54063d8b0412
equal deleted inserted replaced
-1:000000000000 0:54063d8b0412
       
     1 function Network() {
       
     2     /**
       
     3      * The last known Network status.
       
     4      */
       
     5 	this.lastReachability = null;
       
     6 };
       
     7 
       
     8 Network.prototype.isReachable = function(hostName, successCallback, options) {
       
     9 	var req = new XMLHttpRequest();  
       
    10    	req.open('GET', hostName, true);  
       
    11    	req.onreadystatechange = function (aEvt) {  
       
    12      	if (req.readyState == 4) {  
       
    13         	if(req.status == 200)  
       
    14         		successCallback(NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK);
       
    15          	else  
       
    16           		successCallback(NetworkStatus.NOT_REACHABLE);
       
    17  		}  
       
    18   	};  
       
    19   	req.send(null);
       
    20 
       
    21 };
       
    22 
       
    23 /**
       
    24  * This class contains information about any NetworkStatus.
       
    25  * @constructor
       
    26  */
       
    27 function NetworkStatus() {
       
    28 	this.code = null;
       
    29 	this.message = "";
       
    30 }
       
    31 
       
    32 NetworkStatus.NOT_REACHABLE = 0;
       
    33 NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
       
    34 NetworkStatus.REACHABLE_VIA_WIFI_NETWORK = 2;
       
    35 
       
    36 if (typeof navigator.network == "undefined") navigator.network = new Network();