Is where a way to listen to wireless network changes in node js?

老子叫甜甜 提交于 2019-12-25 18:34:47

问题


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:


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");}


来源:https://stackoverflow.com/questions/43729032/is-where-a-way-to-listen-to-wireless-network-changes-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!