mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-03-15 12:51:00 +08:00
Merge pull request #59 from maverickmishra/master
CB-13663 : Removed deprecated platforms
This commit is contained in:
commit
f294a194c9
38
README.md
38
README.md
@ -45,15 +45,10 @@ Report issues with this plugin on the [Apache Cordova issue tracker][Apache Cord
|
|||||||
|
|
||||||
## Supported Platforms
|
## Supported Platforms
|
||||||
|
|
||||||
- Amazon Fire OS
|
|
||||||
- Android
|
- Android
|
||||||
- BlackBerry 10
|
|
||||||
- Browser
|
- Browser
|
||||||
- iOS
|
- iOS
|
||||||
- Windows Phone 7 and 8
|
|
||||||
- Tizen
|
|
||||||
- Windows
|
- Windows
|
||||||
- Firefox OS
|
|
||||||
|
|
||||||
# Connection
|
# Connection
|
||||||
|
|
||||||
@ -114,27 +109,10 @@ eventually be removed.
|
|||||||
- <iOS7 can't detect the type of cellular network connection.
|
- <iOS7 can't detect the type of cellular network connection.
|
||||||
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
|
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
|
||||||
|
|
||||||
### Windows Phone Quirks
|
|
||||||
|
|
||||||
- When running in the emulator, always detects `navigator.connection.type` as `Connection.UNKNOWN`.
|
|
||||||
|
|
||||||
- Windows Phone can't detect the type of cellular network connection.
|
|
||||||
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
|
|
||||||
|
|
||||||
### Windows Quirks
|
### Windows Quirks
|
||||||
|
|
||||||
- When running in the Phone 8.1 emulator, always detects `navigator.connection.type` as `Connection.ETHERNET`.
|
- When running in the Phone 8.1 emulator, always detects `navigator.connection.type` as `Connection.ETHERNET`.
|
||||||
|
|
||||||
### Tizen Quirks
|
|
||||||
|
|
||||||
- Tizen can only detect a WiFi or cellular connection.
|
|
||||||
- `navigator.connection.type` is set to `Connection.CELL_2G` for all cellular data.
|
|
||||||
|
|
||||||
### Firefox OS Quirks
|
|
||||||
|
|
||||||
- Firefox OS can't detect the type of cellular network connection.
|
|
||||||
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
|
|
||||||
|
|
||||||
### Browser Quirks
|
### Browser Quirks
|
||||||
|
|
||||||
- Browser can't detect the type of network connection.
|
- Browser can't detect the type of network connection.
|
||||||
@ -173,14 +151,6 @@ function onOffline() {
|
|||||||
|
|
||||||
During initial startup, the first offline event (if applicable) takes at least a second to fire.
|
During initial startup, the first offline event (if applicable) takes at least a second to fire.
|
||||||
|
|
||||||
### Windows Phone 7 Quirks
|
|
||||||
|
|
||||||
When running in the Emulator, the `connection.status` is always unknown, so this event does _not_ fire.
|
|
||||||
|
|
||||||
### Windows Phone 8 Quirks
|
|
||||||
|
|
||||||
The Emulator reports the connection type as `Cellular`, which does not change, so the event does _not_ fire.
|
|
||||||
|
|
||||||
## online
|
## online
|
||||||
|
|
||||||
This event fires when an application goes online, and the device
|
This event fires when an application goes online, and the device
|
||||||
@ -215,14 +185,6 @@ During initial startup, the first `online` event (if applicable) takes
|
|||||||
at least a second to fire, prior to which `connection.type` is
|
at least a second to fire, prior to which `connection.type` is
|
||||||
`UNKNOWN`.
|
`UNKNOWN`.
|
||||||
|
|
||||||
### Windows Phone 7 Quirks
|
|
||||||
|
|
||||||
When running in the Emulator, the `connection.status` is always unknown, so this event does _not_ fire.
|
|
||||||
|
|
||||||
### Windows Phone 8 Quirks
|
|
||||||
|
|
||||||
The Emulator reports the connection type as `Cellular`, which does not change, so events does _not_ fire.
|
|
||||||
|
|
||||||
## Sample: Upload a File Depending on your Network State <a name="sample"></a>
|
## Sample: Upload a File Depending on your Network State <a name="sample"></a>
|
||||||
|
|
||||||
The code examples in this section show examples of changing app behavior using the online and offline events and your network connection status.
|
The code examples in this section show examples of changing app behavior using the online and offline events and your network connection status.
|
||||||
|
18
package.json
18
package.json
@ -1,22 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "cordova-plugin-network-information",
|
"name": "cordova-plugin-network-information",
|
||||||
"version": "1.3.5-dev",
|
"version": "2.0.0-dev",
|
||||||
"description": "Cordova Network Information Plugin",
|
"description": "Cordova Network Information Plugin",
|
||||||
"types": "./types/index.d.ts",
|
"types": "./types/index.d.ts",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "cordova-plugin-network-information",
|
"id": "cordova-plugin-network-information",
|
||||||
"platforms": [
|
"platforms": [
|
||||||
"firefoxos",
|
|
||||||
"android",
|
"android",
|
||||||
"amazon-fireos",
|
|
||||||
"ubuntu",
|
|
||||||
"ios",
|
"ios",
|
||||||
"blackberry10",
|
|
||||||
"wp7",
|
|
||||||
"wp8",
|
|
||||||
"windows8",
|
|
||||||
"windows",
|
"windows",
|
||||||
"tizen",
|
|
||||||
"browser"
|
"browser"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -32,17 +24,9 @@
|
|||||||
"network",
|
"network",
|
||||||
"information",
|
"information",
|
||||||
"ecosystem:cordova",
|
"ecosystem:cordova",
|
||||||
"cordova-firefoxos",
|
|
||||||
"cordova-android",
|
"cordova-android",
|
||||||
"cordova-amazon-fireos",
|
|
||||||
"cordova-ubuntu",
|
|
||||||
"cordova-ios",
|
"cordova-ios",
|
||||||
"cordova-blackberry10",
|
|
||||||
"cordova-wp7",
|
|
||||||
"cordova-wp8",
|
|
||||||
"cordova-windows8",
|
|
||||||
"cordova-windows",
|
"cordova-windows",
|
||||||
"cordova-tizen",
|
|
||||||
"cordova-browser"
|
"cordova-browser"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
88
plugin.xml
88
plugin.xml
@ -21,7 +21,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="cordova-plugin-network-information"
|
id="cordova-plugin-network-information"
|
||||||
version="1.3.5-dev">
|
version="2.0.0-dev">
|
||||||
|
|
||||||
<name>Network Information</name>
|
<name>Network Information</name>
|
||||||
<description>Cordova Network Information Plugin</description>
|
<description>Cordova Network Information Plugin</description>
|
||||||
@ -39,12 +39,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
|||||||
<clobbers target="Connection" />
|
<clobbers target="Connection" />
|
||||||
</js-module>
|
</js-module>
|
||||||
|
|
||||||
<!-- firefoxos -->
|
|
||||||
<platform name="firefoxos">
|
|
||||||
<js-module src="src/firefoxos/NetworkProxy.js" name="NetworkProxy">
|
|
||||||
<runs />
|
|
||||||
</js-module>
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- android -->
|
<!-- android -->
|
||||||
<platform name="android">
|
<platform name="android">
|
||||||
@ -62,34 +56,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
|||||||
|
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- amazon-fireos -->
|
|
||||||
<platform name="amazon-fireos">
|
|
||||||
<config-file target="res/xml/config.xml" parent="/*">
|
|
||||||
<feature name="NetworkStatus">
|
|
||||||
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager"/>
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/*">
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
|
|
||||||
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- ubuntu -->
|
|
||||||
<platform name="ubuntu">
|
|
||||||
<config-file target="config.xml" parent="/*">
|
|
||||||
<feature name="Camera">
|
|
||||||
<param policy_group="connectivity" policy_version="1" />
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
<header-file src="src/ubuntu/network_information.h" />
|
|
||||||
<source-file src="src/ubuntu/network_information.cpp" />
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- ios -->
|
<!-- ios -->
|
||||||
<platform name="ios">
|
<platform name="ios">
|
||||||
<config-file target="config.xml" parent="/*">
|
<config-file target="config.xml" parent="/*">
|
||||||
@ -106,51 +72,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
|||||||
<framework src="CoreTelephony.framework" />
|
<framework src="CoreTelephony.framework" />
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- blackberry10 -->
|
|
||||||
<platform name="blackberry10">
|
|
||||||
<source-file src="src/blackberry10/index.js" target-dir="NetworkStatus" />
|
|
||||||
<config-file target="www/config.xml" parent="/widget">
|
|
||||||
<feature name="NetworkStatus" value="NetworkStatus"/>
|
|
||||||
</config-file>
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- wp7 -->
|
|
||||||
<platform name="wp7">
|
|
||||||
<config-file target="config.xml" parent="/*">
|
|
||||||
<feature name="NetworkStatus">
|
|
||||||
<param name="wp-package" value="NetworkStatus"/>
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
|
||||||
<Capability Name="ID_CAP_NETWORKING" />
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/wp/NetworkStatus.cs" />
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- wp8 -->
|
|
||||||
<platform name="wp8">
|
|
||||||
<config-file target="config.xml" parent="/*">
|
|
||||||
<feature name="NetworkStatus">
|
|
||||||
<param name="wp-package" value="NetworkStatus"/>
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
|
||||||
<Capability Name="ID_CAP_NETWORKING" />
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/wp/NetworkStatus.cs" />
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- windows8 -->
|
|
||||||
<platform name="windows8">
|
|
||||||
<js-module src="src/windows/NetworkInfoProxy.js" name="NetworkInfoProxy">
|
|
||||||
<runs/>
|
|
||||||
</js-module>
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- windows -->
|
<!-- windows -->
|
||||||
<platform name="windows">
|
<platform name="windows">
|
||||||
<js-module src="src/windows/NetworkInfoProxy.js" name="NetworkInfoProxy">
|
<js-module src="src/windows/NetworkInfoProxy.js" name="NetworkInfoProxy">
|
||||||
@ -158,13 +79,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
|||||||
</js-module>
|
</js-module>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- tizen -->
|
|
||||||
<platform name="tizen">
|
|
||||||
<js-module src="src/tizen/NetworkProxy.js" name="NetworkProxy">
|
|
||||||
<runs />
|
|
||||||
</js-module>
|
|
||||||
</platform>
|
|
||||||
|
|
||||||
<!-- browser -->
|
<!-- browser -->
|
||||||
<platform name="browser">
|
<platform name="browser">
|
||||||
<js-module src="src/browser/network.js" name="NetworkInfoProxy">
|
<js-module src="src/browser/network.js" name="NetworkInfoProxy">
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* 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) {
|
|
||||||
switch (con.type) {
|
|
||||||
case 'wired':
|
|
||||||
return 'ethernet';
|
|
||||||
case 'wifi':
|
|
||||||
return 'wifi';
|
|
||||||
case 'none':
|
|
||||||
return 'none';
|
|
||||||
case 'cellular':
|
|
||||||
switch (con.technology) {
|
|
||||||
case 'edge':
|
|
||||||
case 'gsm':
|
|
||||||
return '2g';
|
|
||||||
case 'evdo':
|
|
||||||
return '3g';
|
|
||||||
case 'umts':
|
|
||||||
return '3g';
|
|
||||||
case 'lte':
|
|
||||||
return '4g';
|
|
||||||
}
|
|
||||||
return 'cellular';
|
|
||||||
}
|
|
||||||
return 'unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
function currentConnectionType () {
|
|
||||||
try {
|
|
||||||
// possible for webplatform to throw pps exception
|
|
||||||
return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type: 'none' });
|
|
||||||
} catch (e) {
|
|
||||||
return 'unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getConnectionInfo: function (success, fail, args, env) {
|
|
||||||
var result = new PluginResult(args, env);
|
|
||||||
result.ok(currentConnectionType());
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Network API overview: http://www.w3.org/TR/netinfo-api/
|
|
||||||
and http://w3c.github.io/netinfo/
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
var connectionType = Connection.UNKNOWN;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
require('cordova/exec/proxy').add('NetworkStatus', module.exports);
|
|
@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* global tizen */
|
|
||||||
|
|
||||||
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);
|
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "network_information.h"
|
|
||||||
|
|
||||||
void NetworkInformation::getConnectionInfo(int scId, int ecId) {
|
|
||||||
Q_UNUSED(ecId);
|
|
||||||
|
|
||||||
QString result;
|
|
||||||
QNetworkInfo::NetworkMode networkMode = m_systemNetworkInfo.currentNetworkMode();
|
|
||||||
QNetworkInfo::NetworkStatus networkStatus = m_systemNetworkInfo.networkStatus(networkMode, 0);
|
|
||||||
QNetworkInfo::CellDataTechnology cellDataTechnology = m_systemNetworkInfo.currentCellDataTechnology(0);
|
|
||||||
|
|
||||||
if (networkStatus == QNetworkInfo::NoNetworkAvailable)
|
|
||||||
result = "Connection.NONE";
|
|
||||||
|
|
||||||
switch (networkMode) {
|
|
||||||
case QNetworkInfo::WimaxMode:
|
|
||||||
case QNetworkInfo::WlanMode:
|
|
||||||
result = "Connection.WIFI";
|
|
||||||
break;
|
|
||||||
case QNetworkInfo::EthernetMode:
|
|
||||||
result = "Connection.ETHERNET";
|
|
||||||
break;
|
|
||||||
case QNetworkInfo::LteMode:
|
|
||||||
result = "Connection.CELL_4G";
|
|
||||||
break;
|
|
||||||
case QNetworkInfo::GsmMode:
|
|
||||||
case QNetworkInfo::CdmaMode:
|
|
||||||
case QNetworkInfo::TdscdmaMode:
|
|
||||||
case QNetworkInfo::WcdmaMode:
|
|
||||||
switch (cellDataTechnology) {
|
|
||||||
case QNetworkInfo::UmtsDataTechnology:
|
|
||||||
case QNetworkInfo::HspaDataTechnology:
|
|
||||||
result = "Connection.CELL_3G";
|
|
||||||
break;
|
|
||||||
case QNetworkInfo::EdgeDataTechnology:
|
|
||||||
case QNetworkInfo::GprsDataTechnology:
|
|
||||||
result = "Connection.CELL_2G";
|
|
||||||
break;
|
|
||||||
case QNetworkInfo::UnknownDataTechnology:
|
|
||||||
result = "Connection.UNKNOWN";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QNetworkInfo::BluetoothMode:
|
|
||||||
case QNetworkInfo::UnknownMode:
|
|
||||||
result = "Connection.UNKNOWN";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->callback(scId, result);
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef NETWORK_INFORMATION_H
|
|
||||||
#define NETWORK_INFORMATION_H
|
|
||||||
|
|
||||||
#include <cplugin.h>
|
|
||||||
|
|
||||||
#include <QtSystemInfo>
|
|
||||||
#include <QtCore>
|
|
||||||
|
|
||||||
class NetworkInformation: public CPlugin {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit NetworkInformation(Cordova *cordova): CPlugin(cordova) {}
|
|
||||||
|
|
||||||
virtual const QString fullName() override {
|
|
||||||
return NetworkInformation::fullID();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual const QString shortName() override {
|
|
||||||
return "Connection";
|
|
||||||
}
|
|
||||||
|
|
||||||
static const QString fullID() {
|
|
||||||
return "NetworkStatus";
|
|
||||||
}
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void getConnectionInfo(int scId, int ecId);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QNetworkInfo m_systemNetworkInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,129 +0,0 @@
|
|||||||
/*
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Controls;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Ink;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
using Microsoft.Phone.Net.NetworkInformation;
|
|
||||||
|
|
||||||
namespace WPCordovaClassLib.Cordova.Commands
|
|
||||||
{
|
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation(v=VS.92).aspx
|
|
||||||
// http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=VS.92).aspx
|
|
||||||
|
|
||||||
public class NetworkStatus : BaseCommand
|
|
||||||
{
|
|
||||||
const string UNKNOWN = "unknown";
|
|
||||||
const string ETHERNET = "ethernet";
|
|
||||||
const string WIFI = "wifi";
|
|
||||||
const string CELL_2G = "2g";
|
|
||||||
const string CELL_3G = "3g";
|
|
||||||
const string CELL_4G = "4g";
|
|
||||||
const string NONE = "none";
|
|
||||||
const string CELL = "cellular";
|
|
||||||
|
|
||||||
private bool HasCallback = false;
|
|
||||||
|
|
||||||
public NetworkStatus()
|
|
||||||
{
|
|
||||||
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnResume(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e)
|
|
||||||
{
|
|
||||||
this.getConnectionInfo("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getConnectionInfo(string empty)
|
|
||||||
{
|
|
||||||
HasCallback = true;
|
|
||||||
updateConnectionType(checkConnectionType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private string checkConnectionType()
|
|
||||||
{
|
|
||||||
if (DeviceNetworkInformation.IsNetworkAvailable)
|
|
||||||
{
|
|
||||||
if (DeviceNetworkInformation.IsWiFiEnabled)
|
|
||||||
{
|
|
||||||
return WIFI;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return DeviceNetworkInformation.IsCellularDataEnabled ? CELL : UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string checkConnectionType(NetworkInterfaceSubType type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case NetworkInterfaceSubType.Cellular_1XRTT: //cell
|
|
||||||
case NetworkInterfaceSubType.Cellular_GPRS: //cell
|
|
||||||
return CELL;
|
|
||||||
case NetworkInterfaceSubType.Cellular_EDGE: //2
|
|
||||||
return CELL_2G;
|
|
||||||
case NetworkInterfaceSubType.Cellular_3G:
|
|
||||||
case NetworkInterfaceSubType.Cellular_EVDO: //3
|
|
||||||
case NetworkInterfaceSubType.Cellular_EVDV: //3
|
|
||||||
case NetworkInterfaceSubType.Cellular_HSPA: //3
|
|
||||||
return CELL_3G;
|
|
||||||
case NetworkInterfaceSubType.WiFi:
|
|
||||||
return WIFI;
|
|
||||||
case NetworkInterfaceSubType.Unknown:
|
|
||||||
case NetworkInterfaceSubType.Desktop_PassThru:
|
|
||||||
default:
|
|
||||||
return UNKNOWN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeDetected(object sender, NetworkNotificationEventArgs e)
|
|
||||||
{
|
|
||||||
switch (e.NotificationType)
|
|
||||||
{
|
|
||||||
case NetworkNotificationType.InterfaceConnected:
|
|
||||||
updateConnectionType(checkConnectionType(e.NetworkInterface.InterfaceSubtype));
|
|
||||||
break;
|
|
||||||
case NetworkNotificationType.InterfaceDisconnected:
|
|
||||||
updateConnectionType(NONE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateConnectionType(string type)
|
|
||||||
{
|
|
||||||
// This should also implicitly fire offline/online events as that is handled on the JS side
|
|
||||||
if (this.HasCallback)
|
|
||||||
{
|
|
||||||
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
|
|
||||||
result.KeepCallback = true;
|
|
||||||
DispatchCommandResult(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user