react-native-srschat 0.1.27 → 0.1.29

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 (75) hide show
  1. package/README.md +215 -0
  2. package/lib/commonjs/assets/chat-icon-mobile.svg +1 -0
  3. package/lib/commonjs/assets/posiden.svg +51 -0
  4. package/lib/commonjs/components/PoseidonLogo.js +127 -0
  5. package/lib/commonjs/components/PoseidonLogo.js.map +1 -0
  6. package/lib/commonjs/components/header.js +6 -6
  7. package/lib/commonjs/components/header.js.map +1 -1
  8. package/lib/commonjs/components/input.js +20 -1
  9. package/lib/commonjs/components/input.js.map +1 -1
  10. package/lib/commonjs/components/productCard.js +164 -37
  11. package/lib/commonjs/components/productCard.js.map +1 -1
  12. package/lib/commonjs/components/voice.js +88 -17
  13. package/lib/commonjs/components/voice.js.map +1 -1
  14. package/lib/commonjs/components/welcomeInput.js +20 -1
  15. package/lib/commonjs/components/welcomeInput.js.map +1 -1
  16. package/lib/commonjs/layout/icon.js +11 -7
  17. package/lib/commonjs/layout/icon.js.map +1 -1
  18. package/lib/commonjs/layout/layout.js +10 -6
  19. package/lib/commonjs/layout/layout.js.map +1 -1
  20. package/lib/commonjs/layout/welcome.js +5 -6
  21. package/lib/commonjs/layout/welcome.js.map +1 -1
  22. package/lib/commonjs/layout/window.js +2 -1
  23. package/lib/commonjs/layout/window.js.map +1 -1
  24. package/lib/commonjs/utils/audioRecorder.js +58 -7
  25. package/lib/commonjs/utils/audioRecorder.js.map +1 -1
  26. package/lib/module/assets/chat-icon-mobile.svg +1 -0
  27. package/lib/module/assets/posiden.svg +51 -0
  28. package/lib/module/components/PoseidonLogo.js +117 -0
  29. package/lib/module/components/PoseidonLogo.js.map +1 -0
  30. package/lib/module/components/header.js +6 -6
  31. package/lib/module/components/header.js.map +1 -1
  32. package/lib/module/components/input.js +20 -1
  33. package/lib/module/components/input.js.map +1 -1
  34. package/lib/module/components/productCard.js +165 -38
  35. package/lib/module/components/productCard.js.map +1 -1
  36. package/lib/module/components/voice.js +90 -19
  37. package/lib/module/components/voice.js.map +1 -1
  38. package/lib/module/components/welcomeInput.js +20 -1
  39. package/lib/module/components/welcomeInput.js.map +1 -1
  40. package/lib/module/layout/icon.js +11 -7
  41. package/lib/module/layout/icon.js.map +1 -1
  42. package/lib/module/layout/layout.js +10 -6
  43. package/lib/module/layout/layout.js.map +1 -1
  44. package/lib/module/layout/welcome.js +5 -6
  45. package/lib/module/layout/welcome.js.map +1 -1
  46. package/lib/module/layout/window.js +2 -1
  47. package/lib/module/layout/window.js.map +1 -1
  48. package/lib/module/utils/audioRecorder.js +56 -7
  49. package/lib/module/utils/audioRecorder.js.map +1 -1
  50. package/lib/typescript/components/PoseidonLogo.d.ts +7 -0
  51. package/lib/typescript/components/PoseidonLogo.d.ts.map +1 -0
  52. package/lib/typescript/components/header.d.ts.map +1 -1
  53. package/lib/typescript/components/input.d.ts.map +1 -1
  54. package/lib/typescript/components/productCard.d.ts.map +1 -1
  55. package/lib/typescript/components/voice.d.ts.map +1 -1
  56. package/lib/typescript/components/welcomeInput.d.ts.map +1 -1
  57. package/lib/typescript/layout/icon.d.ts.map +1 -1
  58. package/lib/typescript/layout/layout.d.ts.map +1 -1
  59. package/lib/typescript/layout/welcome.d.ts.map +1 -1
  60. package/lib/typescript/utils/audioRecorder.d.ts +2 -0
  61. package/lib/typescript/utils/audioRecorder.d.ts.map +1 -1
  62. package/package.json +5 -3
  63. package/src/assets/chat-icon-mobile.svg +1 -0
  64. package/src/assets/posiden.svg +51 -0
  65. package/src/components/PoseidonLogo.js +55 -0
  66. package/src/components/header.js +3 -2
  67. package/src/components/input.js +20 -1
  68. package/src/components/productCard.js +205 -60
  69. package/src/components/voice.js +107 -23
  70. package/src/components/welcomeInput.js +20 -1
  71. package/src/layout/icon.js +5 -3
  72. package/src/layout/layout.js +12 -8
  73. package/src/layout/welcome.js +2 -5
  74. package/src/layout/window.js +2 -1
  75. package/src/utils/audioRecorder.js +60 -13
