friedrith / node-wifi

📶 NodeJS tool to manage wifi (connections, scans)
MIT License
397 stars 161 forks source link

getCurrentConnections does not work on mac #28

Closed felixgalindo closed 6 years ago

peterbe commented 6 years ago

I too get nothing:

wifi.init({
    iface : null // network interface, choose a random wifi interface if set to null
});

wifi.getCurrentConnections(function(err, currentConnections) {
  if (err) {
    console.error(err);
    throw err
    // console.log(err)
  }
  console.log('CURRENT CONNETIONS');
  console.log(currentConnections)
})

Using the latest version.

xdadda commented 6 years ago

Same problem here. Can it be fixed? update: looking at the source code I see that I had to run it as a Promise

wifi.getCurrentConnections().then(wifi => this.net.ssid = wifi[0].ssid).catch(err => console.log(err))

Shouldn't the instructions be updated?

peterbe commented 6 years ago

To anybody else ending up here and being too eager to wait for a fix, here's what I did: https://github.com/peterbe/howsmywifi/blob/2c479bcbd344fce0b9a77b9fe972a38e24b78262/index.js#L30-L68

I only have a mac so I wouldn't even be able to test node-wifi on non-macs. The spawn() solution works for mac. I was going to use that as a fallback.

xdadda commented 6 years ago

As mentioned no need for a fix, just call the Promise as explained above. And it will work on all platforms.

peterbe commented 6 years ago

Sweet! Thanks. Removed my hack

friedrith commented 6 years ago

Sorry for the late. I have pushed a new version that corrects the bug of callback on macOS.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.