react-native-srschat 0.1.81 → 0.1.85
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/lib/commonjs/components/email.js +4 -8
- package/lib/commonjs/components/email.js.map +1 -1
- package/lib/commonjs/components/productCard.js +91 -86
- package/lib/commonjs/components/productCard.js.map +1 -1
- package/lib/commonjs/components/welcomeButton.js +4 -4
- package/lib/commonjs/components/welcomeButton.js.map +1 -1
- package/lib/commonjs/contexts/AppContext.js +46 -45
- package/lib/commonjs/contexts/AppContext.js.map +1 -1
- package/lib/commonjs/hooks/Stream.js +399 -74
- package/lib/commonjs/hooks/Stream.js.map +1 -1
- package/lib/commonjs/layout/disclaimer.js +36 -32
- package/lib/commonjs/layout/disclaimer.js.map +1 -1
- package/lib/commonjs/layout/welcome.js +8 -7
- package/lib/commonjs/layout/welcome.js.map +1 -1
- package/lib/commonjs/layout/window.js +152 -131
- package/lib/commonjs/layout/window.js.map +1 -1
- package/lib/commonjs/utils/audioRecorder.js.map +1 -1
- package/lib/commonjs/utils/storage.js +1 -1
- package/lib/module/components/email.js +4 -8
- package/lib/module/components/email.js.map +1 -1
- package/lib/module/components/productCard.js +94 -89
- package/lib/module/components/productCard.js.map +1 -1
- package/lib/module/components/welcomeButton.js +4 -4
- package/lib/module/components/welcomeButton.js.map +1 -1
- package/lib/module/contexts/AppContext.js +47 -46
- package/lib/module/contexts/AppContext.js.map +1 -1
- package/lib/module/hooks/Stream.js +400 -75
- package/lib/module/hooks/Stream.js.map +1 -1
- package/lib/module/layout/disclaimer.js +41 -37
- package/lib/module/layout/disclaimer.js.map +1 -1
- package/lib/module/layout/welcome.js +8 -7
- package/lib/module/layout/welcome.js.map +1 -1
- package/lib/module/layout/window.js +152 -131
- package/lib/module/layout/window.js.map +1 -1
- package/lib/module/utils/audioRecorder.js.map +1 -1
- package/lib/module/utils/storage.js +1 -1
- package/lib/typescript/components/email.d.ts.map +1 -1
- package/lib/typescript/components/productCard.d.ts +1 -1
- package/lib/typescript/components/productCard.d.ts.map +1 -1
- package/lib/typescript/components/welcomeButton.d.ts.map +1 -1
- package/lib/typescript/contexts/AppContext.d.ts +2 -2
- package/lib/typescript/contexts/AppContext.d.ts.map +1 -1
- package/lib/typescript/hooks/Stream.d.ts.map +1 -1
- package/lib/typescript/layout/disclaimer.d.ts +1 -1
- package/lib/typescript/layout/disclaimer.d.ts.map +1 -1
- package/lib/typescript/layout/welcome.d.ts.map +1 -1
- package/lib/typescript/layout/window.d.ts.map +1 -1
- package/lib/typescript/utils/audioRecorder.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/components/email.js +3 -15
- package/src/components/productCard.js +279 -203
- package/src/components/welcomeButton.js +10 -10
- package/src/contexts/AppContext.js +185 -106
- package/src/hooks/Stream.js +607 -237
- package/src/layout/disclaimer.js +125 -78
- package/src/layout/welcome.js +58 -20
- package/src/layout/window.js +279 -140
- package/src/utils/audioRecorder.js +40 -34
- package/src/utils/storage.ts +2 -2
|
@@ -48,7 +48,7 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
48
48
|
Voice.removeAllListeners();
|
|
49
49
|
|
|
50
50
|
// Set up all event listeners
|
|
51
|
-
Voice.onSpeechStart =
|
|
51
|
+
Voice.onSpeechStart = e => {
|
|
52
52
|
console.log('onSpeechStart: ', e);
|
|
53
53
|
isCurrentlyRecording = true;
|
|
54
54
|
finalResult = '';
|
|
@@ -57,7 +57,7 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
57
57
|
handleSilenceDetection();
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
Voice.onSpeechRecognized =
|
|
60
|
+
Voice.onSpeechRecognized = e => {
|
|
61
61
|
console.log('onSpeechRecognized: ', e);
|
|
62
62
|
if (e.isFinal) {
|
|
63
63
|
console.log('Speech recognition final');
|
|
@@ -65,9 +65,9 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
Voice.onSpeechEnd = async
|
|
68
|
+
Voice.onSpeechEnd = async e => {
|
|
69
69
|
console.log('onSpeechEnd: ', e);
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
if (silenceTimer) {
|
|
72
72
|
clearTimeout(silenceTimer);
|
|
73
73
|
silenceTimer = null;
|
|
@@ -79,9 +79,9 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
Voice.onSpeechError = async
|
|
82
|
+
Voice.onSpeechError = async e => {
|
|
83
83
|
console.log('onSpeechError: ', e);
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
if (silenceTimer) {
|
|
86
86
|
clearTimeout(silenceTimer);
|
|
87
87
|
silenceTimer = null;
|
|
@@ -89,7 +89,7 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
89
89
|
|
|
90
90
|
const code = e.error?.code?.toString();
|
|
91
91
|
const msg = e.error?.message || '';
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
// Handle Android-specific errors
|
|
94
94
|
if (Platform.OS === 'android' && (code === '7' || code === '5')) {
|
|
95
95
|
if (finalResult && resultCallback) {
|
|
@@ -98,11 +98,11 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
98
98
|
} else if (!msg.includes('No speech detected') && resultCallback) {
|
|
99
99
|
resultCallback(null, msg);
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
await cleanupVoiceSession();
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
Voice.onSpeechResults =
|
|
105
|
+
Voice.onSpeechResults = e => {
|
|
106
106
|
console.log('onSpeechResults: ', e);
|
|
107
107
|
if (e.value && e.value.length > 0) {
|
|
108
108
|
finalResult = e.value[0];
|
|
@@ -110,7 +110,7 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
-
Voice.onSpeechPartialResults =
|
|
113
|
+
Voice.onSpeechPartialResults = e => {
|
|
114
114
|
console.log('onSpeechPartialResults: ', e);
|
|
115
115
|
|
|
116
116
|
if (silenceTimer) {
|
|
@@ -131,7 +131,7 @@ export async function initVoice(onResult, onPartialResult = null) {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
if (Platform.OS === 'android') {
|
|
134
|
-
Voice.onSpeechVolumeChanged =
|
|
134
|
+
Voice.onSpeechVolumeChanged = e => {
|
|
135
135
|
console.log('onSpeechVolumeChanged: ', e);
|
|
136
136
|
};
|
|
137
137
|
}
|
|
@@ -147,7 +147,7 @@ const handleSilenceDetection = () => {
|
|
|
147
147
|
if (silenceTimer) {
|
|
148
148
|
clearTimeout(silenceTimer);
|
|
149
149
|
}
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
silenceTimer = setTimeout(async () => {
|
|
152
152
|
if (isCurrentlyRecording) {
|
|
153
153
|
await handleFinalResult();
|
|
@@ -176,7 +176,7 @@ const handleFinalResult = async () => {
|
|
|
176
176
|
const cleanupVoiceSession = async () => {
|
|
177
177
|
console.log('cleanupVoiceSession called');
|
|
178
178
|
isCurrentlyRecording = false;
|
|
179
|
-
|
|
179
|
+
|
|
180
180
|
if (silenceTimer) {
|
|
181
181
|
clearTimeout(silenceTimer);
|
|
182
182
|
silenceTimer = null;
|
|
@@ -192,7 +192,7 @@ const cleanupVoiceSession = async () => {
|
|
|
192
192
|
// Check if still recognizing
|
|
193
193
|
const isRecognizing = await Voice.isRecognizing();
|
|
194
194
|
console.log('Voice.isRecognizing() in cleanup:', isRecognizing);
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
if (isRecognizing) {
|
|
197
197
|
try {
|
|
198
198
|
// For iOS, use cancel for immediate termination
|
|
@@ -217,7 +217,6 @@ const cleanupVoiceSession = async () => {
|
|
|
217
217
|
} catch (e) {
|
|
218
218
|
console.log('Error destroying in cleanup:', e);
|
|
219
219
|
}
|
|
220
|
-
|
|
221
220
|
} catch (error) {
|
|
222
221
|
console.error('Error in cleanupVoiceSession:', error);
|
|
223
222
|
}
|
|
@@ -270,7 +269,7 @@ export async function startRecording() {
|
|
|
270
269
|
export async function stopRecording() {
|
|
271
270
|
try {
|
|
272
271
|
console.log('stopRecording called');
|
|
273
|
-
|
|
272
|
+
|
|
274
273
|
if (!isCurrentlyRecording || !Voice) {
|
|
275
274
|
console.log('Not recording or Voice not available');
|
|
276
275
|
return;
|
|
@@ -335,25 +334,27 @@ export async function cancelRecording() {
|
|
|
335
334
|
export async function requestAudioPermission() {
|
|
336
335
|
try {
|
|
337
336
|
// Get stored permission if available
|
|
338
|
-
const storedPermission = permissionStatusGetter
|
|
339
|
-
|
|
337
|
+
const storedPermission = permissionStatusGetter
|
|
338
|
+
? permissionStatusGetter()
|
|
339
|
+
: null;
|
|
340
|
+
|
|
340
341
|
if (storedPermission === 'denied') {
|
|
341
342
|
console.log('Permission previously denied by user');
|
|
342
343
|
return false;
|
|
343
344
|
}
|
|
344
|
-
|
|
345
|
+
|
|
345
346
|
let permissionResult = false;
|
|
346
347
|
if (Platform.OS === 'android') {
|
|
347
348
|
permissionResult = await requestAndroidPermission();
|
|
348
349
|
} else if (Platform.OS === 'ios') {
|
|
349
350
|
permissionResult = await requestIOSPermission();
|
|
350
351
|
}
|
|
351
|
-
|
|
352
|
+
|
|
352
353
|
// Store the result
|
|
353
354
|
if (permissionStatusSetter) {
|
|
354
355
|
permissionStatusSetter(permissionResult ? 'granted' : 'denied');
|
|
355
356
|
}
|
|
356
|
-
|
|
357
|
+
|
|
357
358
|
return permissionResult;
|
|
358
359
|
} catch (error) {
|
|
359
360
|
console.error('Error checking stored permission:', error);
|
|
@@ -381,7 +382,7 @@ async function requestAndroidPermission() {
|
|
|
381
382
|
console.log('Error checking speech services:', e);
|
|
382
383
|
// Continue anyway - some devices report error but work fine
|
|
383
384
|
}
|
|
384
|
-
|
|
385
|
+
|
|
385
386
|
return true;
|
|
386
387
|
} catch (error) {
|
|
387
388
|
console.error('Error requesting Android permission:', error);
|
|
@@ -425,15 +426,20 @@ export function cleanup() {
|
|
|
425
426
|
console.log('Voice module not available during cleanup');
|
|
426
427
|
return;
|
|
427
428
|
}
|
|
428
|
-
|
|
429
|
-
Voice.destroy()
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
429
|
+
|
|
430
|
+
Voice.destroy()
|
|
431
|
+
.then(() => {
|
|
432
|
+
Voice.removeAllListeners();
|
|
433
|
+
cleanupVoiceSession();
|
|
434
|
+
})
|
|
435
|
+
.catch(error => {
|
|
436
|
+
console.error('Error in cleanup:', error);
|
|
437
|
+
// Try one more time
|
|
438
|
+
if (Voice) {
|
|
439
|
+
Voice.destroy().catch(e =>
|
|
440
|
+
console.error('Final cleanup attempt failed:', e),
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
package/src/utils/storage.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const defaultState: ChatState = {
|
|
|
33
33
|
startStreaming: false,
|
|
34
34
|
messages: [{
|
|
35
35
|
type: "ai",
|
|
36
|
-
text: "Hi there 👋 Hi there 👋 I'm your Heritage
|
|
36
|
+
text: "Hi there 👋 Hi there 👋 I'm your Heritage+ AI Assistant. I'm here to help you with Product and Account information during your online visit. I'm still learning and growing - the more we interact and the more feedback you share, the better I can assist you. How can I help you today?"
|
|
37
37
|
}],
|
|
38
38
|
showIcon: true,
|
|
39
39
|
toggleChat: false,
|
|
@@ -86,4 +86,4 @@ export const updateChat = async (token: string, next: ChatState): Promise<void>
|
|
|
86
86
|
} catch (error) {
|
|
87
87
|
console.error('Error updating chat state:', error);
|
|
88
88
|
}
|
|
89
|
-
};
|
|
89
|
+
};
|