{"id":25932661,"url":"https://github.com/socketmobile/singleentry-rn","last_synced_at":"2025-07-10T13:33:36.955Z","repository":{"id":115907757,"uuid":"363503185","full_name":"SocketMobile/singleentry-rn","owner":"SocketMobile","description":"Sample code showing how the React Native Capture module can be used","archived":false,"fork":false,"pushed_at":"2024-11-27T17:08:09.000Z","size":5682,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-04T00:38:38.888Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SocketMobile.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-01T20:41:03.000Z","updated_at":"2024-11-27T17:08:13.000Z","dependencies_parsed_at":"2023-07-15T03:45:38.571Z","dependency_job_id":null,"html_url":"https://github.com/SocketMobile/singleentry-rn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SocketMobile/singleentry-rn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocketMobile%2Fsingleentry-rn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocketMobile%2Fsingleentry-rn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocketMobile%2Fsingleentry-rn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocketMobile%2Fsingleentry-rn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SocketMobile","download_url":"https://codeload.github.com/SocketMobile/singleentry-rn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SocketMobile%2Fsingleentry-rn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264585372,"owners_count":23632646,"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","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":"2025-03-04T00:38:41.987Z","updated_at":"2025-07-10T13:33:32.036Z","avatar_url":"https://github.com/SocketMobile.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SingleEntryRN\n\nSingleEntryRN is a very simple React Native app using the Socket Mobile React Native Capture Module.\n\nIt shows how to use the Socket Mobile CaptureJS SDK to receive the decoded data from the Socket Mobile devices into an input box.\n\nThe connection state of the Socket Mobile device is shown in a status field at the top of the app.\n\n## Install\n\nIn a terminal window type the following commands:\n\n```sh\ngit clone git@github.com:socketmobile/singleentry-rn.git`\n\ncd singleentry-rn\n```\n\nUsing npm:\n\n```sh\nnpm install\n```\n\nUsing yarn:\n\n```sh\nyarn install\n```\n\nthen make sure the **iOS** portion of the application is setup correctly by typing the following in the terminal window.\n\n```sh\ncd ios\npod install\n```\n\n### Android\n\nWhen running SingleEntryRN for Android, the Socket Mobile Companion must be installed on the device.\n\nSocket Mobile Companion can be found [here](https://play.google.com/store/apps/details?id=com.socketmobile.companion\u0026hl=en_US\u0026gl=US \"Google Play Store\").\n\nUse the Socket Mobile Companion to connect a Socket Mobile barcode scanner. This is a one time setup operation that does not need to get repeated unless you connect the scanner to a different host or the bonding of the scanner has been cleared.\n\nThe Socket Mobile Companion must stay installed on the device as it host the service used for connecting to the scanner.\n\nThe React Native Capture module checks if the service is running, and if not it will start it in the background. If the Socket Mobile Companion is not installed on the device an error `SktErrors.ESKT_UNABLEOPENDEVICE` (-27) will be returned from the initial `capture.open` call.\nThe SingleEntryRN status will display a text asking if the Socket Mobile Companion is installed on the device.\n\n### iOS\n\nThe easiest way to connect a Socket Mobile device is by using the Socket Mobile Companion app that can be downloaded from the App Store [here](https://apps.apple.com/us/app/socket-mobile-companion/id1175638950 \"Apple App Store\").\n\n## React Native Capture Module\n\nThe Socket Mobile React Native Capture Module uses the CaptureJS SDK. That is the only dependency (other than React Native itself) this module has.\n\nThis allows to use the same CaptureJS SDK for a browser webapp, than a React Native app.\n\nThe only difference in the case of a React Native App vs a Webapp using the CaptureJS SDK is the Capture Object.\n\nFor a React Native app, Capture is instantiated by doing a `new` on `CaptureRn()` instead of simply `Capture()`.\n\nHere is an example:\n\n```javascript\n    const capture = new CaptureRn();\n    const appInfo = {\n      appId: 'web:com.socketmobile.SingleEntryRN',\n      developerId: 'bb57d8e1-f911-47ba-b510-693be162686a',\n      appKey:\n        'MC4CFQCcoE4i6nBXLRLKVkx8jwbEnzToWAIVAJdfJOE3U+5rUcrRGDLuXWpz0qgu',\n    };\n    capture\n      .open(appInfo, onCaptureEvent)\n      .then(() =\u003e {\n        setStatus('capture open success');\n      })\n      .catch(err =\u003e {\n        myLogger.error(err);\n        setStatus(`failed to open Capture: ${err}`);\n        // this is mostly for Android platform which requires\n        // Socket Mobile Companion app to be installed\n        if (err === SktErrors.ESKT_UNABLEOPENDEVICE) {\n          setStatus('Is Socket Mobile Companion app installed?');\n        }\n      });\n\n```\n\nThe same applies when a Socket Mobile device connects to the host as shown here:\n\n```javascript\n        ../..\n        case CaptureEventIds.DeviceArrival:\n          const newDevice = new CaptureRn();\n          const {guid, name} = e.value;\n          newDevice\n            .openDevice(guid, capture)\n            .then(result =\u003e {\n              myLogger.log('opening a device returns: ', result);\n              setStatus(`result of opening ${e.value.name} : ${result}`);\n              setDevices(prevDevices =\u003e {\n                prevDevices = prevDevices || [];\n                prevDevices.push({\n                  guid,\n                  name,\n                  handle: newDevice.clientOrDeviceHandle,\n                  device: newDevice,\n                });\n                return [...prevDevices];\n              });\n            })\n            .catch(err =\u003e {\n              myLogger.log(err);\n              setStatus(`error opening a device: ${err}`);\n            });\n          break;\n        ../..\n```\n\nThat is the only difference with CaptureJS, the rest of the API is exactly the same.\n\nThe CaptureJS SDK documentation can be found here: [Socket online documentation](https://docs.socketmobile.com/capturejs/en/latest/ \"docs.socketmobile.com\")\n\n## Application Registration and Credentials\n\nThe Socket Mobile Capture SDK requires the application to be registered on the Socket Mobile Developer Profile which requires a developer registration that will give a developer ID in a form of a UUID.\n\nThe application can then be registered using the `web` prefix separated by a `:` (colon) followed by the application ID, i.e.: `com.socketmobile.SingleEntryRN` and by using your Socket Mobile Developer ID returned during your developer registration.\n\n  NOTE: the application ID is case sensitive.\n\nAn **AppKey** is generated in return of the application registration.\n\nThe Socket Mobile Developer portal can be found here: [Socket Mobile Developer Portal](https://www.socketmobile.com/developers \"socketmobile.com/developers\").\n\nThe Developer ID, the AppID and the AppKey are the 3 arguments required to open Capture.\n\n## Receiving the Capture notifications including the decoded data\n\nWhen opening Capture a callback is required as argument. This is this callback that will be called by Capture each time a notification is received including the device presence (DeviceArrival and DeviceRemoval) and of course each time a Socket Mobile device has decoded some data (DecodedData).\n\nHere is an example for handling the decoded data:\n\n```javascript\n\n      const onCaptureEvent = (e, handle) =\u003e {\n        ../..\n\n        case CaptureEventIds.DecodedData:\n          const deviceSource = devices.find(d =\u003e d.handle === handle);\n          if (deviceSource) {\n            setStatus(`decoded data from: ${deviceSource.name}`);\n          }\n          lastDecodedData = {\n            data: arrayToString(e.value.data),\n            length: e.value.data.length,\n            name: e.value.name,\n          };\n          setDecodedData(lastDecodedData);\n          break;\n      }\n\n```\n\n  NOTE: The second argument of the `onCaptureEvent` callback is a handle to identify the source of the Capture event.\n\n## Debugging on a real target device\n\nFirst make sure the React Native Capture NPM package is present in `package.json` and in the `node_modules`.\n\nYou may have to delete the `node_modules` directory and perform an install again using:\n\n```sh\nnpm install\n```\n\nor:\n\n```sh\nyarn install\n```\n\nThen make sure **Metro** is running before launching the app especially if you want to run the application in debug.\nFor that, go to the project root and run metro:\n`cd  singleentry-rn`\n`yarn start`\n\nThen either `yarn android` or `yarn ios` OR you can run it through Xcode. \n\n### Android Debugging\n\nIn an Android environment in order to have the Android device being able to reach the Metro bundler, you need to reverse proxy the port 8081 and this can be achieved by typing the following command in a terminal window:\n`adb reverse tcp:8081 tcp:8081`\n\nUsually this command prints out `8081` when it succeeds.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketmobile%2Fsingleentry-rn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsocketmobile%2Fsingleentry-rn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsocketmobile%2Fsingleentry-rn/lists"}