Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/t1st3/cordova-plugin-ping
:dart: Apache Cordova plugin that pings domains or IPs.
https://github.com/t1st3/cordova-plugin-ping
android cordova cordova-plugin javascript ping
Last synced: about 2 months ago
JSON representation
:dart: Apache Cordova plugin that pings domains or IPs.
- Host: GitHub
- URL: https://github.com/t1st3/cordova-plugin-ping
- Owner: t1st3
- License: mit
- Created: 2016-02-02T13:46:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-12-12T12:09:04.000Z (about 5 years ago)
- Last Synced: 2024-11-02T03:23:35.408Z (about 2 months ago)
- Topics: android, cordova, cordova-plugin, javascript, ping
- Language: Objective-C
- Homepage:
- Size: 43.9 KB
- Stars: 15
- Watchers: 3
- Forks: 21
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# cordova-plugin-ping
[![NPM version](https://img.shields.io/npm/v/cordova-plugin-ping.svg)](https://www.npmjs.org/package/cordova-plugin-ping)
This plugin implements the [`ping` software utility](https://en.wikipedia.org/wiki/Ping_%28networking_utility%29).
## Supported Platforms
- Android
- iOS## Installation
> cordova plugin add cordova-plugin-ping
or
> cordova plugin add https://github.com/t1st3/cordova-plugin-ping.git
## Usage
This plugin defines a global `Ping` object.
Although the object is in the global scope, it is not available until after the `deviceready` event.### Ping a domain
> - query : Domain or IP address to ping.
> - timeout : Time to wait for a response, in seconds.
> - retry : Number of echo requests to send.
> - version : Ping IPv4 or IPv6 address (Ping or Ping6).```js
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
var p, success, err, ipList;
ipList = [{query: 'www.tiste.org', timeout: 1,retry: 3,version:'v4'},
{query: 'www.somesite.com', timeout: 2,'retry': 3,version:'v6'}];
success = function (results) {
console.log(results);
};
err = function (e) {
console.log('Error: ' + e);
};
p = new Ping();
p.ping(ipList, success, err);
}
```## API
### Ping.ping
This method takes the following arguments:
* ipList: an array of json objects with parameters : domain to query, retry, timeout and version.
* success: a callback function that handles success
* err: a callback function that handles errorThe callback function for success takes one argument, which is a JSON array of results:
```json
[{
"response": {
"status": "success",
"result": {
"target": "www.tiste.org",
"avgRtt": "4.476",
"maxRtt": "6.348",
"minRtt": "1.007",
"pctTransmitted": "3",
"pctReceived": "3",
"pctLoss": "0%"
}
},
"request": {
"query": "www.tiste.org",
"timeout": "1",
"retry": "3",
"version": "v4"
}
}, {
"response": {
"status": "success",
"result": {
"target": "www.somesite.com",
"avgRtt": "4.811",
"maxRtt": "7.294",
"minRtt": "0.915",
"pctTransmitted": "3",
"pctReceived": "3",
"pctLoss": "0%"
}
},
"request": {
"query": "www.somesite.com",
"timeout": "2",
"retry": "3",
"version": "v6"
}
}]
```The callback function for error takes one argument, which is the error emitted.
## License
This project is licensed under the [MIT license](https://opensource.org/licenses/MIT). Check the [license file](https://github.com/t1st3/cordova-plugin-ping/blob/master/license).