Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
adding connection object
  • Loading branch information
imhotep committed Apr 4, 2012
1 parent 628e8ea commit 07c467f89354e320cf74127c0c68e8257d972737
Showing 3 changed files with 37 additions and 11 deletions.
@@ -70,7 +70,17 @@ <h3>Compass</h3>
<span id="heading"></span>
</div>
</li>
<li>
<h3>Connection</h3>
<div>
<button type="button" class="btn" onclick="getConnection();">getConnectionType</button>
</div>
<div>
<span id="connection"></span>
</div>
</li>
</ul>
<script type="text/javascript" src="./js/connection.js"></script>
<script type="text/javascript" src="./js/accelerometer.js"></script>
<script type="text/javascript" src="./js/compass.js"></script>
<script type="text/javascript" src="./js/device.js"></script>
@@ -1,4 +1,4 @@
Connection = {
var Connection = {
UNKNOWN: "unknown",
ETHERNET: "ethernet",
WIFI: "wifi",
@@ -7,24 +7,31 @@ Connection = {
CELL_4G: "4g",
NONE: "none"
};

// We can't tell if a cell connection is 2,3 or 4G.
// We just know if it's connected and the signal strength
// if it's roaming and the network name etc..so unless wifi we default to UNKNOWN
function NetworkConnection() {
this.type = Connection.UNKNOWN;
var self = this;
var info = deviceapis.devicestatus;

info.getPropertyValue(function(value) {
var error = function(error) {
console.log(JSON.stringify(error));
};

deviceapis.devicestatus.getPropertyValue(function(value) {
console.log("Device WiFi network status: "+value);
if(value == "connected") {
self.type = Connection.WIFI;
}
}, error, {aspect: "WiFiNetwork", property: "networkStatus"});

info.getPropertyValue(function(value) {
console.log("Device Cellular network status: "+value);
if(value == "connected") {
self.type = Connection.WIFI;
}
}, error, {aspect: "CellularHardware", property: "status"});
// info.getPropertyValue(function(value) {
// console.log("Device Cellular network status: "+value);
// if(signalStrength > 10) {
// self.type = Connection.CELL_3G;
// }
// }, error, {aspect: "CellularNetwork", property: "signalStrength"});
}

var connection = new NetworkConnection();
navigator.network = {};
navigator.network.connection = new NetworkConnection();
@@ -165,4 +165,13 @@ function clearHeadingWatch() {
document.getElementById("heading").innerHTML = "";
console.log("clearHeadingWatch");
}
}

/*
* Connection
*/

function getConnection() {
var connectionEm = document.getElementById("connection");
connectionEm.innerHTML = "Connection type "+navigator.network.connection.type;
}

0 comments on commit 07c467f

Please sign in to comment.