1.0.2 • Published 2 years ago

cordova-plugin-ping-with-ip v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Installation

cordova plugin add https://github.com/adnofer/cordova-plugin-ping-with-ip.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

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
  var p, success, err, ipList;
  ipList = ['tiste.org'];
  success = function (results) {
    console.log(results);
  };
  err = function (e) {
    console.log('Error: ' + e);
  };
  p = new Ping();
  p.ping(ipList, success, err);
}

Ping an IPv4 address

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
  var p, success, err, ipList;
  ipList = ['192.168.1.254'];
  success = function (results) {
    console.log(results);
  };
  err = function (e) {
    console.log('Error: ' + e);
  };
  p = new Ping();
  p.ping(ipList, success, err);
}

Ping multiple domains or IP addresses

document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
  var p, success, err, ipList;
  ipList = ['tiste.org', 'undefineddomain.com', '192.168.1.254'];
  success = function (results) {
    console.log(results);
  };
  err = function (e) {
    console.log('Error: ' + e);
  };
  p = new Ping();
  p.ping(ipList, success, err);
}

Methods

  • Ping.ping

Ping.ping

This method takes the following arguments:

  • ipList: an array of domain names or IP addresses
  • success: a callback function that handles success
  • err: a callback function that handles error

The callback function for success takes one argument, which is a JSON array of results:

[
  {
    "target": "github.com",
	"ip": "140.82.121.4",
    "status": "success",
    "avg": 40.131
  },
  {
    "target": "undefineddomain.com",
	"ip": "140.82.121.4",
    "status": "timeout",
    "avg": 0
  },
  {
    "target": "192.168.1.1",
	"ip": "192.168.1.1",
    "status": "success",
    "avg": 35.654
  }
]

The callback function for error takes one argument, which is the error emitted.

Supported Platforms

  • Android

License

This project is licensed under the MIT license. Check the LICENSE.md file.