npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-connectivity-monitor

v1.2.2

Published

Connectivity status monitoring. Detects if there is WIFI/3G/EDGE/CDMA available.

Downloads

52

Readme

Cordova Connectivity Monitor

Connectivity status monitoring for Cordova apps. Detects if there is WIFI/3G/EDGE/CDMA available.


Platform SDK supported

  • iOS
  • Android

How to use

To install this plugin, follow the Command-line Interface Guide. You can use one of the following command lines:

  • cordova plugin add cordova-connectivity-monitor
  • cordova plugin add https://github.com/appfeel/connectivity-monitor-cordova.git

To start monitoring connectivity, place the following code in your onDeviceReady callback. In order to attach an event listener, use document.addEventListener("deviceready", onDeviceReady, false).

    
    function onDeviceReady() {
      var myHostToObserve = "www.appfeel.com";
      
      document.removeEventListener('deviceready', onDeviceReady, false);
      
      document.addEventListener(connectivity.events.onReachabilityChanged, onReachabilityChanged, false)
      connectivity.observeRemoteHostName(myHostToObserve);
    }
    
    function onReachabilityChanged(e) {
      console.log(e.interface);
      swich(e.interface) {
        case connectivity.DISCONNECTED:
          console.log('DISCONNECTED');
          break;
        case WIFI:
          console.log('WIFI');
          break;
        case WIMAX:
          console.log('WIMAX');
          break;
        case ETHERNET:
          console.log('ETHERNET');
          break;
        case MOBILE:
          console.log('MOBILE');
          break;
        case UNDEFINED:
          console.log('UNDEFINED');
          break;
      }
      
      if (e.connected) {
        console.log("Is connected");
      } else {
        console.log("Is not connected");
      }
      
      swich(e.observer) {
        case HOST:
          console.log('HOST');
          break;
        case INTERNET:
          console.log('INTERNET');
          break;
        case LOCALWIFI:
          console.log('LOCALWIFI');
          break;
      }
    }

Javascript API

Note: All success callbacks are in the form 'function () {}', and all failure callbacks are in the form 'function (err) {}' where err is a String explaining the error reason.

connectivity.observeRemoteHostName(hostName, stopAllObservers, successCallback, failureCallback);

Observes changes of connectivity to a given hostname.

* {!Object}    hostName         (Optional) Name of the host to observe. Default www.google.com
* {Boolean}    stopAllObservers (Optional) Stop any existing observer. Default false
* {function()} successCallback  (Optional) Callback on success
* {function()} failureCallback  (Optional) Callback on fail

connectivity.observeRemoteIPV4(ipv4, stopAllObservers, successCallback, failureCallback);

Observes changes of connectivity to a given ip v4.

  • {!Object} ipv4 (Required) IP v4 to observe. Ex: 192.168.1.0
  • {Boolean} stopAllObservers (Optional) Stop any existing observer. Default false
  • {function()} successCallback (Optional) Callback on success
  • {function()} failureCallback (Optional) Callback on fail

connectivity.observeRemoteIPV6(ipv6, stopAllObservers, successCallback, failureCallback);

Observes changes of connectivity to a given ip v6.

  • {!Object} ipv6 (Required) IP v6 to observe. Ex: ::ffff:192.168.1.0
  • {Boolean} stopAllObservers (Optional) Stop any existing observer. Default false
  • {function()} successCallback (Optional) Callback on success
  • {function()} failureCallback (Optional) Callback on fail

connectivity.observeLocalWifi(stopAllObservers, successCallback, failureCallback);

Observes changes of connectivity to local wifi. (Android: Not yet implemented)

  • {Boolean} stopAllObservers (Optional) Stop any existing observer. Default false
  • {function()} successCallback (Optional) Callback on success
  • {function()} failureCallback (Optional) Callback on fail

connectivity.observeInternetConnection(stopAllObservers, successCallback, failureCallback);

Observes changes of connectivity to internet connection.

  • {Boolean} stopAllObservers (Optional) Stop any existing observer. Default false
  • {function()} successCallback (Optional) Callback on success
  • {function()} failureCallback (Optional) Callback on fail

connectivity.stopAllObservers(successCallback, failureCallback);

Stop any existing observer.

  • {function()} successCallback (Optional) Callback on success
  • {function()} failureCallback (Optional) Callback on fail

Events

document.addEventListener(connectivity.EVENTS.onReachabilityChanged, onReachabilityChanged, false)

Raised when there is a change in connectivity. It calls a function onReachabilityChanged(e) {}

  • {Object} e An object containing the following fields:
  • e.interface: The ingerface type that has changed connectivity status.
  • e.connected: True/False.
  • e.observer: The observer that raised the event.

Constants

connectivity.OBSERVER

Specifies the observer affected by the connectivity change:

  • HOST: specifies that the connectivity change affected host reachability.
  • INTERNET: specifies that the connectivity change affected internet reachability.
  • LOCALWIFI: specifies that the connectivity change affected local wifi reachability.

connectivity.INTERFACE

Specifies on which interface happened the connectivity change:

  • DISCONNECTED: no interface connected.
  • WIFI: connectivity change occured on wifi interface.
  • WIMAX: connectivity change occured on wifi interface.
  • ETHERNET: connectivity change occured on ethernet interface.
  • MOBILE: connectivity change occured on mobile (3G/GPRS/...) interface.
  • UNDEFINED: connectivity change occured on an undefined interface.

Contributing

You can use this cordova plugin for free. You can contribute to this project in many ways:

  • Testimonials of apps that are using this plugin would be especially helpful (and gives your app free marketing). Open an issue.
  • Reporting issues.
  • Patching and bug fixing, especially when submitted with test code. Open a pull request.
  • Other enhancements.

License

The MIT License

Copyright (c) 2014 AppFeel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits