mirror of
https://gitee.com/shuto-github/cordova-plugin-network-information.git
synced 2026-05-29 00:00:04 +08:00
CB-12895 : added eslint and removed eslint
This commit is contained in:
@@ -21,9 +21,9 @@
|
||||
|
||||
/* global PluginResult */
|
||||
|
||||
//map from BB10 to cordova connection types:
|
||||
//https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js
|
||||
function mapConnectionType(con) {
|
||||
// map from BB10 to cordova connection types:
|
||||
// https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js
|
||||
function mapConnectionType (con) {
|
||||
switch (con.type) {
|
||||
case 'wired':
|
||||
return 'ethernet';
|
||||
@@ -43,17 +43,16 @@ function mapConnectionType(con) {
|
||||
case 'lte':
|
||||
return '4g';
|
||||
}
|
||||
return "cellular";
|
||||
return 'cellular';
|
||||
}
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
function currentConnectionType() {
|
||||
function currentConnectionType () {
|
||||
try {
|
||||
//possible for webplatform to throw pps exception
|
||||
return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type : 'none' });
|
||||
}
|
||||
catch (e) {
|
||||
// possible for webplatform to throw pps exception
|
||||
return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type: 'none' });
|
||||
} catch (e) {
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
+10
-12
@@ -18,31 +18,29 @@
|
||||
*
|
||||
*/
|
||||
|
||||
var cordova = require('cordova'),
|
||||
proxy = require("cordova/exec/proxy"),
|
||||
Connection = require('./Connection');
|
||||
var cordova = require('cordova');
|
||||
var proxy = require('cordova/exec/proxy');
|
||||
var Connection = require('./Connection');
|
||||
|
||||
var type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
|
||||
|
||||
// Subscribe to 'native' online/offline events
|
||||
function onStatusChange(evt) {
|
||||
function onStatusChange (evt) {
|
||||
type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
|
||||
// force async
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
cordova.fireDocumentEvent(evt.type);
|
||||
},0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
window.addEventListener('online', onStatusChange);
|
||||
window.addEventListener('offline', onStatusChange);
|
||||
|
||||
proxy.add("NetworkStatus", {
|
||||
getConnectionInfo:function(cbSuccess) {
|
||||
proxy.add('NetworkStatus', {
|
||||
getConnectionInfo: function (cbSuccess) {
|
||||
// force async
|
||||
setTimeout(function(){
|
||||
setTimeout(function () {
|
||||
cbSuccess(type);
|
||||
},0);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -24,73 +24,73 @@
|
||||
and http://w3c.github.io/netinfo/
|
||||
*/
|
||||
|
||||
var Connection = require('./Connection'),
|
||||
modulemapper = require('cordova/modulemapper');
|
||||
var Connection = require('./Connection');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
|
||||
var origConnection = modulemapper.getOriginalSymbol(window, 'navigator.connection');
|
||||
|
||||
module.exports = {
|
||||
|
||||
getConnectionInfo: function(successCallback, errorCallback) {
|
||||
var connection = origConnection || navigator.mozConnection,
|
||||
connectionType = Connection.UNKNOWN;
|
||||
getConnectionInfo: function (successCallback, errorCallback) {
|
||||
var connection = origConnection || navigator.mozConnection;
|
||||
var connectionType = Connection.UNKNOWN;
|
||||
|
||||
if (!connection) {
|
||||
setTimeout(function() {
|
||||
if (!connection) {
|
||||
setTimeout(function () {
|
||||
successCallback(connectionType);
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
var bandwidth = connection.bandwidth;
|
||||
var metered = connection.metered;
|
||||
var type = connection.type;
|
||||
|
||||
if (type !== undefined) {
|
||||
// For more information see:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
|
||||
|
||||
switch (type) {
|
||||
case 'cellular':
|
||||
connectionType = Connection.CELL;
|
||||
break;
|
||||
case 'ethernet':
|
||||
connectionType = Connection.ETHERNET;
|
||||
break;
|
||||
case 'wifi':
|
||||
connectionType = Connection.WIFI;
|
||||
break;
|
||||
case 'none':
|
||||
connectionType = Connection.NONE;
|
||||
break;
|
||||
}
|
||||
} else if (bandwidth !== undefined && metered !== undefined) {
|
||||
/*
|
||||
bandwidth of type double, readonly
|
||||
The user agent must set the value of the bandwidth attribute to:
|
||||
0 if the user is currently offline;
|
||||
Infinity if the bandwidth is unknown;
|
||||
an estimation of the current bandwidth in MB/s (Megabytes per seconds)
|
||||
available for communication with the browsing context active document's
|
||||
domain.
|
||||
|
||||
For more information see:
|
||||
https://developer.mozilla.org/en-US/docs/Web/API/Connection
|
||||
*/
|
||||
|
||||
if (bandwidth === 0) {
|
||||
connectionType = Connection.NONE;
|
||||
} else if (metered && isFinite(bandwidth)) {
|
||||
connectionType = Connection.CELL;
|
||||
} else if (!metered && isFinite(bandwidth)) {
|
||||
connectionType = Connection.WIFI;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
successCallback(connectionType);
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
var bandwidth = connection.bandwidth,
|
||||
metered = connection.metered,
|
||||
type = connection.type;
|
||||
|
||||
if (type !== undefined) {
|
||||
// For more information see:
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
|
||||
|
||||
switch(type) {
|
||||
case "cellular":
|
||||
connectionType = Connection.CELL;
|
||||
break;
|
||||
case "ethernet":
|
||||
connectionType = Connection.ETHERNET;
|
||||
break;
|
||||
case "wifi":
|
||||
connectionType = Connection.WIFI;
|
||||
break;
|
||||
case "none":
|
||||
connectionType = Connection.NONE;
|
||||
break;
|
||||
}
|
||||
} else if (bandwidth !== undefined && metered !== undefined) {
|
||||
/*
|
||||
bandwidth of type double, readonly
|
||||
The user agent must set the value of the bandwidth attribute to:
|
||||
0 if the user is currently offline;
|
||||
Infinity if the bandwidth is unknown;
|
||||
an estimation of the current bandwidth in MB/s (Megabytes per seconds)
|
||||
available for communication with the browsing context active document's
|
||||
domain.
|
||||
|
||||
For more information see:
|
||||
https://developer.mozilla.org/en-US/docs/Web/API/Connection
|
||||
*/
|
||||
|
||||
if (bandwidth === 0) {
|
||||
connectionType = Connection.NONE;
|
||||
} else if (metered && isFinite(bandwidth)) {
|
||||
connectionType = Connection.CELL;
|
||||
} else if (!metered && isFinite(bandwidth)) {
|
||||
connectionType = Connection.WIFI;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
successCallback(connectionType);
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
require("cordova/exec/proxy").add("NetworkStatus", module.exports);
|
||||
require('cordova/exec/proxy').add('NetworkStatus', module.exports);
|
||||
|
||||
+12
-16
@@ -24,15 +24,14 @@
|
||||
var Connection = require('./Connection');
|
||||
|
||||
module.exports = {
|
||||
getConnectionInfo: function(successCallback, errorCallback) {
|
||||
getConnectionInfo: function (successCallback, errorCallback) {
|
||||
var cncType = Connection.NONE;
|
||||
var infoCount = 0;
|
||||
var deviceCapabilities = null;
|
||||
var timerId = 0;
|
||||
var timeout = 300;
|
||||
|
||||
|
||||
function connectionCB() {
|
||||
function connectionCB () {
|
||||
if (timerId !== null) {
|
||||
clearTimeout(timerId);
|
||||
timerId = null;
|
||||
@@ -47,47 +46,44 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
function errorCB(error) {
|
||||
console.log("Error: " + error.code + "," + error.name + "," + error.message);
|
||||
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)) {
|
||||
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)) {
|
||||
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 = setTimeout(function () {
|
||||
timerId = null;
|
||||
infoCount = 1;
|
||||
connectionCB();
|
||||
}, timeout);
|
||||
|
||||
|
||||
if (deviceCapabilities.wifi) {
|
||||
tizen.systeminfo.getPropertyValue("WIFI_NETWORK", wifiSuccessCB, errorCB);
|
||||
tizen.systeminfo.getPropertyValue('WIFI_NETWORK', wifiSuccessCB, errorCB);
|
||||
}
|
||||
|
||||
if (deviceCapabilities.telephony) {
|
||||
tizen.systeminfo.getPropertyValue("CELLULAR_NETWORK", cellularSuccessCB, errorCB);
|
||||
tizen.systeminfo.getPropertyValue('CELLULAR_NETWORK', cellularSuccessCB, errorCB);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require("cordova/tizen/commandProxy").add("NetworkStatus", module.exports);
|
||||
require('cordova/tizen/commandProxy').add('NetworkStatus', module.exports);
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*global Windows:true */
|
||||
/* global Windows:true */
|
||||
|
||||
var Connection = require('./Connection');
|
||||
|
||||
var winNetConn = Windows.Networking.Connectivity;
|
||||
var networkInfo = winNetConn.NetworkInformation;
|
||||
|
||||
function getCurrrentConnectionType() {
|
||||
function getCurrrentConnectionType () {
|
||||
|
||||
var profile = networkInfo.getInternetConnectionProfile();
|
||||
|
||||
@@ -40,26 +40,26 @@ function getCurrrentConnectionType() {
|
||||
// since we use this to detect whether we are online or offline we do check agains InternetAccess
|
||||
// localAccess (airplane mode as an example) or constrainedInternetAccess mean there is no access to the internet available
|
||||
// https://msdn.microsoft.com/library/windows/apps/windows.networking.connectivity.networkconnectivitylevel.aspx
|
||||
if (conLevel != Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) {
|
||||
if (conLevel !== Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) {
|
||||
return Connection.NONE;
|
||||
}
|
||||
|
||||
var connectionType;
|
||||
|
||||
switch (interfaceType) {
|
||||
case 71:
|
||||
connectionType = Connection.WIFI;
|
||||
break;
|
||||
case 6:
|
||||
connectionType = Connection.ETHERNET;
|
||||
break;
|
||||
case 243: // (3GPP WWAN) // Fallthrough is intentional
|
||||
case 244: // (3GPP2 WWAN)
|
||||
connectionType = Connection.CELL_3G;
|
||||
break;
|
||||
default:
|
||||
connectionType = Connection.UNKNOWN;
|
||||
break;
|
||||
case 71:
|
||||
connectionType = Connection.WIFI;
|
||||
break;
|
||||
case 6:
|
||||
connectionType = Connection.ETHERNET;
|
||||
break;
|
||||
case 243: // (3GPP WWAN) // Fallthrough is intentional
|
||||
case 244: // (3GPP2 WWAN)
|
||||
connectionType = Connection.CELL_3G;
|
||||
break;
|
||||
default:
|
||||
connectionType = Connection.UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
return connectionType;
|
||||
@@ -67,8 +67,7 @@ function getCurrrentConnectionType() {
|
||||
|
||||
module.exports = {
|
||||
|
||||
getConnectionInfo:function(win,fail,args)
|
||||
{
|
||||
getConnectionInfo: function (win, fail, args) {
|
||||
var reportConnectionInfoOnce = function () {
|
||||
win(getCurrrentConnectionType(), { keepCallback: true });
|
||||
};
|
||||
@@ -76,8 +75,8 @@ module.exports = {
|
||||
// report current connection type
|
||||
setTimeout(reportConnectionInfoOnce, 0);
|
||||
// start traking future changes
|
||||
networkInfo.addEventListener("networkstatuschanged", reportConnectionInfoOnce);
|
||||
networkInfo.addEventListener('networkstatuschanged', reportConnectionInfoOnce);
|
||||
}
|
||||
};
|
||||
|
||||
require("cordova/exec/proxy").add("NetworkStatus",module.exports);
|
||||
require('cordova/exec/proxy').add('NetworkStatus', module.exports);
|
||||
|
||||
Reference in New Issue
Block a user