Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
react-native-zeroconf
Advanced tools
Basic Zeroconf implementation for React-native
Get running services advertizing themselves using Zeroconf implementations like Avahi, Bonjour or NSD.
yarn add react-native-zeroconf
# for react-native < 0.60 only (all platforms):
react-native link
# for ios (when using CocoaPods):
(cd ios && pod install)
# for macOS (when using CocoaPods):
(cd macos && pod install)
You can look at the wiki if you prefer a manual install.
TXT records will be available on iOS and Android >= 7.
For Android please ensure your manifest is requesting all necessary permissions.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
IOS 14 requires you to specify the services you want to scan for and a description for what you're using them.
In your info.plist
add the following strings:
<key>NSBonjourServices</key>
<array>
<string>my_service._tcp.</string>
<string>my_other_service._tcp.</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Describe why you want to use local network discovery here</string>
Take a look at the example folder. Install the dependencies, run node server.js
and launch the project.
import Zeroconf from 'react-native-zeroconf'
const zeroconf = new Zeroconf()
scan(type = 'http', protocol = 'tcp', domain = 'local.')
Start the zeroconf scanThis will initialize the scan from the Zeroconf
instance. Will stop another scan if any is running.
stop()
Stop the scanIf any scan is running, stop it. Otherwise do nothing.
getServices()
Returns resolved servicesWill return all names of services that have been resolved.
removeDeviceListeners()
Remove listenersAllow you to clean the listeners, avoiding potential memory leaks (#33).
addDeviceListeners()
Add listenersIf you cleaned the listeners and need to get them back on.
publishService(type, protocol, domain, name, port, txt)
Publish a serviceThis adds a service for the current device to the discoverable services on the network.
domain
should be the domain the service is sitting on, dot suffixed, for example 'local.'
type
should be both type and protocol, underscore prefixed, for example '_http._tcp'
name
should be unique to the device, often the device name
port
should be an integer
txt
should be a hash, for example {"foo": "bar"}
unpublishService(name)
Unpublish a serviceThis removes a service from those discoverable on the network.
name
should be the name used when publishing the service
zeroconf.on('start', () => console.log('The scan has started.'))
start
Triggered on scan startstop
Triggered on scan stopfound
Triggered when a service is foundBroadcast a service name as soon as it is found.
resolved
Triggered when a service is resolvedBroadcast a service object once it is fully resolved
{
"host": "XeroxPrinter.local.",
"addresses": [
"192.168.1.23",
"fe80::aebc:123:ffff:abcd"
],
"name": "Xerox Printer",
"fullName": "XeroxPrinter.local._http._tcp.",
"port": 8080
}
remove
Triggered when a service is removedBroadcast a service name removed from the network.
update
Triggered either when a service is found or removederror
Triggered when an error occursFAQs
A Zeroconf discovery utility for react-native
The npm package react-native-zeroconf receives a total of 12,803 weekly downloads. As such, react-native-zeroconf popularity was classified as popular.
We found that react-native-zeroconf 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.