@arfuhad/react-native-smart-camera 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +222 -70
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,61 +1,35 @@
1
1
  # react-native-smart-camera
2
2
 
3
- Expo-compatible native module for camera preview, face detection, blink detection, and WebRTC streaming.
3
+ An Expo-compatible native module that provides camera preview via VisionCamera, comprehensive face detection using Google ML Kit, blink detection, and a native WebRTC bridge for video calling and streaming.
4
4
 
5
- ## Features
5
+ ## Requirements
6
6
 
7
- - 📷 Camera preview via VisionCamera
8
- - 👁️ Real-time face detection with Google ML Kit
9
- - 😉 Blink detection with configurable sensitivity
10
- - 📡 Native WebRTC bridge for video calling and streaming
11
- - 🔌 Expo config plugin for zero-config setup
12
- - 📱 Static image face detection
13
-
14
- ## Expo Compatibility
7
+ - Expo SDK 49
8
+ - Expo Dev Client (required)
9
+ - EAS Build
15
10
 
16
- | Expo Workflow | Supported | Notes |
17
- | --------------- | --------- | ---------------------------------- |
18
- | Expo Managed | ❌ No | Requires native code |
19
- | Expo Dev Client | ✅ Yes | Recommended for development |
20
- | Expo Bare | ✅ Yes | Full native control |
11
+ > **Important**: This package does NOT work with Expo Go. You must use Expo Dev Client or Bare Workflow.
21
12
 
22
- **Requirements:**
23
- - Expo SDK ≥ 49
24
- - Expo Dev Client or Bare Workflow
25
- - EAS Build or local native builds
13
+ | Expo Workflow | Supported | Why |
14
+ |---------------|-----------|-----|
15
+ | Expo Managed (Go) | No | WebRTC + VisionCamera need native code |
16
+ | Expo Dev Client | ✅ Yes | Allows custom native modules |
17
+ | Expo Bare | ✅ Yes | Full native control |
26
18
 
27
19
  ## Installation
28
20
 
29
21
  ```bash
30
- # Install the package
31
- npx expo install react-native-smart-camera
32
-
33
- # Install peer dependencies
34
- npx expo install react-native-vision-camera react-native-webrtc react-native-worklets-core
35
-
36
- # Rebuild native code
37
- npx expo prebuild
38
- npx expo run:ios
22
+ expo install react-native-smart-camera
23
+ expo prebuild
24
+ expo run:ios
39
25
  # or
40
- npx expo run:android
26
+ expo run:android
41
27
  ```
42
28
 
43
- ## Expo Config Plugin
44
-
45
- Add to your `app.json` or `app.config.js`:
29
+ Or with EAS Build:
46
30
 
47
- ```json
48
- {
49
- "plugins": [
50
- [
51
- "react-native-smart-camera",
52
- {
53
- "cameraPermissionText": "Allow camera access for face detection",
54
- "microphonePermissionText": "Allow microphone for audio streaming"
55
- }
56
- ]
57
- ]
58
- }
31
+ ```bash
32
+ eas build --profile development
59
33
  ```
60
34
 
61
35
  ## Usage
@@ -65,7 +39,7 @@ Add to your `app.json` or `app.config.js`:
65
39
  ```tsx
66
40
  import { SmartCamera } from 'react-native-smart-camera';
67
41
 
