【问题标题】:Is where a way to listen to wireless network changes in node js?哪里有办法监听node js中的无线网络变化?
【发布时间】:2017-05-02 02:13:00
【问题描述】:

我正在构建一个应用程序,我需要在其中检测连接的无线网络中的任何更改,即当用户从一个网络转移到另一个网络并记录更改时。

我正在为 nodejs 使用电子 js 和无线工具。

那么有没有办法做到这一点,或者我必须使用 setInterval() 每隔几秒检查一次。

感谢任何建议/解决方案。谢谢。

【问题讨论】:

标签: javascript node.js wifi electron wireless


【解决方案1】:

在线(在 index.html 或其他 html 文件中)检测互联网连接是否存在,如下所示:

在 index.html 中你可以这样做:

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

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

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

在你的文件 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");}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多