{"id":4587,"url":"https://github.com/yonahforst/react-native-discovery","last_synced_at":"2025-08-04T01:32:37.806Z","repository":{"id":39098361,"uuid":"48249098","full_name":"yonahforst/react-native-discovery","owner":"yonahforst","description":"Discover nearby devices using BLE.","archived":false,"fork":false,"pushed_at":"2017-09-28T07:50:03.000Z","size":13513,"stargazers_count":115,"open_issues_count":6,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-07-31T13:13:53.398Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yonahforst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-18T18:02:25.000Z","updated_at":"2025-06-23T02:42:56.000Z","dependencies_parsed_at":"2022-08-09T22:40:14.957Z","dependency_job_id":null,"html_url":"https://github.com/yonahforst/react-native-discovery","commit_stats":null,"previous_names":["joshblour/discovery-react","joshblour/react-native-discovery"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yonahforst/react-native-discovery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonahforst%2Freact-native-discovery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonahforst%2Freact-native-discovery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonahforst%2Freact-native-discovery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonahforst%2Freact-native-discovery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yonahforst","download_url":"https://codeload.github.com/yonahforst/react-native-discovery/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonahforst%2Freact-native-discovery/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268636416,"owners_count":24282087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:17:17.176Z","updated_at":"2025-08-04T01:32:37.537Z","avatar_url":"https://github.com/yonahforst.png","language":"Objective-C","readme":"# Discovery\nDiscover nearby devices using BLE.\n\nReact native implementation of https://github.com/omergul123/Discovery\n\n(Android uses https://github.com/joshblour/discovery-android)\n\n#### Changes from version 0.0.x\nNow supports discovery with multiple UUIDs. You need to intialize each one separately and specify the UUID when you perform actions.\ni.e. `Discovery.setShouldAdvertise(true);` now becomes `Discovery.setShouldAdvertise(\"3E1180E5-222E-43E9-98B4-E6C0DD18E728\", true);`\n\n## What\nDiscovery is a very simple but useful library for discovering nearby devices with BLE(Bluetooth Low Energy) and for exchanging a value (kind of ID or username determined by you on the running app on peer device) regardless of whether the app on peer device works at foreground or background state.\n\n#### Example\n```js\nconst {DeviceEventEmitter} = require('react-native');\nconst Discovery = require('react-native-discovery');\nconst myUUID = \"3E1180E5-222E-43E9-98B4-E6C0DD18E728\";\n\nDiscovery.initialize(\n  myUUID,\n  \"SpacemanSpiff\"\n);\nDiscovery.setShouldAdvertise(myUUID, true);\nDiscovery.setShouldDiscover(myUUID, true);\n\n// Listen for discovery changes\nDeviceEventEmitter.addListener(\n  'discoveredUsers',\n  (data) =\u003e {\n    if (data.uuid == myUUID) {\n      if (data.didChange || data.usersChanged) { //slight callback discrepancy between the iOS and Android libraries\n        console.log(data.users)\n      }\n    }\n  }\n);\n\n// Listen for bluetooth state changes\nDeviceEventEmitter.addListener(\n  'bleStateChanged',\n  (event) =\u003e {\n    console.log('BLE is On: ' + event.isOn)\n  }\n);\n\n\n```\n\n\n#### API\n\n`initialize(uuid, username)` - string, string. Initialize the Discovery object with a UUID specific to your app, and a username specific to your device. Returns a promise which resolves to the specified UUID\n\n`setPaused(uuid, isPaused)` - string, bool. pauses advertising and detection for the specified uuid. Returns a promise which resolves to true.\n\n`setShouldDiscover(uuid, shouldDiscover)` - string, bool. starts and stops discovery for the specified uuid. Returns a promise which resolves to true.\n\n`setShouldAdvertise(uuid, shouldAdvertise)` - string, bool. starts and stops advertising for the specified uuid. Returns a promise which resolves to true.\n\n`setUserTimeoutInterval(uuid, userTimeoutInterval)` - string, integer in seconds (default is 5). After not seeing a user for x seconds, we remove him from the users list in our callback (for the specified uuid). Returns a promise which resolves to true.\n  \n  \n*The following two methods are specific to the Android version, since the Android docs advise against continuous scanning. Instead, we cycle scanning on and off. This also allows us to modify the scan behaviour when the app moves to the background.*\n\n`setScanForSeconds(uuid, scanForSeconds)` - string, integer in seconds (default is 5). This parameter specifies the duration of the ON part of the scan cycle for the specified uuid. Returns a promise which resolves to true.\n    \n`setWaitForSeconds(uuid, waitForSeconds)` - string, integer in seconds (default is 5). This parameter specifies the duration of the OFF part of the scan cycle for the specified uuid. Returns a promise which resolves to true.\n\n\n## Setup\n\n````\nnpm install --save react-native-discovery\n````\n\n### iOS\n* Run open node_modules/react-native-discovery\n* Drag ReactNativeDiscovery.xcodeproj into your Libraries group\n\n### Android\n##### Step 1 - Update Gradle Settings\n\n```\n// file: android/settings.gradle\n...\n\ninclude ':react-native-discovery'\nproject(':react-native-discovery').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-discovery/android')\n```\n##### Step 2 - Update Gradle Build\n\n```\n// file: android/app/build.gradle\n...\n\ndependencies {\n    ...\n    compile project(':react-native-discovery')\n}\n```\n##### Step 3 - Register React Package\n```\n...\nimport com.joshblour.reactnativediscovery.ReactNativeDiscoveryPackage; // \u003c--- import\n\npublic class MainActivity extends ReactActivity {\n\n    ...\n\n    @Override\n    protected List\u003cReactPackage\u003e getPackages() {\n        return Arrays.\u003cReactPackage\u003easList(\n            new MainReactPackage(),\n            new ReactNativeDiscoveryPackage(this) // \u003c------ add the package\n        );\n    }\n\n    ...\n}\n```\n","funding_links":[],"categories":["Components","\u003ca name=\"OS-\u0026-System-\u0026-File-Manager:-Native-Modules\"\u003eOS, System \u0026 File Manager: Native Modules\u003c/a\u003e"],"sub_categories":["System"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonahforst%2Freact-native-discovery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyonahforst%2Freact-native-discovery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonahforst%2Freact-native-discovery/lists"}