cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject webworks commit: CB-5413 Device detection - iterate through all 169.254.x.x networks
Date Fri, 15 Nov 2013 21:01:56 GMT
Updated Branches:
  refs/heads/master fb6a59c1b -> e2c7d813e


CB-5413 Device detection - iterate through all 169.254.x.x networks


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/e2c7d813
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/e2c7d813
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/e2c7d813

Branch: refs/heads/master
Commit: e2c7d813e369b5cc45daebae2a14a43f35449f67
Parents: fb6a59c
Author: Bryan Higgins <bhiggins@blackberry.com>
Authored: Fri Nov 15 14:30:11 2013 -0500
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Fri Nov 15 15:12:21 2013 -0500

----------------------------------------------------------------------
 .../project/cordova/lib/target-utils.js         | 34 +++++++++++---------
 1 file changed, 19 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/e2c7d813/blackberry10/bin/templates/project/cordova/lib/target-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/target-utils.js b/blackberry10/bin/templates/project/cordova/lib/target-utils.js
index 11e6791..e7c8a83 100644
--- a/blackberry10/bin/templates/project/cordova/lib/target-utils.js
+++ b/blackberry10/bin/templates/project/cordova/lib/target-utils.js
@@ -106,18 +106,23 @@ _self = {
     },
 
     findConnectedDevice: function (callback) {
-        var defaultIp = '169.254.0.1';
+        var defaultIp = '169.254.0.1',
+            count = 0,
+            i;
         _self.discoverUsb(function (result) {
-            if (!result) {
-                result = defaultIp;
+            if (!result || result.length === 0) {
+                result = [defaultIp];
+            }
+            for (i = 0; i < result.length; i++) {
+                _self.checkConnection(result[i], 'device', function (connection, ip) {
+                    if (connection)  {
+                        callback(ip);
+                        return;
+                    } else if (++count === result.length) {
+                        callback();
+                    }
+                });
             }
-            _self.checkConnection(result, 'device', function (connection) {
-                if (connection)  {
-                    callback(result);
-                } else {
-                    callback();
-                }
-            });
         });
     },
 
@@ -126,6 +131,7 @@ _self = {
             IP_SPLIT_REGEXP = /(169\.254\.\d{1,3}\.)(\d{1,3})/,
             networkInterfaces = os.networkInterfaces(),
             result,
+            matches = [],
             ni,
             i;
 
@@ -135,16 +141,14 @@ _self = {
                     if (networkInterfaces[ni][i].family === IPV4_TYPE) {
                         result = IP_SPLIT_REGEXP.exec(networkInterfaces[ni][i].address);
                         if (result && result[1] && result[2]) {
-                            callback(result[1] + (result[2] - 1));
-                            return;
+                            matches.push(result[1] + (result[2] - 1));
                         }
                     }
                 }
 
             }
         }
-        //If we haven't found anything callback in defeat
-        callback();
+        callback(matches);
     },
 
     findConnectedSimulator: function (callback) {
@@ -239,7 +243,7 @@ _self = {
                 )),
                 isDeviceConnected = (type === "device" && error && error.code
=== 3);
 
-            callback(isSimConnected || isDeviceConnected);
+            callback(isSimConnected || isDeviceConnected, ip);
         });
     },
 


Mime
View raw message