incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject js commit: fixes for network connection
Date Wed, 16 May 2012 12:34:57 GMT
Updated Branches:
  refs/heads/master aa842e36c -> 2bbb1cc07


fixes for network connection


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/2bbb1cc0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/2bbb1cc0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/2bbb1cc0

Branch: refs/heads/master
Commit: 2bbb1cc079e0d50e272c30de7d429b49be2f84b4
Parents: aa842e3
Author: Anis Kadri <anis.kadri@gmail.com>
Authored: Wed May 16 05:34:42 2012 -0700
Committer: Anis Kadri <anis.kadri@gmail.com>
Committed: Wed May 16 05:34:42 2012 -0700

----------------------------------------------------------------------
 lib/bada/plugin/bada/NetworkStatus.js |   52 ++++++++++++++++------------
 1 files changed, 30 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/2bbb1cc0/lib/bada/plugin/bada/NetworkStatus.js
----------------------------------------------------------------------
diff --git a/lib/bada/plugin/bada/NetworkStatus.js b/lib/bada/plugin/bada/NetworkStatus.js
index e22992a..d334cad 100644
--- a/lib/bada/plugin/bada/NetworkStatus.js
+++ b/lib/bada/plugin/bada/NetworkStatus.js
@@ -1,4 +1,5 @@
-var channel = require('cordova/channel');
+var channel = require('cordova/channel'),
+    Connection = require("cordova/plugin/Connection");
 
 // We can't tell if a cell connection is 2,3 or 4G.
 // We just know if it's connected and the signal strength
@@ -6,26 +7,33 @@ var channel = require('cordova/channel');
 
 module.exports = {
     getConnectionInfo: function(success, fail) {
-       var Connection = require("cordova/plugin/Connection");
-       var connectionType = Connection.NONE;
-       deviceapis.devicestatus.getPropertyValue(function(value) {
-               //console.log("Device WiFi network status: "+value);
-               if(value == "connected") {
-                   connectionType = Connection.WIFI;
-               }
-               channel.onCordovaConnectionReady.fire();
-               success(connectionType);
-           },
-           function(error) {
-                console.log(JSON.stringify(error));
-                fail();
-           } , {aspect: "WiFiNetwork", property: "networkStatus"}
-       );
-        //info.getPropertyValue(function(value) {
-        //console.log("Device Cellular network status: "+value);
-        //if(signalStrength > 10) {
-        //self.type = Connection.CELL_3G;
-        //}
-        //}, fail, {aspect: "CellularNetwork", property: "signalStrength"});
+        var connectionType = Connection.NONE;
+        var networkInfo = ["cellular", "wifi"]; // might be a better way to do this
+        var gotConnectionInfo = function() {
+            networkInfo.pop();
+            if(networkInfo.length === 0) {
+                channel.onCordovaConnectionReady.fire();
+                success(connectionType);
+            }
+        };
+        var error = function(e) {
+            console.log("Error "+e.message);
+            gotConnectionInfo();
+        };
+        deviceapis.devicestatus.getPropertyValue(function(value) {
+            console.log("Device Cellular network status: "+value);
+            if(connectionType === Connection.NONE) {
+                connectionType = Connection.CELL_2G;
+            }
+            gotConnectionInfo();
+        }, error, {aspect: "CellularNetwork", property: "signalStrength"});
+
+        deviceapis.devicestatus.getPropertyValue(function(value) {
+            console.log("Device WiFi network status: "+value);
+            if(value == "connected") {
+                connectionType = Connection.WIFI;
+            }
+            gotConnectionInfo();
+        }, error, {aspect: "WiFiNetwork", property: "networkStatus"});
     }
 };


Mime
View raw message