You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2012/04/05 21:41:02 UTC
[16/18] webos commit: added network connection type api
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/6daae3c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/tree/6daae3c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/diff/6daae3c6
Branch: refs/heads/master
Commit: 6daae3c6930de1e1ee7856cc033f5d820ab4b156
Parents: 462a9d5
Author: hermwong <he...@gmail.com>
Authored: Fri Mar 30 14:56:52 2012 -0700
Committer: hermwong <he...@gmail.com>
Committed: Fri Mar 30 14:56:52 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/6daae3c6/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/6daae3c6/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