Is where a way to listen to wireless network chang

2019-09-19 12:07发布

I am building an application in which I need to detect the any changes in connected wireless network ie when a user transfers from one network to another and log the change.

I am using electron js and wireless-tools for nodejs.

So is there a way to do this or I have to use setInterval() to check every few seconds.

Any suggestions/solutions are appreciated.Thanks.

1条回答
We Are One
2楼-- · 2019-09-19 12:26

online (in index.html or in other html file) to detect if an internet connection exist like this :

In index.html you can do this :

const {ipcRenderer} = require('electron');

const updateOnlineStatus = () => {
  ipcRenderer.send('online-status-changed', navigator.onLine ? true : false)
}

window.addEventListener('online', updateOnlineStatus)
window.addEventListener('offline', updateOnlineStatus)

and in your file main.js :

    var ipcMain = require('electron').ipcMain;
    ipcMain.on('online-status-changed', (event, status) => {

    if(status)
       alert("you are online");
    else 
       alert("you are offline");}
查看更多
登录 后发表回答