incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [17/18] webos commit: added network connection api
Date Thu, 05 Apr 2012 19:41:02 GMT
added network connection 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/462a9d5e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/tree/462a9d5e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/diff/462a9d5e

Branch: refs/heads/master
Commit: 462a9d5ed320ccfdced35494018c02778fb9fd45
Parents: 198b13c
Author: hermwong <herm.wong@gmail.com>
Authored: Thu Mar 29 17:03:08 2012 -0700
Committer: hermwong <herm.wong@gmail.com>
Committed: Thu Mar 29 17:03:08 2012 -0700

----------------------------------------------------------------------
 framework/cordova-1.6.0.js |   26 ++++++++++++++++++++++----
 framework/index.html       |   28 +++++++++++++++++++++++-----
 js/network.js              |   26 ++++++++++++++++++++++----
 3 files changed, 67 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/462a9d5e/framework/cordova-1.6.0.js
----------------------------------------------------------------------
diff --git a/framework/cordova-1.6.0.js b/framework/cordova-1.6.0.js
index 23215f2..66b6848 100644
--- a/framework/cordova-1.6.0.js
+++ b/framework/cordova-1.6.0.js
@@ -1369,11 +1369,18 @@ Network.prototype.isReachable = function(hostName, successCallback,
options) {
 	    method: 'getstatus',
 	    parameters: {},
 	    onSuccess: function(result) { 
+		
 			var status = NetworkStatus.NOT_REACHABLE;
-			if (result.isInternetConnectionAvailable == true)
-			{
-				// don't know whether its via wifi or carrier ... so return the worst case
-				status = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
+			if (result.isInternetConnectionAvailable == true) {
+
+				if (result.wan.state == "connected") {
+					status = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
+				}
+				
+				if (result.wifi.state == "connected") {
+					status = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
+				}
+							
 			}
 			successCallback(status); 
 		},
@@ -1382,6 +1389,17 @@ Network.prototype.isReachable = function(hostName, successCallback,
options) {
 
 };
 
+Network.prototype.connection = function(hostName, successCallback, options) {
+	this.request = navigator.service.Request('palm://com.palm.connectionmanager', {
+	    method: 'getstatus',
+	    parameters: {},
+	    onSuccess: function(result) { 
+			successCallback(result); 
+		},
+	    onFailure: function() {}
+	});	
+};
+
 /*
  * This class contains information about any NetworkStatus.
  * @constructor

http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/462a9d5e/framework/index.html
----------------------------------------------------------------------
diff --git a/framework/index.html b/framework/index.html
index fb62362..8d0f103 100644
--- a/framework/index.html
+++ b/framework/index.html
@@ -31,7 +31,7 @@
 	<a onclick="page('screen');">Adjust Screen Settings</a>
 	<a onclick="page('notifications');">Notification Examples</a>
 	<a onclick="info();">Show Device Info</a>
-	<a onclick="net();">Show Network Info</a>		
+	<a onclick="page('net');">Show Network Info</a>		
 	<a onclick="window.debug.log('trace this');">Console Logging</a>
 	<a onclick="launchmap()">Launch Map App</a>
 	<a onclick="navigator.window.newCard('dashboard.html'); menu(false);">Launch New Card</a>
@@ -74,7 +74,14 @@
 
 <div id="info" style="display: none;"></div>
 
-<div id="net" style="display: none;"></div>
+<div id="net" style="display: none;">
+    <p>navigator.network.isReachable</p>
+    <button id="isReachable" onclick="isReachable();">isReachable</button>
+    <p>navigator.network.connection</p>
+    <button id="isReachable" onclick="networkConnection();">connection</button>
+    <div id="networkResult"></div>
+    
+</div>
 
 <div id="camera" style="display: none;"></div>
 
@@ -223,9 +230,8 @@ function storage() {
 	page('storage');
 }
 
-function net() {
-	page('net');
-	var netpage = lastpage;
+function isReachable() {
+	var netpage = document.getElementById("networkResult");
 	netpage.innerHTML = "Requesting network info...";
 	
 	function successful(response) {
@@ -244,6 +250,18 @@ function net() {
 	var request = navigator.network.isReachable('palm://com.palm.connectionmanager', successful,
{});
 }
 
+function networkConnection() {
+    
+    var netpage = document.getElementById("networkResult");
+	netpage.innerHTML = "Requesting connection info...";
+	
+    function successful(response) {
+        netpage.innerHTML = JSON.stringify(response);
+    }
+    
+    var request = navigator.network.connection('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/462a9d5e/js/network.js
----------------------------------------------------------------------
diff --git a/js/network.js b/js/network.js
index 8737baf..d5d6bbf 100755
--- a/js/network.js
+++ b/js/network.js
@@ -10,11 +10,18 @@ Network.prototype.isReachable = function(hostName, successCallback, options)
{
 	    method: 'getstatus',
 	    parameters: {},
 	    onSuccess: function(result) { 
+		
 			var status = NetworkStatus.NOT_REACHABLE;
-			if (result.isInternetConnectionAvailable == true)
-			{
-				// don't know whether its via wifi or carrier ... so return the worst case
-				status = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
+			if (result.isInternetConnectionAvailable == true) {
+
+				if (result.wan.state == "connected") {
+					status = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
+				}
+				
+				if (result.wifi.state == "connected") {
+					status = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
+				}
+							
 			}
 			successCallback(status); 
 		},
@@ -23,6 +30,17 @@ Network.prototype.isReachable = function(hostName, successCallback, options)
{
 
 };
 
+Network.prototype.connection = function(hostName, successCallback, options) {
+	this.request = navigator.service.Request('palm://com.palm.connectionmanager', {
+	    method: 'getstatus',
+	    parameters: {},
+	    onSuccess: function(result) { 
+			successCallback(result); 
+		},
+	    onFailure: function() {}
+	});	
+};
+
 /*
  * This class contains information about any NetworkStatus.
  * @constructor


Mime
View raw message