Open AltekJimmyChang opened 4 years ago
Can not connect to Wi-Fi AP with the connect API
With init({iface:null}), and then call connect function. it should find the interface automatical and connect to Wi-Fi AP
It alwayse use the en0 to as Wi-Fi interface. But it may en1 in some model
Use the networksetup -listallhardwareports can find the proper interface. Below is my code.
function osx_initWiFi(callback) { let args = ['-listallhardwareports']; execFile('networksetup', args, { env }, function(err, resp) { let respList = resp.split('\n'); let wifiIndex=respList.findIndex( item=> item==="Hardware Port: Wi-Fi"); if (wifiIndex!==-1) { let wifiStr = respList[wifiIndex+1].split(':'); let out = wifiStr[1].trim(); console.log(got wifi port :${out} , ${out.length}); callback && callback(out); }else { callback && callback(null); } }); }
got wifi port :${out} , ${out.length}
osx_initWiFi(ret=>init({iface:ret}))
Can not connect to Wi-Fi AP with the connect API
Expected Behavior
With init({iface:null}), and then call connect function. it should find the interface automatical and connect to Wi-Fi AP
Current Behavior
It alwayse use the en0 to as Wi-Fi interface. But it may en1 in some model
Affected features
Possible Solution
Use the networksetup -listallhardwareports can find the proper interface. Below is my code.
function osx_initWiFi(callback) { let args = ['-listallhardwareports']; execFile('networksetup', args, { env }, function(err, resp) { let respList = resp.split('\n'); let wifiIndex=respList.findIndex( item=> item==="Hardware Port: Wi-Fi"); if (wifiIndex!==-1) { let wifiStr = respList[wifiIndex+1].split(':'); let out = wifiStr[1].trim(); console.log(
got wifi port :${out} , ${out.length}
); callback && callback(out); }else { callback && callback(null); } }); }osx_initWiFi(ret=>init({iface:ret}))
Steps to Reproduce (for bugs)
Context
Your Environment