{"library":"react-native-zeroconf","title":"React Native Zeroconf Discovery","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install react-native-zeroconf"],"cli":null},"imports":["import Zeroconf from 'react-native-zeroconf'","zeroconf.on('resolved', service => { /* ... */ })"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Zeroconf from 'react-native-zeroconf'\nimport { useEffect } from 'react';\n\nconst ZeroconfScanner = () => {\n  useEffect(() => {\n    const zeroconf = new Zeroconf()\n\n    zeroconf.on('resolved', service => {\n      console.log('Found service:', service.name)\n      console.log('IP addresses:', service.addresses)\n      console.log('Port:', service.port)\n      console.log('Service details:', service)\n    })\n\n    zeroconf.on('start', () => console.log('Scan started'))\n    zeroconf.on('stop', () => console.log('Scan stopped'))\n    zeroconf.on('error', error => console.error('Zeroconf error:', error))\n\n    // Start scanning for HTTP services. Consider 'DNSSD' for better Android compatibility.\n    // zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')\n    zeroconf.scan('http', 'tcp', 'local.')\n\n    // Stop scanning after 10 seconds and clean up listeners\n    const timer = setTimeout(() => {\n      zeroconf.stop()\n      console.log('All services after 10s:', zeroconf.getServices())\n      // It's crucial to remove listeners on unmount to prevent memory leaks\n      zeroconf.removeDeviceListeners(); // Specific method for cleanup (not in provided README, but good practice)\n    }, 10000)\n\n    return () => {\n      clearTimeout(timer)\n      zeroconf.stop()\n      zeroconf.removeDeviceListeners(); // Ensure cleanup on component unmount\n    }\n  }, [])\n\n  return null // This component doesn't render anything visible\n}\n\nexport default ZeroconfScanner;\n","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}