cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/2] git commit: Initial implementation of Tizen plugin.
Date Tue, 28 Jan 2014 06:57:32 GMT
Updated Branches:
  refs/heads/dev 65e423cd7 -> 41642e745


Initial implementation of Tizen plugin.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/commit/a78e4c5d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/tree/a78e4c5d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/diff/a78e4c5d

Branch: refs/heads/dev
Commit: a78e4c5dc7a0d257718fb52d0aadbf425fcaf708
Parents: f1a99e7
Author: Salvatore Iovene <salvatore@iovene.com>
Authored: Thu Nov 28 10:44:14 2013 +0200
Committer: Salvatore Iovene <salvatore@iovene.com>
Committed: Thu Nov 28 10:44:14 2013 +0200

----------------------------------------------------------------------
 plugin.xml                | 28 ++++++++++-------
 src/tizen/NetworkProxy.js | 71 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/a78e4c5d/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 4b4b90e..3e618a8 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -11,7 +11,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
     <keywords>cordova,network,information</keywords>
     <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git</repo>
     <issue>https://issues.apache.org/jira/browse/CB/component/12320640</issue>
-    
+
     <js-module src="www/network.js" name="network">
         <clobbers target="navigator.connection" />
         <clobbers target="navigator.network.connection" />
@@ -20,43 +20,43 @@ xmlns:android="http://schemas.android.com/apk/res/android"
     <js-module src="www/Connection.js" name="Connection">
         <clobbers target="Connection" />
     </js-module>
-                
-    <!-- firefoxos --> 
+
+    <!-- firefoxos -->
     <platform name="firefoxos">
         <config-file target="config.xml" parent="/*">
             <feature name="Network">
                 <param name="firefoxos-package" value="Network" />
             </feature>
-        </config-file>                                         
+        </config-file>
         <js-module src="src/firefoxos/NetworkProxy.js" name="NetworkProxy">
             <runs />
         </js-module>
     </platform>
-            
+
     <!-- android -->
     <platform name="android">
         <config-file target="res/xml/config.xml" parent="/*">
             <feature name="NetworkStatus">
                 <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager"/>
-            </feature>   
+            </feature>
         </config-file>
-        
+
         <config-file target="AndroidManifest.xml" parent="/*">
             <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
         </config-file>
 
         <source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation"
/>
-        
+
     </platform>
 
     <!-- ios -->
-    <platform name="ios">    
+    <platform name="ios">
         <config-file target="config.xml" parent="/*">
             <feature name="NetworkStatus">
-                <param name="ios-package" value="CDVConnection" /> 
+                <param name="ios-package" value="CDVConnection" />
             </feature>
         </config-file>
-        
+
         <header-file src="src/ios/CDVConnection.h" />
         <source-file src="src/ios/CDVConnection.m" />
         <header-file src="src/ios/CDVReachability.h" />
@@ -109,4 +109,10 @@ xmlns:android="http://schemas.android.com/apk/res/android"
         </js-module>
     </platform>
 
+    <!-- tizen -->
+    <platform name="tizen">
+        <js-module src="src/tizen/NetworkProxy.js" name="NetworkProxy">
+            <runs />
+        </js-module>
+    </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/a78e4c5d/src/tizen/NetworkProxy.js
----------------------------------------------------------------------
diff --git a/src/tizen/NetworkProxy.js b/src/tizen/NetworkProxy.js
new file mode 100644
index 0000000..1b7a89a
--- /dev/null
+++ b/src/tizen/NetworkProxy.js
@@ -0,0 +1,71 @@
+var cordova = require('cordova');
+var Connection = require('./Connection');
+
+module.exports = {
+    getConnectionInfo: function(successCallback, errorCallback) {
+        var cncType = Connection.NONE;
+        var infoCount = 0;
+        var deviceCapabilities = null;
+        var timerId = 0;
+        var timeout = 300;
+
+
+        function connectionCB() {
+            if (timerId !== null) {
+                clearTimeout(timerId);
+                timerId = null;
+            }
+
+            infoCount++;
+
+            if (infoCount > 1) {
+                if (successCallback) {
+                    successCallback(cncType);
+                }
+            }
+        }
+
+        function errorCB(error) {
+            console.log("Error: " + error.code + "," + error.name + "," + error.message);
+
+            if (errorCallback) {
+                errorCallback();
+            }
+        }
+
+        function wifiSuccessCB(wifi) {
+            if ((wifi.status === "ON")  && (wifi.ipAddress.length !== 0)) {
+                cncType = Connection.WIFI;
+            }
+            connectionCB();
+        }
+
+        function cellularSuccessCB(cell) {
+            if ((cncType === Connection.NONE) && (cell.status === "ON") &&
(cell.ipAddress.length !== 0)) {
+                cncType = Connection.CELL_2G;
+            }
+            connectionCB();
+        }
+
+
+        deviceCapabilities = tizen.systeminfo.getCapabilities();
+
+
+        timerId = setTimeout(function() {
+            timerId = null;
+            infoCount = 1;
+            connectionCB();
+        }, timeout);
+
+
+        if (deviceCapabilities.wifi) {
+            tizen.systeminfo.getPropertyValue("WIFI_NETWORK", wifiSuccessCB, errorCB);
+        }
+
+        if (deviceCapabilities.telephony) {
+            tizen.systeminfo.getPropertyValue("CELLULAR_NETWORK", cellularSuccessCB, errorCB);
+        }
+    }
+};
+
+require("cordova/tizen/commandProxy").add("NetworkStatus", module.exports);


Mime
View raw message