mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-01-31 10:35:43 +08:00
Initial implementation of Tizen plugin.
This commit is contained in:
parent
f1a99e72fe
commit
a78e4c5dc7
@ -109,4 +109,10 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
<!-- tizen -->
|
||||
<platform name="tizen">
|
||||
<js-module src="src/tizen/NetworkProxy.js" name="NetworkProxy">
|
||||
<runs />
|
||||
</js-module>
|
||||
</platform>
|
||||
</plugin>
|
||||
|
71
src/tizen/NetworkProxy.js
Normal file
71
src/tizen/NetworkProxy.js
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user