From a78e4c5dc7a0d257718fb52d0aadbf425fcaf708 Mon Sep 17 00:00:00 2001 From: Salvatore Iovene Date: Thu, 28 Nov 2013 10:44:14 +0200 Subject: [PATCH] Initial implementation of Tizen plugin. --- plugin.xml | 28 +++++++++------ src/tizen/NetworkProxy.js | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 src/tizen/NetworkProxy.js 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" cordova,network,information https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git https://issues.apache.org/jira/browse/CB/component/12320640 - + @@ -20,43 +20,43 @@ xmlns:android="http://schemas.android.com/apk/res/android" - - + + - + - + - + - + - + - + - + - + @@ -109,4 +109,10 @@ xmlns:android="http://schemas.android.com/apk/res/android" + + + + + + 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);