{"id":29916197,"url":"https://github.com/multisafepay/react-native-sunmi-barcode-scanner","last_synced_at":"2025-08-02T04:15:29.625Z","repository":{"id":307653441,"uuid":"1029653492","full_name":"MultiSafepay/react-native-sunmi-barcode-scanner","owner":"MultiSafepay","description":"React Native Sunmi Barcode Scanner SDK","archived":false,"fork":false,"pushed_at":"2025-08-01T11:09:49.000Z","size":5898,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-01T12:56:59.834Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/MultiSafepay.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,"zenodo":null}},"created_at":"2025-07-31T11:16:08.000Z","updated_at":"2025-08-01T11:09:53.000Z","dependencies_parsed_at":"2025-08-01T13:07:15.651Z","dependency_job_id":null,"html_url":"https://github.com/MultiSafepay/react-native-sunmi-barcode-scanner","commit_stats":null,"previous_names":["multisafepay/react-native-sunmi-barcode-scanner"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/MultiSafepay/react-native-sunmi-barcode-scanner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MultiSafepay%2Freact-native-sunmi-barcode-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MultiSafepay%2Freact-native-sunmi-barcode-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MultiSafepay%2Freact-native-sunmi-barcode-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MultiSafepay%2Freact-native-sunmi-barcode-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MultiSafepay","download_url":"https://codeload.github.com/MultiSafepay/react-native-sunmi-barcode-scanner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MultiSafepay%2Freact-native-sunmi-barcode-scanner/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334299,"owners_count":24233784,"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-02T02:00:12.353Z","response_time":74,"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":"2025-08-02T04:15:28.940Z","updated_at":"2025-08-02T04:15:29.575Z","avatar_url":"https://github.com/MultiSafepay.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Native Sunmi Barcode Scanner\n\nA React Native Expo module for integrating with Sunmi barcode scanners on Android devices, specifically designed for Sunmi K2 kiosks and similar hardware.\n\n## Features\n\n- 🔧 **Dual Operation Modes**: Support for both ON_DEMAND and CONTINUOUS scanning modes\n- 📱 **Cross-platform Safety**: Platform detection prevents crashes on non-Android devices\n- ⚡ **Broadcast-based Integration**: Uses Sunmi's official broadcast API for reliable communication\n- 🔊 **Configurable Audio**: Enable/disable scan beep sounds\n- ⏱️ **Smart Timeouts**: Mode-aware timeout handling (30s for ON_DEMAND, configurable for CONTINUOUS)\n- 🛡️ **Android 14+ Compatible**: Supports latest Android security requirements\n- 🎯 **TypeScript Support**: Full TypeScript definitions included\n\n## Installation\n\n```bash\nnpm install https://github.com/MultiSafepay/react-native-sunmi-barcode-scanner#main\n```\n\n## Basic Usage\n\n```typescript\nimport ReactNativeSunmiBarcodeScanner from \"react-native-sunmi-barcode-scanner\";\n\n// Initialize the scanner (call once when app starts)\nReactNativeSunmiBarcodeScanner.initializeScanner();\n\n// Scan a QR code\ntry {\n  const result = await ReactNativeSunmiBarcodeScanner.scanQRCode();\n  console.log(\"Scanned:\", result);\n} catch (error) {\n  console.error(\"Scan failed:\", error.message);\n}\n```\n\n## Operation Modes\n\n### ON_DEMAND Mode (Default)\n\nScanner is inactive by default and only scans when explicitly triggered via `scanQRCode()`.\n\n```typescript\n// Set to ON_DEMAND mode\nReactNativeSunmiBarcodeScanner.setScannerOperationMode(\"ON_DEMAND\");\n\n// Trigger a single scan\nconst result = await ReactNativeSunmiBarcodeScanner.scanQRCode();\n```\n\n### CONTINUOUS Mode\n\nScanner continuously scans for barcodes. Call `scanQRCode()` to wait for the next scan result.\n\n```typescript\n// Set to CONTINUOUS mode\nReactNativeSunmiBarcodeScanner.setScannerOperationMode(\"CONTINUOUS\");\n\n// Wait for next scan (scanner is always active)\nconst result = await ReactNativeSunmiBarcodeScanner.scanQRCode();\n```\n\n## API Reference\n\n### Methods\n\n#### `initializeScanner(): void`\n\nInitializes the scanner with default settings. Should be called once when the app starts.\n\n#### `scanQRCode(): Promise\u003cstring\u003e`\n\nScans for a QR code and returns the result. Behavior depends on current operation mode:\n\n- **ON_DEMAND**: Triggers a single scan with 30-second timeout\n- **CONTINUOUS**: Waits for next scan with configurable timeout\n\n**Throws:**\n\n- `PlatformNotSupportedError`: When called on non-Android platforms\n- `COOLDOWN_ACTIVE`: When called too quickly (2-second cooldown)\n- `SCAN_TIMEOUT`: When scan times out\n- `SCAN_CANCELLED`: When scan is cancelled\n\n#### `cancelScan(): Promise\u003cvoid\u003e`\n\nCancels any active scan operation.\n\n#### `setScannerOperationMode(mode: ScannerOperationMode): void`\n\nSets the scanner operation mode.\n\n**Parameters:**\n\n- `mode`: `\"ON_DEMAND\"` | `\"CONTINUOUS\"`\n\n#### `getScannerOperationMode(): ScannerOperationMode`\n\nReturns the current scanner operation mode.\n\n#### `setScanTimeout(timeout: number): void`\n\nSets the scan timeout in milliseconds (applies to CONTINUOUS mode only).\n\n**Parameters:**\n\n- `timeout`: Timeout in milliseconds (default: 10000)\n\n#### `setBeep(enabled: boolean): void`\n\nEnables or disables the scan beep sound.\n\n**Parameters:**\n\n- `enabled`: Whether to play beep sound on successful scan\n\n### Types\n\n```typescript\ntype ScannerOperationMode = \"ON_DEMAND\" | \"CONTINUOUS\";\n```\n\n## Complete Example\n\n```typescript\nimport React, { useState, useEffect } from \"react\";\nimport { Alert, Button, View, Text } from \"react-native\";\nimport ReactNativeSunmiBarcodeScanner from \"react-native-sunmi-barcode-scanner\";\n\nexport default function App() {\n  const [currentMode, setCurrentMode] = useState\u003c\"ON_DEMAND\" | \"CONTINUOUS\"\u003e(\"ON_DEMAND\");\n  const [isScanning, setIsScanning] = useState(false);\n\n  useEffect(() =\u003e {\n    // Initialize scanner when app starts\n    ReactNativeSunmiBarcodeScanner.initializeScanner();\n\n    // Get current mode\n    const mode = ReactNativeSunmiBarcodeScanner.getScannerOperationMode();\n    setCurrentMode(mode);\n  }, []);\n\n  const handleScan = async () =\u003e {\n    if (isScanning) return;\n\n    setIsScanning(true);\n    try {\n      const result = await ReactNativeSunmiBarcodeScanner.scanQRCode();\n      Alert.alert(\"Scan Result\", result);\n    } catch (error) {\n      Alert.alert(\"Scan Error\", error.message);\n    } finally {\n      setIsScanning(false);\n    }\n  };\n\n  const switchMode = (mode: \"ON_DEMAND\" | \"CONTINUOUS\") =\u003e {\n    ReactNativeSunmiBarcodeScanner.setScannerOperationMode(mode);\n    setCurrentMode(mode);\n  };\n\n  return (\n    \u003cView style={{ flex: 1, padding: 20 }}\u003e\n      \u003cText\u003eCurrent Mode: {currentMode}\u003c/Text\u003e\n\n      \u003cView style={{ flexDirection: \"row\", gap: 10, marginVertical: 20 }}\u003e\n        \u003cButton\n          title=\"On-Demand\"\n          color={currentMode === \"ON_DEMAND\" ? \"#28a032ff\" : \"#718faeff\"}\n          onPress={() =\u003e switchMode(\"ON_DEMAND\")}\n        /\u003e\n        \u003cButton\n          title=\"Continuous\"\n          color={currentMode === \"CONTINUOUS\" ? \"#28a032ff\" : \"#718faeff\"}\n          onPress={() =\u003e switchMode(\"CONTINUOUS\")}\n        /\u003e\n      \u003c/View\u003e\n\n      \u003cButton\n        title={isScanning ? \"Scanning...\" : \"Scan QR Code\"}\n        onPress={handleScan}\n        disabled={isScanning}\n      /\u003e\n    \u003c/View\u003e\n  );\n}\n```\n\n## Platform Support\n\n- ✅ **Android**: Full support on Sunmi devices (K2, etc.)\n- ❌ **iOS**: Not supported (throws `PlatformNotSupportedError`)\n- ❌ **Web**: Not supported (throws `PlatformNotSupportedError`)\n\n## Hardware Requirements\n\n- Sunmi Android device with built-in barcode scanner (e.g., Sunmi K2 kiosk)\n- Android API level 24 or higher\n- Sunmi scanner service installed and running\n\n## Technical Details\n\n### Sunmi Commands Used\n\n- `@SCNMOD0` - Trigger mode (ON_DEMAND)\n- `@SCNMOD2` - Auto sense mode (CONTINUOUS)\n- `#SCNTRG1` - Trigger single scan\n- `#SCNTRG0` - Stop scanning\n- `@ORTSET30000` - 30 second timeout for ON_DEMAND\n- `@ORTSET800` - 800ms timeout for CONTINUOUS\n- `@RRDDUR1000` - 1000ms same code interval\n- `@GRBENA1` - Enable beep sound\n\n### Broadcast Intents\n\n- `com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED` - Receives scan results\n- `com.sunmi.scanner.ACTION_SCANNER_SERIAL_SETTING` - Scanner configuration\n- `com.sunmi.scanner.Setting_cmd` - Send commands to scanner\n\n## Troubleshooting\n\n### Common Issues\n\n1. **\"Platform not supported\" error**\n   - Solution: This module only works on Android Sunmi devices\n\n2. **Scanner not responding**\n   - Solution: Ensure Sunmi scanner service is running\n   - Try: Restart the device or reinstall Sunmi scanner app\n\n3. **Scans not detected**\n   - Solution: Make sure broadcast output is enabled\n   - Check: Scanner hardware is not physically damaged\n\n4. **Timeout issues**\n   - ON_DEMAND mode: 30-second timeout is fixed\n   - CONTINUOUS mode: Use `setScanTimeout()` to adjust\n\n### Debug Tips\n\n- Enable development mode to see console logs\n- Check if scanner LED/laser is active during scans\n- Test with different QR code types and sizes\n- Verify scanner permissions in Android settings\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\n### Version 0.1.0\n\n- Initial release\n- Dual operation mode support (ON_DEMAND/CONTINUOUS)\n- Platform safety checks\n- Android 14+ compatibility\n- TypeScript support\n\n## Acknowledgments\n\n- Built for Sunmi K2 kiosks and compatible hardware\n- Uses Sunmi's official broadcast-based scanner API\n- Developed with Expo modules architecture\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultisafepay%2Freact-native-sunmi-barcode-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultisafepay%2Freact-native-sunmi-barcode-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultisafepay%2Freact-native-sunmi-barcode-scanner/lists"}