Registry / http-networking / react-native-zeroconf

react-native-zeroconf

JSON →
library0.14.0jsnpmunverified

react-native-zeroconf is a comprehensive utility library that enables React Native applications to discover and publish network services using Zeroconf protocols like Bonjour and mDNS. The current stable version is 0.14.0, which was released approximately 3 months ago. It appears to follow an active, though not strictly scheduled, release cadence, with updates addressing platform compatibility, including Android 15+ requirements. It offers cross-platform support for both iOS and Android, providing developers with robust service discovery and publishing capabilities. A key differentiator is its dual Android implementation, allowing selection between the native NSD (Network Service Discovery) API or an embedded DNSSD (mDNSResponder) for potentially broader compatibility. Its active development ensures ongoing support for evolving mobile OS requirements, such as the upcoming Android 15+ page size alignment.

npm install react-native-zeroconf
INSTALL
IMPORT
SIG · REACT-NATIVE-ZEROC
R
react-native-zeroconf
http-networkingjavascriptv0.14.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Zeroconf
import Zeroconf from 'react-native-zeroconf'
const Zeroconf = require('react-native-zeroconf')
While CommonJS `require` might work in some React Native environments, modern React Native (especially with Hermes) and TypeScript projects primarily use ES module `import` syntax. The library exports a default class.
Zeroconf events
zeroconf.on('resolved', service => { /* ... */ })
zeroconf.addListener('resolved', service => { /* ... */ })
The library extends EventEmitter and uses `on` for event subscription, not `addListener` which is also a valid EventEmitter method but `on` is more commonly documented for this library's usage.

Demonstrates how to initialize Zeroconf, listen for resolved services, and start/stop scanning for HTTP services. Includes essential cleanup for React components and error handling.

