@trustchex/react-native-sdk 1.464.0 → 1.472.0
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.
- package/android/src/main/java/com/trustchex/reactnativesdk/camera/TrustchexCameraView.kt +43 -3
- package/ios/Camera/TrustchexCameraView.swift +152 -27
- package/ios/Permission/PermissionModule.m +22 -0
- package/ios/Permission/PermissionModule.swift +67 -0
- package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +24 -3
- package/lib/module/Screens/Dynamic/VerbalConsentScreen.js +1 -1
- package/lib/module/Screens/Dynamic/VideoCallScreen.js +7 -12
- package/lib/module/Screens/Static/ResultScreen.js +4 -1
- package/lib/module/Shared/Components/EIDScanner.js +166 -163
- package/lib/module/Shared/Components/FaceCamera.js +14 -8
- package/lib/module/Shared/Components/IdentityDocumentCamera.js +7 -6
- package/lib/module/Shared/Libs/PERMISSIONS_MANAGER.md +268 -0
- package/lib/module/Shared/Libs/index.js +20 -0
- package/lib/module/Shared/Libs/permissions.utils.js +199 -0
- package/lib/module/Translation/Resources/en.js +1 -0
- package/lib/module/Translation/Resources/tr.js +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/VideoCallScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/FaceCamera.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/index.d.ts +20 -0
- package/lib/typescript/src/Shared/Libs/index.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/permissions.utils.d.ts +58 -0
- package/lib/typescript/src/Shared/Libs/permissions.utils.d.ts.map +1 -0
- package/lib/typescript/src/Translation/Resources/en.d.ts +1 -0
- package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/tr.d.ts +1 -0
- package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +45 -5
- package/src/Screens/Dynamic/VerbalConsentScreen.tsx +1 -1
- package/src/Screens/Dynamic/VideoCallScreen.tsx +8 -19
- package/src/Screens/Static/ResultScreen.tsx +13 -9
- package/src/Shared/Components/EIDScanner.tsx +210 -160
- package/src/Shared/Components/FaceCamera.tsx +19 -16
- package/src/Shared/Components/IdentityDocumentCamera.tsx +7 -7
- package/src/Shared/Libs/PERMISSIONS_MANAGER.md +268 -0
- package/src/Shared/Libs/index.ts +63 -0
- package/src/Shared/Libs/permissions.utils.ts +251 -0
- package/src/Translation/Resources/en.ts +1 -0
- package/src/Translation/Resources/tr.ts +1 -0
- package/src/version.ts +1 -1
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
type Frame,
|
|
22
22
|
} from './TrustchexCamera';
|
|
23
23
|
import { NativeModules } from 'react-native';
|
|
24
|
+
import PermissionManager from '../Libs/permissions.utils';
|
|
24
25
|
import mrzUtils from '../Libs/mrz.utils';
|
|
25
26
|
import { useKeepAwake } from '../Libs/native-keep-awake.utils';
|
|
26
27
|
import { useIsFocused } from '@react-navigation/native';
|
|
@@ -246,13 +247,12 @@ const IdentityDocumentCamera = ({
|
|
|
246
247
|
|
|
247
248
|
useEffect(() => {
|
|
248
249
|
const requestPermissions = async () => {
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
setHasPermission(true);
|
|
250
|
+
try {
|
|
251
|
+
const hasCameraPermission =
|
|
252
|
+
await PermissionManager.requestPermission('camera');
|
|
253
|
+
setHasPermission(hasCameraPermission);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
setHasPermission(false);
|
|
256
256
|
}
|
|
257
257
|
setPermissionsRequested(true);
|
|
258
258
|
};
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# PermissionManager Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`PermissionManager` is a centralized utility for handling all platform-specific permission requests (camera, microphone, NFC, etc.) in the React Native SDK. It abstracts away platform differences (iOS vs Android) and provides a clean, consistent API.
|
|
6
|
+
|
|
7
|
+
## Location
|
|
8
|
+
|
|
9
|
+
- **File**: `src/Shared/Libs/permissions.utils.ts`
|
|
10
|
+
- **Export**: Can be imported from `src/Shared/Libs/index.ts`
|
|
11
|
+
|
|
12
|
+
## Supported Permissions
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
type PermissionType = 'camera' | 'microphone' | 'nfc';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Permission | iOS | Android | Notes |
|
|
19
|
+
| ------------ | --- | ------- | ---------------------------------------- |
|
|
20
|
+
| `camera` | ✅ | ✅ | Camera access for video recording |
|
|
21
|
+
| `microphone` | ✅ | ✅ | Microphone access for audio recording |
|
|
22
|
+
| `nfc` | ✅ | ✅ | NFC chip reading (document verification) |
|
|
23
|
+
|
|
24
|
+
## API Reference
|
|
25
|
+
|
|
26
|
+
### Request Methods
|
|
27
|
+
|
|
28
|
+
#### `requestPermission(permission: PermissionType): Promise<boolean>`
|
|
29
|
+
|
|
30
|
+
Request a single permission. Returns `true` if granted, `false` if denied.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import PermissionManager from '../../Shared/Libs/permissions.utils';
|
|
34
|
+
|
|
35
|
+
const hasCamera = await PermissionManager.requestPermission('camera');
|
|
36
|
+
if (!hasCamera) {
|
|
37
|
+
console.log('Camera permission denied');
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### `requestPermissions(permissions: PermissionType[]): Promise<Map<PermissionType, boolean>>`
|
|
42
|
+
|
|
43
|
+
Request multiple permissions at once. Returns a Map with permission status for each.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const results = await PermissionManager.requestPermissions([
|
|
47
|
+
'camera',
|
|
48
|
+
'microphone',
|
|
49
|
+
]);
|
|
50
|
+
const hasCamera = results.get('camera') ?? false;
|
|
51
|
+
const hasMicrophone = results.get('microphone') ?? false;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### `requestCameraAndMicrophone(): Promise<boolean>`
|
|
55
|
+
|
|
56
|
+
**⭐ Convenience method** — Request camera and microphone together (common for video recording). Returns `true` only if BOTH are granted.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const hasBothPermissions = await PermissionManager.requestCameraAndMicrophone();
|
|
60
|
+
if (!hasBothPermissions) {
|
|
61
|
+
showError('Camera and microphone access required for video call');
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `requestCamera(): Promise<boolean>`
|
|
66
|
+
|
|
67
|
+
Request camera permission only.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const hasCamera = await PermissionManager.requestCamera();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### `requestMicrophone(): Promise<boolean>`
|
|
74
|
+
|
|
75
|
+
Request microphone permission only.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const hasMicrophone = await PermissionManager.requestMicrophone();
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### `requestNFC(): Promise<boolean>`
|
|
82
|
+
|
|
83
|
+
Request NFC permission for document verification.
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const hasNFC = await PermissionManager.requestNFC();
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### `requestWithFallback(permission: PermissionType, onDenied?: () => void): Promise<boolean>`
|
|
90
|
+
|
|
91
|
+
Request permission with custom callback when denied.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const granted = await PermissionManager.requestWithFallback('camera', () => {
|
|
95
|
+
showAlert('Camera access is required for verification');
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Check Methods (Non-requesting)
|
|
100
|
+
|
|
101
|
+
Check if a permission is already granted without requesting.
|
|
102
|
+
|
|
103
|
+
#### `checkPermission(permission: PermissionType): Promise<boolean>`
|
|
104
|
+
|
|
105
|
+
Check a single permission status.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
const hasCamera = await PermissionManager.checkPermission('camera');
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### `hasCameraAndMicrophone(): Promise<boolean>`
|
|
112
|
+
|
|
113
|
+
Check if both camera and microphone are granted.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const ready = await PermissionManager.hasCameraAndMicrophone();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### `hasCamera(): Promise<boolean>`
|
|
120
|
+
|
|
121
|
+
Check if camera is granted.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const hasCamera = await PermissionManager.hasCamera();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `hasMicrophone(): Promise<boolean>`
|
|
128
|
+
|
|
129
|
+
Check if microphone is granted.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const hasMicrophone = await PermissionManager.hasMicrophone();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### `hasNFC(): Promise<boolean>`
|
|
136
|
+
|
|
137
|
+
Check if NFC is granted.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const hasNFC = await PermissionManager.hasNFC();
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Common Patterns
|
|
144
|
+
|
|
145
|
+
### Pattern 1: Video Call Setup (Camera + Microphone)
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import PermissionManager from '../../Shared/Libs/permissions.utils';
|
|
149
|
+
|
|
150
|
+
async function initializeVideoCall() {
|
|
151
|
+
const hasBothPermissions =
|
|
152
|
+
await PermissionManager.requestCameraAndMicrophone();
|
|
153
|
+
|
|
154
|
+
if (!hasBothPermissions) {
|
|
155
|
+
setConnectionState('permissions_denied');
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Proceed with video call initialization
|
|
160
|
+
const stream = await service.initialize();
|
|
161
|
+
setLocalStream(stream);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Pattern 2: Document Verification (NFC)
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
const hasNFC = await PermissionManager.requestNFC();
|
|
169
|
+
|
|
170
|
+
if (!hasNFC) {
|
|
171
|
+
showError('NFC access required to read document');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const result = await readNFCChip();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Pattern 3: Check Before Requesting
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
// First check if permission is already granted
|
|
182
|
+
const alreadyHasCamera = await PermissionManager.checkPermission('camera');
|
|
183
|
+
|
|
184
|
+
if (alreadyHasCamera) {
|
|
185
|
+
// Skip request dialog
|
|
186
|
+
startCamera();
|
|
187
|
+
} else {
|
|
188
|
+
// Request permission (shows OS dialog)
|
|
189
|
+
const granted = await PermissionManager.requestCamera();
|
|
190
|
+
if (granted) {
|
|
191
|
+
startCamera();
|
|
192
|
+
} else {
|
|
193
|
+
showErrorMessage('Camera access required');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Platform Implementation Details
|
|
199
|
+
|
|
200
|
+
### iOS
|
|
201
|
+
|
|
202
|
+
Uses the `react-native-permissions` library with `RNPermissions` module.
|
|
203
|
+
|
|
204
|
+
**Permissions layout location**: `ios/App.xcodeproj/Info.plist`
|
|
205
|
+
|
|
206
|
+
Required Info.plist keys:
|
|
207
|
+
|
|
208
|
+
- `NSCameraUsageDescription` — Camera access explanation
|
|
209
|
+
- `NSMicrophoneUsageDescription` — Microphone access explanation
|
|
210
|
+
- `NFCReaderUsageDescription` — NFC access explanation
|
|
211
|
+
|
|
212
|
+
### Android
|
|
213
|
+
|
|
214
|
+
Uses built-in `PermissionsAndroid` from React Native core.
|
|
215
|
+
|
|
216
|
+
**Permissions manifest location**: `android/app/src/main/AndroidManifest.xml`
|
|
217
|
+
|
|
218
|
+
Required manifest permissions:
|
|
219
|
+
|
|
220
|
+
- `android.permission.CAMERA` — Camera access
|
|
221
|
+
- `android.permission.RECORD_AUDIO` — Microphone access
|
|
222
|
+
- `android.permission.NFC` — NFC chip reading
|
|
223
|
+
|
|
224
|
+
## Error Handling
|
|
225
|
+
|
|
226
|
+
The PermissionManager handles errors internally and logs them using the debug utility. All methods return clear boolean or Map results so you can check status directly:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const granted = await PermissionManager.requestCamera();
|
|
230
|
+
|
|
231
|
+
// Simple check
|
|
232
|
+
if (!granted) {
|
|
233
|
+
// Handle permission denied
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Best Practices
|
|
238
|
+
|
|
239
|
+
1. ✅ **Use convenience methods** — `requestCameraAndMicrophone()` instead of manually requesting both
|
|
240
|
+
2. ✅ **Request at the right time** — Request permissions when the feature is about to be used
|
|
241
|
+
3. ✅ **Check before requesting** — Use `checkPermission()` if you want to skip the OS dialog
|
|
242
|
+
4. ✅ **Handle denial gracefully** — Always provide clear error messages when permissions are denied
|
|
243
|
+
5. ✅ **Use the centralized manager** — Never import React Native permissions directly; always use PermissionManager
|
|
244
|
+
|
|
245
|
+
## Troubleshooting
|
|
246
|
+
|
|
247
|
+
### Permission request dialog not appearing
|
|
248
|
+
|
|
249
|
+
- Check that you're using `request*` methods, not `check*` methods
|
|
250
|
+
- Verify the permission is in the app's manifest (Android) or Info.plist (iOS)
|
|
251
|
+
- Test on a device where the permission hasn't been granted yet
|
|
252
|
+
|
|
253
|
+
### Camera/Microphone not working after permission granted
|
|
254
|
+
|
|
255
|
+
- Check that you're handling successful permission grant and initializing the feature
|
|
256
|
+
- Verify other features aren't holding exclusive access to the device
|
|
257
|
+
|
|
258
|
+
### NFC not working on iOS
|
|
259
|
+
|
|
260
|
+
- Ensure `NFCReaderUsageDescription` is set in Info.plist
|
|
261
|
+
- The app must be signed with proper entitlements for NFC
|
|
262
|
+
- NFC requires iPhone XS or later
|
|
263
|
+
|
|
264
|
+
## Related Files
|
|
265
|
+
|
|
266
|
+
- `src/Screens/Dynamic/VideoCallScreen.tsx` — Example usage with video calls
|
|
267
|
+
- `src/Shared/Libs/index.ts` — Exported for easy importing
|
|
268
|
+
- `src/Shared/Libs/debug.utils.ts` — Used internally for debug logging
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Export utility modules with validated symbols only.
|
|
2
|
+
export { default as PermissionManager } from './permissions.utils';
|
|
3
|
+
export type { PermissionType } from './permissions.utils';
|
|
4
|
+
export { SignalingClient } from './SignalingClient';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
setDebugMode,
|
|
8
|
+
setLogLevel,
|
|
9
|
+
isDebugEnabled,
|
|
10
|
+
getLogLevel,
|
|
11
|
+
traceLog,
|
|
12
|
+
debugLog,
|
|
13
|
+
infoLog,
|
|
14
|
+
debugWarn,
|
|
15
|
+
debugError,
|
|
16
|
+
logError,
|
|
17
|
+
logWarn,
|
|
18
|
+
} from './debug.utils';
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
default as HTTPClient,
|
|
22
|
+
HttpClientError,
|
|
23
|
+
UnauthorizedError,
|
|
24
|
+
ForbiddenError,
|
|
25
|
+
NotFoundError,
|
|
26
|
+
BadRequestError,
|
|
27
|
+
TooManyRequestsError,
|
|
28
|
+
InternalServerError,
|
|
29
|
+
} from './http-client';
|
|
30
|
+
|
|
31
|
+
export * from './analytics.utils';
|
|
32
|
+
export type { Rect } from './contains';
|
|
33
|
+
export { getLocalizedCountryName } from './country-display.utils';
|
|
34
|
+
export { getSessionKey, encryptWithAes, decryptWithAes } from './crypto.utils';
|
|
35
|
+
export { default as debounce } from './debounce.utils';
|
|
36
|
+
export { handleDeepLink } from './deeplink.utils';
|
|
37
|
+
export { getSimulatedDemoData, isDemoSession } from './demo.utils';
|
|
38
|
+
export { default as MRZUtils } from './mrz.utils';
|
|
39
|
+
export { NativeDeviceInfo } from './native-device-info.utils';
|
|
40
|
+
export { default as getDeviceInfo } from './native-device-info.utils';
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
useKeepAwake,
|
|
44
|
+
enableKeepAwake,
|
|
45
|
+
disableKeepAwake,
|
|
46
|
+
isKeepAwakeCurrentlyActive,
|
|
47
|
+
getKeepAwakeStats,
|
|
48
|
+
} from './native-keep-awake.utils';
|
|
49
|
+
|
|
50
|
+
export { runWithRetry } from './promise.utils';
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
configureStatusBarForWhiteBackground,
|
|
54
|
+
useStatusBarWhiteBackground,
|
|
55
|
+
} from './status-bar.utils';
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
speak,
|
|
59
|
+
speakWithDebounce,
|
|
60
|
+
stopSpeaking,
|
|
61
|
+
resetLastMessage,
|
|
62
|
+
initializeTTS,
|
|
63
|
+
} from './tts.utils';
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Platform,
|
|
3
|
+
NativeModules,
|
|
4
|
+
PermissionsAndroid,
|
|
5
|
+
type Permission,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import { debugLog, debugError, debugWarn } from './debug.utils';
|
|
8
|
+
|
|
9
|
+
const { PermissionModule } = NativeModules;
|
|
10
|
+
|
|
11
|
+
export type PermissionType = 'camera' | 'microphone' | 'nfc';
|
|
12
|
+
|
|
13
|
+
class PermissionManager {
|
|
14
|
+
private static permissionCache: Map<PermissionType, boolean> = new Map();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Request a single permission
|
|
18
|
+
*/
|
|
19
|
+
static async requestPermission(permission: PermissionType): Promise<boolean> {
|
|
20
|
+
try {
|
|
21
|
+
if (Platform.OS === 'android') {
|
|
22
|
+
return await this.requestAndroidPermission(permission);
|
|
23
|
+
} else {
|
|
24
|
+
return await this.requestIOSPermission(permission);
|
|
25
|
+
}
|
|
26
|
+
} catch (error) {
|
|
27
|
+
debugError(
|
|
28
|
+
'PermissionManager',
|
|
29
|
+
`Failed to request ${permission}:`,
|
|
30
|
+
error
|
|
31
|
+
);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Request multiple permissions at once
|
|
38
|
+
*/
|
|
39
|
+
static async requestPermissions(
|
|
40
|
+
permissions: PermissionType[]
|
|
41
|
+
): Promise<Map<PermissionType, boolean>> {
|
|
42
|
+
const results = new Map<PermissionType, boolean>();
|
|
43
|
+
|
|
44
|
+
if (Platform.OS === 'android') {
|
|
45
|
+
const androidPermissions = permissions.map((p) =>
|
|
46
|
+
this.permissionTypeToAndroid(p)
|
|
47
|
+
);
|
|
48
|
+
const granted =
|
|
49
|
+
await PermissionsAndroid.requestMultiple(androidPermissions);
|
|
50
|
+
|
|
51
|
+
permissions.forEach((p, i) => {
|
|
52
|
+
const isGranted =
|
|
53
|
+
granted[androidPermissions[i]] === PermissionsAndroid.RESULTS.GRANTED;
|
|
54
|
+
results.set(p, isGranted);
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
for (const permission of permissions) {
|
|
58
|
+
const isGranted = await this.requestIOSPermission(permission);
|
|
59
|
+
results.set(permission, isGranted);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Check if a permission is granted (without requesting)
|
|
68
|
+
*/
|
|
69
|
+
static async checkPermission(permission: PermissionType): Promise<boolean> {
|
|
70
|
+
try {
|
|
71
|
+
if (Platform.OS === 'android') {
|
|
72
|
+
const androidPerm = this.permissionTypeToAndroid(permission);
|
|
73
|
+
const result = await PermissionsAndroid.check(androidPerm);
|
|
74
|
+
return result;
|
|
75
|
+
} else {
|
|
76
|
+
return await this.checkIOSPermission(permission);
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
debugError(
|
|
80
|
+
'PermissionManager',
|
|
81
|
+
`Failed to check ${permission} permission:`,
|
|
82
|
+
error
|
|
83
|
+
);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Request permission with user-friendly error handling
|
|
90
|
+
*/
|
|
91
|
+
static async requestWithFallback(
|
|
92
|
+
permission: PermissionType,
|
|
93
|
+
onDenied?: () => void
|
|
94
|
+
): Promise<boolean> {
|
|
95
|
+
const isGranted = await this.requestPermission(permission);
|
|
96
|
+
|
|
97
|
+
if (!isGranted) {
|
|
98
|
+
debugLog('PermissionManager', `${permission} permission denied`);
|
|
99
|
+
onDenied?.();
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Convenience method: Request camera and microphone together (for video recording)
|
|
108
|
+
*/
|
|
109
|
+
static async requestCameraAndMicrophone(): Promise<boolean> {
|
|
110
|
+
const permissions = await this.requestPermissions(['camera', 'microphone']);
|
|
111
|
+
|
|
112
|
+
const hasCamera = permissions.get('camera') ?? false;
|
|
113
|
+
const hasMicrophone = permissions.get('microphone') ?? false;
|
|
114
|
+
|
|
115
|
+
return hasCamera && hasMicrophone;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Convenience method: Request camera only
|
|
120
|
+
*/
|
|
121
|
+
static async requestCamera(): Promise<boolean> {
|
|
122
|
+
return this.requestPermission('camera');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Convenience method: Request microphone only
|
|
127
|
+
*/
|
|
128
|
+
static async requestMicrophone(): Promise<boolean> {
|
|
129
|
+
return this.requestPermission('microphone');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Convenience method: Request NFC only
|
|
134
|
+
*/
|
|
135
|
+
static async requestNFC(): Promise<boolean> {
|
|
136
|
+
return this.requestPermission('nfc');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Check if camera and microphone are both accessible
|
|
141
|
+
*/
|
|
142
|
+
static async hasCameraAndMicrophone(): Promise<boolean> {
|
|
143
|
+
const camera = await this.checkPermission('camera');
|
|
144
|
+
const microphone = await this.checkPermission('microphone');
|
|
145
|
+
return camera && microphone;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Check if camera is accessible
|
|
150
|
+
*/
|
|
151
|
+
static async hasCamera(): Promise<boolean> {
|
|
152
|
+
return this.checkPermission('camera');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Check if microphone is accessible
|
|
157
|
+
*/
|
|
158
|
+
static async hasMicrophone(): Promise<boolean> {
|
|
159
|
+
return this.checkPermission('microphone');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Check if NFC is accessible
|
|
164
|
+
*/
|
|
165
|
+
static async hasNFC(): Promise<boolean> {
|
|
166
|
+
return this.checkPermission('nfc');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Private helper methods
|
|
170
|
+
|
|
171
|
+
private static permissionTypeToAndroid(permission: PermissionType): Permission {
|
|
172
|
+
const map: Record<PermissionType, Permission> = {
|
|
173
|
+
camera: PermissionsAndroid.PERMISSIONS.CAMERA,
|
|
174
|
+
microphone: PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
|
|
175
|
+
nfc: 'android.permission.NFC' as Permission,
|
|
176
|
+
};
|
|
177
|
+
return map[permission];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private static async requestAndroidPermission(
|
|
181
|
+
permission: PermissionType
|
|
182
|
+
): Promise<boolean> {
|
|
183
|
+
const androidPerm = this.permissionTypeToAndroid(permission);
|
|
184
|
+
const result = await PermissionsAndroid.request(androidPerm);
|
|
185
|
+
return result === PermissionsAndroid.RESULTS.GRANTED;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private static async requestIOSPermission(
|
|
189
|
+
permission: PermissionType
|
|
190
|
+
): Promise<boolean> {
|
|
191
|
+
if (!PermissionModule) {
|
|
192
|
+
debugLog(
|
|
193
|
+
'PermissionManager',
|
|
194
|
+
'PermissionModule not available, assuming permission granted'
|
|
195
|
+
);
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
switch (permission) {
|
|
201
|
+
case 'camera':
|
|
202
|
+
return await PermissionModule.requestCameraPermission();
|
|
203
|
+
case 'microphone':
|
|
204
|
+
return await PermissionModule.requestMicrophonePermission();
|
|
205
|
+
case 'nfc':
|
|
206
|
+
// NFC permission on iOS is automatically handled when NFCManager is initialized
|
|
207
|
+
// No explicit permission request needed
|
|
208
|
+
return true;
|
|
209
|
+
default:
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
debugError(
|
|
214
|
+
'PermissionManager',
|
|
215
|
+
`iOS permission request failed for ${permission}:`,
|
|
216
|
+
error
|
|
217
|
+
);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static async checkIOSPermission(
|
|
223
|
+
permission: PermissionType
|
|
224
|
+
): Promise<boolean> {
|
|
225
|
+
if (!PermissionModule) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
switch (permission) {
|
|
231
|
+
case 'camera':
|
|
232
|
+
return await PermissionModule.checkCameraPermission?.();
|
|
233
|
+
case 'microphone':
|
|
234
|
+
return await PermissionModule.checkMicrophonePermission?.();
|
|
235
|
+
case 'nfc':
|
|
236
|
+
return true;
|
|
237
|
+
default:
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
} catch (error) {
|
|
241
|
+
debugWarn(
|
|
242
|
+
'PermissionManager',
|
|
243
|
+
`iOS permission check failed for ${permission}`,
|
|
244
|
+
error
|
|
245
|
+
);
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export default PermissionManager;
|
|
@@ -103,6 +103,7 @@ export default {
|
|
|
103
103
|
'eidScannerScreen.docTypeResidence': 'Residence Permit',
|
|
104
104
|
'eidScannerScreen.docTypeVisa': 'Visa',
|
|
105
105
|
'eidScannerScreen.expirationDate': 'Expiration Date',
|
|
106
|
+
'eidScannerScreen.issuingState': 'Issuing State',
|
|
106
107
|
'eidScannerScreen.mrzText': 'MRZ Text',
|
|
107
108
|
'eidScannerScreen.nfcNotSupported':
|
|
108
109
|
'This device does not support NFC functionality.',
|
|
@@ -103,6 +103,7 @@ export default {
|
|
|
103
103
|
'eidScannerScreen.docTypeResidence': 'Oturma İzni',
|
|
104
104
|
'eidScannerScreen.docTypeVisa': 'Vize',
|
|
105
105
|
'eidScannerScreen.expirationDate': 'Geçerlilik Tarihi',
|
|
106
|
+
'eidScannerScreen.issuingState': 'Veren Ülke',
|
|
106
107
|
'eidScannerScreen.mrzText': 'MRZ Metni',
|
|
107
108
|
'eidScannerScreen.nfcNotSupported':
|
|
108
109
|
'Bu cihaz NFC işlevini desteklememektedir.',
|
package/src/version.ts
CHANGED