mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-01-18 21:52:48 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information
This commit is contained in:
commit
401ea85eef
16
CONTRIBUTING.md
Normal file
16
CONTRIBUTING.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Contributing to Apache Cordova
|
||||
|
||||
Anyone can contribute to Cordova. And we need your contributions.
|
||||
|
||||
There are multiple ways to contribute: report bugs, improve the docs, and
|
||||
contribute code.
|
||||
|
||||
For instructions on this, start with the
|
||||
[contribution overview](http://cordova.apache.org/#contribute).
|
||||
|
||||
The details are explained there, but the important items are:
|
||||
- Sign and submit an Apache ICLA (Contributor License Agreement).
|
||||
- Have a Jira issue open that corresponds to your contribution.
|
||||
- Run the tests so your patch doesn't break existing functionality.
|
||||
|
||||
We look forward to your contributions!
|
5
NOTICE
Normal file
5
NOTICE
Normal file
@ -0,0 +1,5 @@
|
||||
Apache Cordova
|
||||
Copyright 2012 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
@ -46,3 +46,10 @@
|
||||
|
||||
### 0.2.7 (Feb 05, 2014)
|
||||
* Initial implementation of Tizen plugin.
|
||||
|
||||
### 0.2.8 (Apr 17, 2014)
|
||||
* CB-6342: [iOS] iOS reports a cellular connection even when in Airplane mode
|
||||
* CB-6422: [windows8] use cordova/exec/proxy
|
||||
* CB-6460: Update license headers
|
||||
* CB-6465: Add license headers to Tizen code
|
||||
* Add NOTICE file
|
||||
|
@ -37,6 +37,7 @@ wifi connection, and whether the device has an internet connection.
|
||||
- Windows Phone 7 and 8
|
||||
- Tizen
|
||||
- Windows 8
|
||||
- Firefox OS
|
||||
|
||||
# Connection
|
||||
|
||||
@ -108,6 +109,11 @@ eventually be removed.
|
||||
- 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.
|
||||
|
||||
# Network-related Events
|
||||
|
||||
## offline
|
||||
|
25
plugin.xml
25
plugin.xml
@ -1,9 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="org.apache.cordova.network-information"
|
||||
version="0.2.7">
|
||||
version="0.2.9-dev">
|
||||
|
||||
<name>Network Information</name>
|
||||
<description>Cordova Network Information Plugin</description>
|
||||
@ -23,11 +41,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
<!-- firefoxos -->
|
||||
<platform name="firefoxos">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Network">
|
||||
<param name="firefoxos-package" value="Network" />
|
||||
</feature>
|
||||
</config-file>
|
||||
<js-module src="src/firefoxos/NetworkProxy.js" name="NetworkProxy">
|
||||
<runs />
|
||||
</js-module>
|
||||
|
@ -17,44 +17,73 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
Network API overview: http://dvcs.w3.org/hg/dap/raw-file/tip/network-api/Overview.html
|
||||
|
||||
Network API overview: http://www.w3.org/TR/netinfo-api/
|
||||
and http://w3c.github.io/netinfo/
|
||||
*/
|
||||
|
||||
var cordova = require('cordova'),
|
||||
Connection = require('./Connection'),
|
||||
modulemapper = require('cordova/modulemapper');
|
||||
|
||||
var cordova = require('cordova');
|
||||
var origConnection = modulemapper.getOriginalSymbol(window, 'navigator.connection');
|
||||
|
||||
module.exports = {
|
||||
|
||||
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
|
||||
|
||||
getConnectionInfo: function (win, fail, args) {
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
win(connection.bandwidth);
|
||||
},
|
||||
|
||||
isMetered: function (win, fail, args) {
|
||||
/*
|
||||
readonly attribute boolean metered
|
||||
A connection is metered when the user's connection is subject to a limitation from his Internet Service Provider strong enough to request web applications to be careful with the bandwidth usage.
|
||||
module.exports = {
|
||||
|
||||
What is a metered connection is voluntarily left to the user agent to judge. It would not be possible to give an exhaustive list of limitations considered strong enough to flag the connection as metered and even if doable, some limitations can be considered strong or weak depending on the context.
|
||||
Examples of metered connections are mobile connections with a small bandwidth quota or connections with a pay-per use plan.
|
||||
The user agent MUST set the value of the metered attribute to true if the connection with the browsing context active document's domain is metered and false otherwise. If the implementation is not able to know the status of the connection or if the user is offline, the value MUST be set to false.
|
||||
getConnectionInfo: function(successCallback, errorCallback) {
|
||||
var connection = origConnection || navigator.mozConnection,
|
||||
connectionType = Connection.UNKNOWN,
|
||||
bandwidth = connection.bandwidth,
|
||||
metered = connection.metered,
|
||||
type = connection.type;
|
||||
|
||||
If unable to know if a connection is metered, a user agent could ask the user about the status of his current connection.
|
||||
*/
|
||||
win(connection.metered);
|
||||
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/firefoxos/commandProxy").add("Network", module.exports);
|
||||
require("cordova/firefoxos/commandProxy").add("NetworkStatus", module.exports);
|
@ -52,8 +52,14 @@
|
||||
return @"none";
|
||||
|
||||
case ReachableViaWWAN:
|
||||
return @"cellular";
|
||||
|
||||
{
|
||||
BOOL isConnectionRequired = [reachability connectionRequired];
|
||||
if (isConnectionRequired) {
|
||||
return @"none";
|
||||
} else {
|
||||
return @"cellular";
|
||||
}
|
||||
}
|
||||
case ReachableViaWiFi:
|
||||
return @"wifi";
|
||||
|
||||
|
@ -205,7 +205,7 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe
|
||||
return NotReachable;
|
||||
}
|
||||
|
||||
BOOL retVal = NotReachable;
|
||||
NetworkStatus retVal = NotReachable;
|
||||
|
||||
if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) {
|
||||
// if target host is reachable and no connection is required
|
||||
|
@ -1,3 +1,24 @@
|
||||
/*
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
var cordova = require('cordova');
|
||||
var Connection = require('./Connection');
|
||||
|
||||
|
@ -84,4 +84,4 @@ module.exports = {
|
||||
|
||||
};
|
||||
|
||||
require("cordova/windows8/commandProxy").add("NetworkStatus",module.exports);
|
||||
require("cordova/exec/proxy").add("NetworkStatus",module.exports);
|
||||
|
Loading…
Reference in New Issue
Block a user