
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
react-native-wifi-direct
Advanced tools
A react native module for connecting and disconnecting from Android Wi-Fi Direct networks (p2p).
This currently only supports Android
A react native module for connecting and disconnecting from Android Wi-Fi Direct networks (p2p). This was built to be used with IOT devices that broadcast a Wi-Fi Direct network.
Install library from npm
npm install react-native-wifi-direct
Then link the library:
react-native link react-native-wifi-direct
import WifiDirect from 'react-native-wifi-direct'
Permissions: Starting with Android API 25, apps must be granted the ACCESS_COARSE_LOCATION (or ACCESS_FINE_LOCATION) permission in order to obtain results.
import { PermissionsAndroid } from 'react-native'
...
const permission = PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION
const options = {
'title': 'Wifi networks',
'message': 'We need your permission in order to find wifi networks'
}
PermissionsAndroid.request(permission, options).then((granted) => {
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Permission granted!");
} else {
console.log("You will not able to retrieve wifi available networks list")
}
}).catch((error) => {
console.warn(error)
})
Initialize react-native-wifi-direct
. This should be done in your index.js
(index.android.js
) or root level app.js
file.
WifiDirect.initialize()
Start scanning for Wi-Fi Direct networks in the area. The scan will continue until a connection is initiated. The scan does not return any results. It only returns whether it successfully started.
WifiDirect.discoverPeers().then((success) => {
if (success) {
console.log("Peer discovery has initiated successfully.")
} else {
console.log("Peer discover failed to initiate. Is your Wi-Fi on?")
}
})
If you need to stop peer discovery to do non Wi-Fi Direct scan, you can call stopPeerDiscovery
. Note that discoverPeers
will stop on it's own if you connect to a Wi-Fi Direct network.
WifiDirect.stopPeerDiscovery().then((success) => {
if (success) {
console.log("Peer discovery will stop.")
} else {
console.log("Peer discovery can not be stopped.")
}
})
Register an event to listen for when devices are found. This event will be called every time your device updates its network list.
componentWillMount () {
WifiDirect.addListener('PEERS_UPDATED', this.peersUpdated)
}
// Don't forget to remove the listener to prevent a memory leak
componentWillUnmount () {
WifiDirect.removeListener('PEERS_UPDATED', this.peersUpdated)
}
peersUpdated = (event) => {
console.log("Devices found!", event.devices)
}
Connect to a Wi-Fi Direct network. The devices found from event.devices
in the PEERS_UPDATED
listener, will have a MAC address that is used to connect.
WifiDirect.connect(device.address).then((success) => {
if (success) {
console.log("Connection has initiated.")
} else {
console.log("Connection failed to initiated. Check your Wi-Fi.")
}
})
The CONNECTION_INFO_UPDATED
event is triggered when a connection is successfully established.
componentWillMount () {
WifiDirect.addListener('CONNECTION_INFO_UPDATED', this.connectionInfoUpdated)
}
// Don't forget to remove the listener to prevent a memory leak
componentWillUnmount () {
WifiDirect.removeListener('CONNECTION_INFO_UPDATED', this.connectionInfoUpdated)
}
connectionInfoUpdated = (event) => {
console.log("Connection established!", event.connectionInfo)
}
WifiDirect.disconnect().then((success) => {
if (success) {
console.log("Disconnecting initiated.")
} else {
console.log("Disconnect initiation failed. Are you already disconnected?")
}
})
FAQs
A react native module for connecting and disconnecting from Android Wi-Fi Direct networks (p2p).
The npm package react-native-wifi-direct receives a total of 339 weekly downloads. As such, react-native-wifi-direct popularity was classified as not popular.
We found that react-native-wifi-direct demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.