react-native-sdk-ble-middleware-v3
v0.0.3
Published
A React Native middleware library for simplified BLE (Bluetooth Low Energy) operations with context-based API
Maintainers
Readme
react-native-middleware
A React Native middleware library that provides a simplified, context-based API for BLE (Bluetooth Low Energy) operations. This middleware wraps react-native-sdk-ble-v3 and handles all the complexity of BLE communication, so your demo app only needs to install this middleware.
✨ Features
- 🔌 Simplified BLE Operations - Easy-to-use API for scanning, connecting, and managing BLE devices
- 📡 Automatic Event Handling - Built-in state management for devices, connections, and notifications
- 🎣 React Hooks - Custom hooks for seamless integration with React components
- 🔔 Notification Support - Automatic handling of characteristic notifications (FF21, FF31, FF41, FF02)
- � Infusion Control - Built-in methods for controlling infusion devices (start/stop commands)
- �🛡️ Type-Safe - Full TypeScript support with comprehensive type definitions
- 📱 Cross-Platform - Works on both Android and iOS
📦 Installation
In Your Demo App
Step 1: Install the middleware package
npm install react-native-middlewareor
yarn add react-native-middlewareStep 2: Install the required peer dependency
npm install react-native-sdk-ble-v3or
yarn add react-native-sdk-ble-v3Step 3: Link native dependencies (if not using auto-linking)
npx pod-install # iOS onlyNote:
react-native-sdk-ble-v3is a peer dependency. You need to install it in your demo app so that the native modules are properly linked to your app's binary.
In the Middleware Package (For Development)
cd react-native-middleware
npm install
npm run prepare🚀 Quick Start
1. Wrap Your App with BLEProvider
import { BLEProvider } from 'react-native-middleware';
export default function App() {
return (
<BLEProvider>
<YourApp />
</BLEProvider>
);
}2. Use BLE Hooks in Your Components
import { useBLE } from 'react-native-middleware';
function DeviceScanner() {
const {
bluetoothEnabled,
isScanning,
discoveredDevices,
connectedDeviceId,
startScan,
stopScan,
connectToDevice,
} = useBLE();
return (
<View>
<Button
title={isScanning ? 'Stop Scan' : 'Start Scan'}
onPress={isScanning ? stopScan : startScan}
/>
{discoveredDevices.map((device) => (
<TouchableOpacity
key={device.id}
onPress={() => connectToDevice(device)}
>
<Text>{device.name || 'Unknown Device'}</Text>
</TouchableOpacity>
))}
</View>
);
}📚 Documentation
- Installation Guide - Detailed installation instructions and troubleshooting
- Migration Guide - Guide for migrating to peer dependency setup
- Quick Start Guide - Step-by-step setup instructions
- API Documentation - Complete API reference and usage examples
- Infusion Control Guide - Guide for using infusion start/stop functions
- Example App - Full working example application
🎯 Architecture
┌─────────────────┐
│ Demo App │ ← Only installs react-native-middleware
│ │
└────────┬────────┘
│ Uses
▼
┌─────────────────┐
│ Middleware │ ← Provides BLEProvider, hooks, and utilities
│ │
└────────┬────────┘
│ Wraps
▼
┌─────────────────┐
│ react-native- │ ← Only installed in middleware package
│ sdk-ble │
└─────────────────┘🔧 Available Hooks
useBLE()
Complete BLE functionality with all state and operations, including infusion control.
useBLEDevices()
Device scanning and discovery functionality.
useBLEConnection()
Connection status and disconnect operation.
useBLENotifications()
Access to characteristic notifications.
useBLEInfusion()
Infusion control operations (enableBluetooth, startInfusion, stopInfusion).
📱 Supported Platforms
- ✅ iOS 13.0+
- ✅ Android SDK 21+
🛠️ Requirements
- React Native >= 0.70
- React >= 18.0
📄 License
MIT
🤝 Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
🐛 Issues
If you find a bug or have a feature request, please open an issue on GitHub.
Made with create-react-native-library
