Detect wifi on/off

Hello all,
i’m creating an chat app in ionic 2.i want to detect wifi on/off and based upon that i have to call a method.please help me.

i have implented using cordova-network-information.but it works when page refreshes.
apart from this if there any solution please help me.

I am not sure how to detect if the connection is wifi or not but you can detect connection like this:

import { Network } from '@ionic-native/network';
declare var Connection;
constructor(public network: Network){
this.onDevice ='cordova'); => {
    }); => {
isOnline(): boolean {
    if (this.onDevice && {
      return !== Connection.NONE;
    } else {
      return navigator.onLine;

If you want to work with the hardware read this document.

It’s ok but it works when you constructor is scenario is different.
i want to call method when user does wifi/internet on/off.
the best u can understand in whatsapp send message to a friend (off your wifi) friend will not receive you message.after sending just on you wifi the message will be send now.

but I just gave you solution for that, look at my methods, and onConnect()

Thanks a lot it’s works.
Here is code:
Network.onConnect().subscribe(() => {


BUT it calls two times console.log(); why?

Network.onConnect() is use to detect if you have internet connection or not, it not detect wifi on/off