incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [5/18] webos commit: added network connection type api
Date Thu, 05 Apr 2012 19:41:02 GMT
added network connection type api


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/commit/5e8870b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/tree/5e8870b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/diff/5e8870b9

Branch: refs/heads/master
Commit: 5e8870b9030d3b0f8370c30edd65c4bd4371054e
Parents: 89511fe
Author: hermwong <herm.wong@gmail.com>
Authored: Fri Mar 30 14:56:52 2012 -0700
Committer: hermwong <herm.wong@gmail.com>
Committed: Thu Apr 5 12:21:08 2012 -0700

----------------------------------------------------------------------
 framework/index.html |   27 ++++++++++++++++++++++++++-
 js/network.js        |   17 +++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/5e8870b9/framework/index.html
----------------------------------------------------------------------
diff --git a/framework/index.html b/framework/index.html
index 8d0f103..666ea60 100644
--- a/framework/index.html
+++ b/framework/index.html
@@ -78,7 +78,9 @@
     <p>navigator.network.isReachable</p>
     <button id="isReachable" onclick="isReachable();">isReachable</button>
     <p>navigator.network.connection</p>
-    <button id="isReachable" onclick="networkConnection();">connection</button>
+    <button id="connection" onclick="networkConnection();">connection</button>
+    <p>navigator.network.connection.type</p>
+    <button id="connectionType" onclick="networkConnectionType();">connection type</button>
     <div id="networkResult"></div>
     
 </div>
@@ -262,6 +264,29 @@ function networkConnection() {
     var request = navigator.network.connection('palm://com.palm.connectionmanager', successful,
{});
 }
 
+function networkConnectionType() {
+    var netpage = document.getElementById("networkResult");
+ 	netpage.innerHTML = "Requesting connection type...";
+
+     function successful(response) {
+         
+ 		var connection = {};
+            connection[0] = Connection.UNKNOWN;
+            connection[1] = Connection.ETHERNET;
+            connection[2] = Connection.WIFI;
+            connection[3] = Connection.CELL_2G;
+            connection[4] = Connection.CELL_3G;
+            connection[5] = Connection.CELL_4G;
+            connection[6] = Connection.NONE;
+         
+         	var r = JSON.stringify(connection[response]);
+         	netpage.innerHTML = "connection type: ";
+    		netpage.innerHTML += r.replace(/,/g, ', ');
+     }
+
+     var request = navigator.network.connection.type('palm://com.palm.connectionmanager',
successful, {});    
+}
+
 function displayCurrentOrientation() {
 	navigator.notification.showBanner(navigator.orientation.getCurrentOrientation(), 'current
orientaiton'); 
 }	

http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/5e8870b9/js/network.js
----------------------------------------------------------------------
diff --git a/js/network.js b/js/network.js
index d5d6bbf..806ed3f 100755
--- a/js/network.js
+++ b/js/network.js
@@ -41,6 +41,23 @@ Network.prototype.connection = function(hostName, successCallback, options)
{
 	});	
 };
 
+Network.prototype.connection.type = function(hostName, successCallback, options) {
+	navigator.network.isReachable(hostName,successCallback, options);
+};
+
+function Connection() {
+	this.code = null;
+	this.message = "";
+};
+
+Connection.UNKNOWN = 'unknown';
+Connection.ETHERNET = 'ethernet';
+Connection.WIFI = 'wifi';
+Connection.CELL_2G = '2g';
+Connection.CELL_3G = '3g';
+Connection.CELL_4G = '4g';
+Connection.NONE = 'none';
+
 /*
  * This class contains information about any NetworkStatus.
  * @constructor


Mime
View raw message