Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@viral-network/react-native-wifi-direct
Advanced tools
Readme
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_FINE_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 @viral-network/react-native-wifi-direct receives a total of 4 weekly downloads. As such, @viral-network/react-native-wifi-direct popularity was classified as not popular.
We found that @viral-network/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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.