mirror of
https://gitee.com/shuto-github/cordova-plugin-network-information.git
synced 2026-05-29 00:00:04 +08:00
CB-13663 : Removed deprecated platforms
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user