import Zeroconf from 'react-native-zeroconf' import { useEffect } from 'react'; const ZeroconfScanner = () => { useEffect(() => { const zeroconf = new Zeroconf() zeroconf.on('resolved', service => { console.log('Found service:', service.name) console.log('IP addresses:', service.addresses) console.log('Port:', service.port) console.log('Service details:', service) }) zeroconf.on('start', () => console.log('Scan started')) zeroconf.on('stop', () => console.log('Scan stopped')) zeroconf.on('error', error => console.error('Zeroconf error:', error)) // Start scanning for HTTP services. Consider 'DNSSD' for better Android compatibility. // zeroconf.scan('http', 'tcp', 'local.', 'DNSSD') zeroconf.scan('http', 'tcp', 'local.') // Stop scanning after 10 seconds and clean up listeners const timer = setTimeout(() => { zeroconf.stop() console.log('All services after 10s:', zeroconf.getServices()) // It's crucial to remove listeners on unmount to prevent memory leaks zeroconf.removeDeviceListeners(); // Specific method for cleanup (not in provided README, but good practice) }, 10000) return () => { clearTimeout(timer) zeroconf.stop() zeroconf.removeDeviceListeners(); // Ensure cleanup on component unmount } }, []) return null // This component doesn't render anything visible } export default ZeroconfScanner;
Debug
Known issues
breakingFor React Native versions 0.60 and above, manual linking via `react-native link` is deprecated and can cause build failures due to autolinking. Ensure you remove any manual `link` commands if upgrading an older project or setting up a new one.
fix
Remove `react-native link` from your installation steps. Autolinking should handle the native module setup automatically. If issues persist, try reinstalling `node_modules` and `pod install` in the `ios` directory.
affects: >=0.60
gotchaOn iOS 14 and newer, applications must explicitly declare the service types they intend to discover in `Info.plist` using `NSBonjourServices` and provide a `NSLocalNetworkUsageDescription` key. Failure to do so will prevent network discovery and result in an empty list of services. Additionally, for network-intensive operations, you might need to request the Multicast Networking Entitlement through Apple.
fix
Add `NSBonjourServices` array (e.g., `<string>_http._tcp.</string>`) and `NSLocalNetworkUsageDescription` string to your `Info.plist`. For more advanced use cases or consistent discovery, apply for the Multicast Networking Entitlement with Apple.
affects: >=0.1.0
gotchaEssential network permissions (`INTERNET`, `ACCESS_NETWORK_STATE`, `ACCESS_WIFI_STATE`, `CHANGE_WIFI_MULTICAST_STATE`) must be explicitly declared in your `AndroidManifest.xml`. Without these, Zeroconf discovery will fail silently or with permission denied errors on Android.
fix
Ensure the required `<uses-permission>` tags are present within the `<manifest>` tag of your `AndroidManifest.xml`.
affects: >=0.1.0
gotchaStarting November 1, 2025, Google Play requires all apps to be compatible with devices using 16KB page sizes (Android 15+). While `react-native-zeroconf@0.14.0` includes the necessary alignment fix, users on older versions may experience crashes or instability on Android 15+ devices when this requirement becomes active.
fix
Upgrade to `react-native-zeroconf@0.14.0` or newer to ensure compatibility with Android 15+ and Google Play requirements.
affects: <0.14.0
gotchaOn Android, the library offers two implementations for service discovery: the native `NSD` (default) and an embedded `DNSSD`. `DNSSD` is often recommended for better cross-device compatibility, especially if `NSD` proves unreliable or inconsistent on specific Android versions or OEM devices, a common issue with Android's NSD.
fix
If encountering unreliable discovery on Android, explicitly specify `'DNSSD'` as the `implType` parameter when calling `scan()`: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.
affects: >=0.1.0
gotchaZeroconf discovery relies on multicast networking which is often unsupported by Android emulators by default. For reliable testing, a physical Android device on the same network as the services is recommended.
fix
Test on a physical Android device or configure your Android emulator for multicast support, which usually involves advanced networking setup (e.g., using TAP networking with QEMU).
affects: >=0.1.0
gotchaLeaving scans active indefinitely can lead to memory leaks or unexpected crashes, especially when the app is backgrounded or the device sleeps, particularly on iOS and older Android versions.
fix
Always stop the Zeroconf scan and remove listeners when the component unmounts or the app goes into the background. Use React Native's `AppState` API to manage scans based on app foreground/background state. Example: `zeroconf.stop(); zeroconf.removeDeviceListeners();`
affects: >=0.1.0
Errors
Common errors & fixes
Native module 'RNZeroconf' was not found.
The native module is not correctly linked or multiple linking attempts have occurred, typically due to `react-native link` being used with autolinking on newer React Native versions.
fix
For React Native 0.60+, ensure autolinking is working by deleting `node_modules` and `Podfile.lock` (iOS), then `npm install` or `yarn install`, followed by `cd ios && pod install` (for iOS/macOS). Avoid using `react-native link`.
TypeError: Cannot read property 'scan' of null
The `Zeroconf` instance or its underlying native module is not correctly initialized or the import failed, leading to an `undefined` or `null` reference. This can also happen in Expo managed workflows if not using `expo prebuild`.
fix
Ensure `import Zeroconf from 'react-native-zeroconf'` is at the top of your file and `const zeroconf = new Zeroconf()` is called before attempting to use its methods. If using Expo, run `npx expo prebuild` to generate native projects or confirm native modules are properly configured.
Error: { NSNetServicesErrorCode = "-72007"; NSNetServicesErrorDomain = 10; }
This error typically indicates an issue with `NSNetService` not being able to resolve or publish services on iOS, often related to missing `Info.plist` entries or network entitlements, especially on iOS 17+.
fix
Verify that `NSBonjourServices` and `NSLocalNetworkUsageDescription` are correctly configured in your `Info.plist`. If the problem persists on iOS 17+, you may need to request the Multicast Networking Entitlement from Apple.
No services found / Scan returns empty array / 'resolved' event never fires.
This is a common issue with several potential causes, including incorrect permissions, services not being on the same network, firewall blocking multicast, or unreliable Android NSD implementation.
fix
Double-check Android `AndroidManifest.xml` permissions and iOS `Info.plist` entries (`NSBonjourServices`, `NSLocalNetworkUsageDescription`). Ensure devices are on the same Wi-Fi network. On Android, try explicitly using the `DNSSD` implementation for scanning: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.
Uncaught, unspecified "error" event. (-72000)
This generic JavaScript error in React Native often indicates an unhandled exception propagating from native code, frequently observed when Zeroconf scans are active and the app is backgrounded or the device sleeps, leading to network state changes.
fix
Implement robust lifecycle management: stop Zeroconf scans (`zeroconf.stop()`) and remove listeners (`zeroconf.removeDeviceListeners()`) when the app moves to the background (using React Native's `AppState` API) or when the component unmounts. Re-initialize and restart scans when the app comes to the foreground.
Upgrade
Version history
0.14.0latest on npm
Audit
Dependencies
react-nativerequiredPeer dependency for a React Native module, providing the native bridge.
Agent activity
6 hits · last 30 days
node
6
Resources