问题
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