| /* |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| */ |
| |
| /** |
| * Network status. |
| */ |
| NetworkStatus = { |
| NOT_REACHABLE: 0, |
| REACHABLE_VIA_CARRIER_DATA_NETWORK: 1, |
| 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; |
| }; |
| |
| /** |
| * Determine if a URI is reachable over the network. |
| |
| * @param {Object} uri |
| * @param {Function} callback |
| * @param {Object} options (isIpAddress:boolean) |
| */ |
| Network.prototype.isReachable = function(uri, callback, options) { |
| var isIpAddress = false; |
| if (options && options.isIpAddress) { |
| isIpAddress = options.isIpAddress; |
| } |
| Cordova.exec(callback, null, 'org.apache.cordova.Network', 'isReachable', [uri, isIpAddress]); |
| }; |
| |
| /** |
| * Called by the geolocation framework when the reachability status has changed. |
| * @param {Reachability} reachability The current reachability status. |
| */ |
| // TODO: Callback from native code not implemented for Android |
| Network.prototype.updateReachability = function(reachability) { |
| this.lastReachability = reachability; |
| }; |
| |
| Cordova.addConstructor(function() { |
| if (typeof navigator.network == "undefined") navigator.network = new Network(); |
| }); |