@@ -3,6 +3,7 @@
3
3
  import { Platform, PermissionsAndroid } from 'react-native';
4
4
  import Voice from '@react-native-community/voice';
5
5
  import { check, PERMISSIONS, request, RESULTS } from 'react-native-permissions';
6
+ import useAsyncStorage from '../hooks/useAsyncStorage';
6
7
 
7
8
  let resultCallback = null;
8
9
  let silenceTimer = null;
@@ -10,6 +11,19 @@ let isCurrentlyRecording = false;
10
11
  let finalResult = '';
11
12
  const SILENCE_DURATION = 1500; // 1.5 seconds of silence before stopping
12
13
 
14
+ // Add this constant for AsyncStorage key
15
+ const PERMISSION_STORAGE_KEY = '@voice_permission_status';
16
+
17
+ // Create a function that can be called to get permission status
18
+ // This needs to be outside the React component lifecycle
19
+ let permissionStatusGetter = null;
20
+ let permissionStatusSetter = null;
21
+
22
+ export function setPermissionStatusHandlers(getter, setter) {
23
+ permissionStatusGetter = getter;
24
+ permissionStatusSetter = setter;
25
+ }
26
+
13
27
  // Initialize Voice handlers
14
28
  export async function initVoice(onResult) {
15
29
  try {
@@ -60,15 +74,25 @@ export async function initVoice(onResult) {
60
74
  Voice.onSpeechError = async (e) => {
61
75
  console.error('onSpeechError: ', e);
62
76
 
63
-
64
77
  if (silenceTimer) {
65
78
  clearTimeout(silenceTimer);
66
79
  silenceTimer = null;
67
80
  }
68
81
 
82
+ // Check for "No speech detected" error
83
+ const isNoSpeechError = e.error?.code === "recognition_fail" &&
84
+ e.error?.message?.includes("No speech detected");
69
85
 
70
86
  await cleanupVoiceSession();
71
- resultCallback(null, e.error?.message || 'Speech recognition error');
87
+
88
+ // Only send error to callback if it's not a "No speech detected" error
89
+ if (!isNoSpeechError) {
90
+ resultCallback(null, e.error?.message || 'Speech recognition error');
91
+ } else {
92
+ console.log('No speech detected, ignoring error');
93
+ // Optionally, call the callback with null parameters or a special indicator
94
+ resultCallback(null, null); // This won't trigger an error alert in the component
95
+ }
72
96
  };
73
97
 
74
98
  Voice.onSpeechResults = (e) => {
@@ -245,13 +269,32 @@ export async function cancelRecording() {
245
269
  }
246
270
 
247
271
  export async function requestAudioPermission() {
248
- if (Platform.OS === 'android') {
249
- return await requestAndroidPermission();
250
- } else if (Platform.OS === 'ios') {
251
- return await requestIOSPermission();
272
+ try {
273
+ // Get stored permission if available
274
+ const storedPermission = permissionStatusGetter ? permissionStatusGetter() : null;
275
+
276
+ if (storedPermission === 'denied') {
277
+ console.log('Permission previously denied by user');
278
+ return false;
279
+ }
280
+
281
+ let permissionResult = false;
282
+ if (Platform.OS === 'android') {
283
+ permissionResult = await requestAndroidPermission();
284
+ } else if (Platform.OS === 'ios') {
285
+ permissionResult = await requestIOSPermission();
286
+ }
287
+
288
+ // Store the result
289
+ if (permissionStatusSetter) {
290
+ permissionStatusSetter(permissionResult ? 'granted' : 'denied');
291
+ }
292
+
293
+ return permissionResult;
294
+ } catch (error) {
295
+ console.error('Error checking stored permission:', error);
296
+ return false;
252
297
  }
253
-
254
- return false;
255
298
  }
256
299
 
257
300
  async function requestAndroidPermission() {
@@ -267,23 +310,19 @@ async function requestAndroidPermission() {
267
310
  PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
268
311
  {
269
312
  title: 'Microphone Permission',
270
-
271
313
  message: 'This app needs access to your microphone for voice recognition.',
272
-
273
314
  buttonPositive: 'OK',
274
315
  buttonNegative: 'Cancel',
275
316
  }
276
317
  );
277
-
318
+
278
319
  return granted === PermissionsAndroid.RESULTS.GRANTED;
279
320
  } catch (error) {
280
321
  console.error('Error requesting Android permission:', error);
281
-
282
322
  return false;
283
323
  }
284
324
  }
285
325
 
286
-
287
326
  async function requestIOSPermission() {
288
327
  try {
289
328
  // Request microphone permission
@@ -307,6 +346,14 @@ async function requestIOSPermission() {
307
346
  }
308
347
  }
309
348
 
349
+ export function resetStoredPermission() {
350
+ if (permissionStatusSetter) {
351
+ permissionStatusSetter(null);
352
+ return true;
353
+ }
354
+ return false;
355
+ }
356
+
310
357
  export function cleanup() {
311
358
  Voice.destroy().then(() => {
312
359
  Voice.removeAllListeners();