68
- export default function App() {
42
+ function App() {
69
43
  return (
70
44
  <SmartCamera
71
45
  camera="front"
@@ -75,14 +49,18 @@ export default function App() {
75
49
  }
76
50
  ```
77
51
 
78
- ### Face Detection
52
+ ### Face Detection with Blink Detection
79
53
 
80
54
  ```tsx
81
- import { SmartCamera, Face } from 'react-native-smart-camera';
55
+ import { SmartCamera } from 'react-native-smart-camera';
82
56
 
83
- export default function App() {
84
- const handleFaces = (faces: Face[]) => {
85
- console.log(`Detected ${faces.length} faces`);
57
+ function App() {
58
+ const handleBlink = (event) => {
59
+ console.log('Blink detected!', event);
60
+ };
61
+
62
+ const handleFaceDetected = (faces) => {
63
+ console.log('Faces:', faces);
86
64
  };
87
65
 
88
66
  return (
@@ -94,34 +72,120 @@ export default function App() {
94
72
  landmarkMode: 'all',
95
73
  classificationMode: 'all',
96
74
  }}
97
- onFaceDetected={handleFaces}
75
+ blinkDetection
76
+ onBlinkDetected={handleBlink}
77
+ onFaceDetected={handleFaceDetected}
98
78
  style={{ flex: 1 }}
99
79
  />
100
80
  );
101
81
  }
102
82
  ```
103
83
 
104
- ### Blink Detection
84
+ ### WebRTC Video Calling
105
85
 
106
86
  ```tsx
107
- import { SmartCamera, BlinkEvent } from 'react-native-smart-camera';
87
+ import { SmartCamera } from 'react-native-smart-camera';
88
+ import { RTCPeerConnection } from 'react-native-webrtc';
108
89
 
109
- export default function App() {
110
- const handleBlink = (event: BlinkEvent) => {
111
- console.log('Blink detected!', event);
112
- };
90
+ function VideoCall() {
91
+ const peerConnection = new RTCPeerConnection(config);
113
92
 
114
93
  return (
115
94
  <SmartCamera
116
95
  camera="front"
117
- blinkDetection
118
- onBlinkDetected={handleBlink}
96
+ webrtc={{
97
+ enabled: true,
98
+ peerConnection,
99
+ mode: 'call',
100
+ }}
119
101
  style={{ flex: 1 }}
120
102
  />
121
103
  );
122
104
  }
123
105
  ```
124
106
 
107
+ ## API Reference
108
+
109
+ ### SmartCamera Props
110
+
111
+ ```tsx
112
+ interface SmartCameraProps {
113
+ // Camera settings
114
+ camera?: 'front' | 'back';
115
+ fps?: number;
116
+ style?: ViewStyle;
117
+
118
+ // Face Detection Options
119
+ faceDetection?: FaceDetectionConfig;
120
+
121
+ // Blink Detection
122
+ blinkDetection?: boolean;
123
+ onBlinkDetected?: (event: BlinkEvent) => void;
124
+
125
+ // Face Detection Callback
126
+ onFaceDetected?: (faces: Face[]) => void;
127
+
128
+ // WebRTC Configuration
129
+ webrtc?: WebRTCConfig;
130
+ }
131
+ ```
132
+
133
+ ### Face Detection Options
134
+
135
+ #### Common Options (Frame Processor and Static Images)
136
+
137
+ | Option | Description | Default | Options |
138
+ |--------|-------------|---------|---------|
139
+ | `performanceMode` | Favor speed or accuracy when detecting faces | `'fast'` | `'fast'`, `'accurate'` |
140
+ | `landmarkMode` | Whether to identify facial landmarks: eyes, ears, nose, cheeks, mouth | `'none'` | `'none'`, `'all'` |
141
+ | `contourMode` | Whether to detect contours of facial features. Contours are detected for only the most prominent face in an image | `'none'` | `'none'`, `'all'` |
142
+ | `classificationMode` | Whether to classify faces into categories such as 'smiling' and 'eyes open' | `'none'` | `'none'`, `'all'` |
143
+ | `minFaceSize` | Sets the smallest desired face size, expressed as the ratio of the width of the head to width of the image | `0.15` | `number` |
144
+ | `trackingEnabled` | Whether to assign faces an ID to track faces across images. Note: Don't enable with contourMode for best performance | `false` | `boolean` |
145
+
146
+ #### Frame Processor Options
147
+
148
+ | Option | Description | Default | Options |
149
+ |--------|-------------|---------|---------|
150
+ | `cameraFacing` | Current active camera | `'front'` | `'front'`, `'back'` |
151
+ | `autoMode` | Handle auto scale (face bounds, contour, landmarks) and rotation on native side. If disabled, results are relative to frame coordinates, not screen/preview. Disable when using Skia Frame Processor | `false` | `boolean` |
152
+ | `windowWidth` | Required when using `autoMode`. Screen width for coordinate scaling | `1.0` | `number` |
153
+ | `windowHeight` | Required when using `autoMode`. Screen height for coordinate scaling | `1.0` | `number` |
154
+
155
+ #### Static Images
156
+
157
+ | Option | Description | Default | Options |
158
+ |--------|-------------|---------|---------|
159
+ | `image` | Image source for static face detection | - | `number`, `string`, `{ uri: string }` |
160
+
161
+ ### Types
162
+
163
+ ```tsx
164
+ interface BlinkEvent {
165
+ timestamp: number;
166
+ leftEyeOpen: number; // 0.0 - 1.0
167
+ rightEyeOpen: number; // 0.0 - 1.0
168
+ isBlink: boolean;
169
+ faceId?: number;
170
+ }
171
+
172
+ interface Face {
173
+ bounds: { x: number; y: number; width: number; height: number };
174
+ landmarks?: FaceLandmarks;
175
+ contours?: FaceContours;
176
+ smilingProbability?: number;
177
+ leftEyeOpenProbability?: number;
178
+ rightEyeOpenProbability?: number;
179
+ trackingId?: number;
180
+ }
181
+
182
+ interface WebRTCConfig {
183
+ enabled: boolean;
184
+ peerConnection?: RTCPeerConnection;
185
+ mode?: 'call' | 'stream';
186
+ }
187
+ ```
188
+
125
189
  ### Static Image Detection
126
190
 
127
191
  ```tsx
@@ -134,21 +198,109 @@ const faces = await detectFacesInImage({
134
198
  });
135
199
  ```
136
200
 
137
- ## Face Detection Options
201
+ ## Hooks
138
202
 
139
- | Option | Description | Default | Options |
140
- | ------------------ | ----------------------------------------------- | --------- | --------------------- |
141
- | `performanceMode` | Speed vs accuracy trade-off | `'fast'` | `'fast'`, `'accurate'`|
142
- | `landmarkMode` | Detect facial landmarks | `'none'` | `'none'`, `'all'` |
143
- | `contourMode` | Detect facial contours | `'none'` | `'none'`, `'all'` |
144
- | `classificationMode` | Classify smiling/eyes open | `'none'` | `'none'`, `'all'` |
145
- | `minFaceSize` | Minimum face size ratio | `0.15` | `number` |
146
- | `trackingEnabled` | Track faces across frames | `false` | `boolean` |
203
+ ### useSmartCamera
147
204
 
148
- ## API Reference
205
+ ```tsx
206
+ import { useSmartCamera } from 'react-native-smart-camera';
207
+
208
+ const {
209
+ hasPermission,
210
+ requestPermission,
211
+ device,
212
+ switchCamera,
213
+ } = useSmartCamera();
214
+ ```
215
+
216
+ ### useFaceDetection
217
+
218
+ ```tsx
219
+ import { useFaceDetection } from 'react-native-smart-camera';
220
+
221
+ const { faces, isDetecting } = useFaceDetection({
222
+ performanceMode: 'fast',
223
+ classificationMode: 'all',
224
+ });
225
+ ```
226
+
227
+ ### useBlinkDetection
228
+
229
+ ```tsx
230
+ import { useBlinkDetection } from 'react-native-smart-camera';
231
+
232
+ const { lastBlink, blinkCount } = useBlinkDetection({
233
+ debounceMs: 300,
234
+ });
235
+ ```
236
+
237
+ ### useSmartCameraWebRTC
238
+
239
+ ```tsx
240
+ import { useSmartCameraWebRTC } from 'react-native-smart-camera';
241
+
242
+ const {
243
+ videoTrack,
244
+ startStreaming,
245
+ stopStreaming,
246
+ switchCamera,
247
+ } = useSmartCameraWebRTC({
248
+ peerConnection,
249
+ mode: 'call',
250
+ });
251
+ ```
149
252
 
150
- See [ARCHITECTURE.md](./ARCHITECTURE.md) for full API documentation.
253
+ ## Expo Config Plugin
254
+
255
+ This package includes an Expo config plugin that automatically configures permissions and native dependencies.
256
+
257
+ ```json
258
+ {
259
+ "expo": {
260
+ "plugins": ["react-native-smart-camera"]
261
+ }
262
+ }
263
+ ```
264
+
265
+ The plugin automatically adds:
266
+ - Camera permission (iOS & Android)
267
+ - Microphone permission (iOS & Android)
268
+ - Required iOS frameworks
269
+ - Android ProGuard rules for ML Kit
270
+
271
+ ## Architecture
272
+
273
+ ```
274
+ Expo App
275
+ ├── SmartCamera (JS Component)
276
+ ├── VisionCamera (native camera)
277
+ ├── Frame Processor (worklet)
278
+ │ └── ML Kit Face Detection
279
+ ├── Native WebRTC Bridge
280
+ │ ├── iOS (Swift)
281
+ │ └── Android (Kotlin)
282
+ └── react-native-webrtc
283
+ ```
284
+
285
+ ## Peer Dependencies
286
+
287
+ This package requires the following peer dependencies:
288
+
289
+ ```json
290
+ {
291
+ "react-native-vision-camera": ">=3.0.0",
292
+ "react-native-webrtc": ">=118.0.0",
293
+ "react-native-worklets-core": ">=1.0.0"
294
+ }
295
+ ```
296
+
297
+ ## Limitations
298
+
299
+ - ❌ Not supported in Expo Go
300
+ - ❌ Requires Expo Dev Client or Bare Workflow
301
+ - ❌ Native build required (via `expo run:ios/android` or EAS Build)
151
302
 
152
303
  ## License
153
304
 
154
305
  MIT
306
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arfuhad/react-native-smart-camera",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Expo-compatible native module for camera preview, face detection, blink detection, and WebRTC streaming",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",