@revrag-ai/embed-react-native 1.0.5 → 1.0.7
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/LICENSE +1 -1
- package/README.md +13 -382
- package/android/CMakeLists.txt +15 -0
- package/android/build.gradle +77 -25
- package/android/cpp-adapter.cpp +8 -0
- package/android/generated/java/com/revragai/embedreactnative/NativeEmbedReactNativeSpec.java +37 -0
- package/android/generated/jni/CMakeLists.txt +49 -0
- package/android/generated/jni/RNEmbedReactNativeSpec-generated.cpp +32 -0
- package/android/generated/jni/RNEmbedReactNativeSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
- package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI.h +67 -0
- package/android/gradle.properties +5 -5
- package/cpp/revrag-ai-embed-react-native.cpp +7 -0
- package/cpp/revrag-ai-embed-react-native.h +8 -0
- package/ios/EmbedReactNative.h +9 -0
- package/ios/{Onwid.mm → EmbedReactNative.mm} +4 -4
- package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec-generated.mm +29 -0
- package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec.h +50 -0
- package/ios/generated/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
- package/ios/generated/RNEmbedReactNativeSpecJSI.h +67 -0
- package/lib/commonjs/NativeEmbedReactNative.js +9 -0
- package/lib/commonjs/api/api.js +256 -0
- package/lib/commonjs/api/types/embed.api.types.js +2 -0
- package/lib/commonjs/components/Embed/EmbedAudioWave.js +157 -0
- package/lib/commonjs/components/Embed/EmbedButton.js +511 -0
- package/lib/commonjs/components/Embed/EmbedVoice.js +131 -0
- package/lib/commonjs/components/styles/EmbedButton.style.js +248 -0
- package/lib/commonjs/events/embed.event.js +74 -0
- package/lib/commonjs/hooks/initialize.js +102 -0
- package/lib/commonjs/hooks/initialize.livekit.js +20 -0
- package/lib/commonjs/hooks/types/initialize.types.js +2 -0
- package/lib/commonjs/hooks/types/voiceAgent.types.js +6 -0
- package/lib/commonjs/hooks/voiceagent.js +358 -0
- package/lib/commonjs/index.js +34 -0
- package/lib/commonjs/index.types.js +22 -0
- package/lib/commonjs/store/store.key.js +46 -0
- package/lib/commonjs/utils/reanimated.helper.js +100 -0
- package/lib/module/NativeEmbedReactNative.js +5 -0
- package/lib/module/api/api.js +248 -0
- package/lib/module/api/types/embed.api.types.js +2 -0
- package/lib/module/components/Embed/EmbedAudioWave.js +152 -0
- package/lib/module/components/Embed/EmbedButton.js +506 -0
- package/lib/module/components/Embed/EmbedVoice.js +127 -0
- package/lib/module/components/styles/EmbedButton.style.js +243 -0
- package/lib/module/events/embed.event.js +70 -0
- package/lib/module/hooks/initialize.js +79 -75
- package/lib/module/hooks/{initializelivekit.js → initialize.livekit.js} +7 -4
- package/lib/module/hooks/types/initialize.types.js +2 -0
- package/lib/module/hooks/types/voiceAgent.types.js +4 -0
- package/lib/module/hooks/voiceagent.js +353 -0
- package/lib/module/index.js +6 -60
- package/lib/module/index.types.js +23 -0
- package/lib/module/store/store.key.js +38 -0
- package/lib/module/utils/reanimated.helper.js +94 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/package.json +69 -27
- package/react-native.config.js +8 -14
- package/revrag-ai-embed-react-native.podspec +41 -0
- package/Onwid.podspec +0 -20
- package/ios/Onwid.h +0 -5
- package/lib/index.d.ts +0 -77
- package/lib/module/Event/onwid.js +0 -74
- package/lib/module/NativeOnwid.js +0 -4
- package/lib/module/component/OnwidButton.js +0 -366
- package/lib/module/component/audiowave.js +0 -137
- package/lib/module/component/voice.js +0 -103
- package/lib/module/hooks/initialize.types.js +0 -2
- package/lib/module/hooks/voiceAgent.js +0 -334
- package/lib/module/hooks/voiceAgent.types.js +0 -2
- package/lib/module/onwidApi/api.js +0 -184
- package/lib/module/onwidApi/api.types.js +0 -2
- package/lib/module/store.key.js +0 -47
- package/lib/module/style/onwidButton.style.js +0 -230
- package/lib/module/utils/reanimatedHelpers.js +0 -87
- package/lib/module/utils/utils.js +0 -1
- package/lib/typescript/Event/onwid.d.ts +0 -13
- package/lib/typescript/NativeOnwid.d.ts +0 -6
- package/lib/typescript/component/OnwidButton.d.ts +0 -28
- package/lib/typescript/component/audiowave.d.ts +0 -6
- package/lib/typescript/component/voice.d.ts +0 -15
- package/lib/typescript/hooks/initialize.d.ts +0 -2
- package/lib/typescript/hooks/initialize.types.d.ts +0 -5
- package/lib/typescript/hooks/initializelivekit.d.ts +0 -3
- package/lib/typescript/hooks/voiceAgent.d.ts +0 -2
- package/lib/typescript/hooks/voiceAgent.types.d.ts +0 -16
- package/lib/typescript/index.d.ts +0 -27
- package/lib/typescript/onwidApi/api.d.ts +0 -53
- package/lib/typescript/onwidApi/api.types.d.ts +0 -21
- package/lib/typescript/store.key.d.ts +0 -3
- package/lib/typescript/style/onwidButton.style.d.ts +0 -98
- package/lib/typescript/utils/reanimatedHelpers.d.ts +0 -29
- package/lib/typescript/utils/utils.d.ts +0 -0
- package/scripts/verify-setup.js +0 -90
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ConnectionState, Room } from 'livekit-client';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { EventKeys } from "../events/embed.event.js";
|
|
6
|
+
import { APIService } from "../api/api.js";
|
|
7
|
+
import { getAgentData } from "../store/store.key.js";
|
|
8
|
+
// Create a singleton instance of Room that persists across hook instances
|
|
9
|
+
// This ensures we don't create multiple Room instances that could conflict
|
|
10
|
+
let roomInstance = null;
|
|
11
|
+
let isConnecting = false;
|
|
12
|
+
let isDisconnecting = false;
|
|
13
|
+
let hasListeners = false;
|
|
14
|
+
let connectionAttempts = 0;
|
|
15
|
+
let stableConnectionTimerId = null;
|
|
16
|
+
const MAX_CONNECTION_ATTEMPTS = 3;
|
|
17
|
+
const STABLE_CONNECTION_TIMEOUT = 5000; // 5 seconds
|
|
18
|
+
|
|
19
|
+
// Create getters for the room instance
|
|
20
|
+
const getRoomInstance = () => {
|
|
21
|
+
if (!roomInstance) {
|
|
22
|
+
console.log('Creating new Room instance');
|
|
23
|
+
// Configure the room with the right options at creation time
|
|
24
|
+
roomInstance = new Room({
|
|
25
|
+
adaptiveStream: true,
|
|
26
|
+
dynacast: true,
|
|
27
|
+
// Using the most stable configuration for React Native
|
|
28
|
+
publishDefaults: {
|
|
29
|
+
simulcast: false // Disable simulcast to reduce SDP complexity
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return roomInstance;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Reset connection attempt counter
|
|
37
|
+
const resetConnectionAttempts = () => {
|
|
38
|
+
connectionAttempts = 0;
|
|
39
|
+
|
|
40
|
+
// Clear any pending stable connection timer
|
|
41
|
+
if (stableConnectionTimerId) {
|
|
42
|
+
clearTimeout(stableConnectionTimerId);
|
|
43
|
+
stableConnectionTimerId = null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Cleanup function to reset the room state
|
|
48
|
+
const resetRoomState = () => {
|
|
49
|
+
if (roomInstance) {
|
|
50
|
+
try {
|
|
51
|
+
console.log('Resetting room state');
|
|
52
|
+
console.log('isDisconnecting', isDisconnecting);
|
|
53
|
+
|
|
54
|
+
// Only disconnect if currently connected
|
|
55
|
+
if (roomInstance.state !== ConnectionState.Disconnected && !isDisconnecting) {
|
|
56
|
+
isDisconnecting = true;
|
|
57
|
+
roomInstance.disconnect().finally(() => {
|
|
58
|
+
isDisconnecting = false;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Don't destroy the room instance, just reset its state
|
|
63
|
+
hasListeners = false;
|
|
64
|
+
resetConnectionAttempts();
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error('Error resetting room state:', e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
export const useVoiceAgent = () => {
|
|
71
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
72
|
+
const [error, setError] = useState(null);
|
|
73
|
+
const [tokenDetails, setTokenDetails] = useState(null);
|
|
74
|
+
const [isMicMuted, setIsMicMuted] = useState(false);
|
|
75
|
+
const [connectionState, setConnectionState] = useState(() => {
|
|
76
|
+
// Initialize with the current room state if it exists
|
|
77
|
+
const room = getRoomInstance();
|
|
78
|
+
return room ? room.state : ConnectionState.Disconnected;
|
|
79
|
+
});
|
|
80
|
+
const [stableConnection, setStableConnection] = useState(false);
|
|
81
|
+
console.log('ConnectionState_connected', connectionState
|
|
82
|
+
// tokenDetails?.token
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Setup event listeners for the room
|
|
86
|
+
const setupRoomListeners = () => {
|
|
87
|
+
if (hasListeners || !roomInstance) return;
|
|
88
|
+
console.log('Setting up room listeners');
|
|
89
|
+
const handleConnectionChange = state => {
|
|
90
|
+
console.log('Connection state changed:', state);
|
|
91
|
+
// Use a function to ensure we're setting with the latest state
|
|
92
|
+
setConnectionState(() => state);
|
|
93
|
+
|
|
94
|
+
// Handle connection state changes
|
|
95
|
+
if (state === ConnectionState.Connected) {
|
|
96
|
+
// Reset connection attempts when connected successfully
|
|
97
|
+
resetConnectionAttempts();
|
|
98
|
+
|
|
99
|
+
// Set up a timer to mark the connection as stable after a few seconds
|
|
100
|
+
// This prevents immediate disconnections from being treated as stable
|
|
101
|
+
if (stableConnectionTimerId) {
|
|
102
|
+
clearTimeout(stableConnectionTimerId);
|
|
103
|
+
}
|
|
104
|
+
stableConnectionTimerId = setTimeout(() => {
|
|
105
|
+
console.log('Connection marked as stable');
|
|
106
|
+
setStableConnection(true);
|
|
107
|
+
}, STABLE_CONNECTION_TIMEOUT);
|
|
108
|
+
} else if (state === ConnectionState.Disconnected) {
|
|
109
|
+
// Mark connection as unstable
|
|
110
|
+
setStableConnection(false);
|
|
111
|
+
|
|
112
|
+
// Clear any pending stable connection timer
|
|
113
|
+
if (stableConnectionTimerId) {
|
|
114
|
+
clearTimeout(stableConnectionTimerId);
|
|
115
|
+
stableConnectionTimerId = null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// If disconnected unexpectedly and we have token details, don't automatically reconnect
|
|
119
|
+
// This prevents connection loops
|
|
120
|
+
if (tokenDetails && !isDisconnecting) {
|
|
121
|
+
console.log('Room disconnected unexpectedly - not auto-reconnecting');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const handleTrackSubscribed = track => {
|
|
126
|
+
if (track.kind === 'audio') {
|
|
127
|
+
track.setVolume(1.0);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Handle participant disconnected - this could be helpful to detect server-side kicks
|
|
132
|
+
roomInstance.on('participantDisconnected', () => {
|
|
133
|
+
console.log('Participant disconnected from room');
|
|
134
|
+
});
|
|
135
|
+
roomInstance.on('connectionStateChanged', handleConnectionChange);
|
|
136
|
+
roomInstance.on('trackSubscribed', handleTrackSubscribed);
|
|
137
|
+
|
|
138
|
+
// Listen for SDP negotiation errors to handle them better
|
|
139
|
+
roomInstance.on('mediaDevicesError', e => {
|
|
140
|
+
console.log('Media devices error:', e.message);
|
|
141
|
+
});
|
|
142
|
+
hasListeners = true;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Initialize room and listeners
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
const room = getRoomInstance();
|
|
148
|
+
setupRoomListeners();
|
|
149
|
+
|
|
150
|
+
// Sync local state with room state
|
|
151
|
+
setConnectionState(room.state);
|
|
152
|
+
return () => {
|
|
153
|
+
// Do NOT disconnect or destroy the room on component unmount
|
|
154
|
+
// This ensures the singleton persists across component lifecycle
|
|
155
|
+
// But we do want to update local state if the component is unmounted
|
|
156
|
+
if (!tokenDetails) {
|
|
157
|
+
setTokenDetails(null);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}, []);
|
|
161
|
+
|
|
162
|
+
// Connect to LiveKit when token is set
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
const room = getRoomInstance();
|
|
165
|
+
if (!tokenDetails || isConnecting) return;
|
|
166
|
+
|
|
167
|
+
// Always sync our state with the room's current state
|
|
168
|
+
setConnectionState(room.state);
|
|
169
|
+
const connectToRoom = async () => {
|
|
170
|
+
// Prevent multiple connection attempts
|
|
171
|
+
if (isConnecting) return;
|
|
172
|
+
|
|
173
|
+
// Limit connection attempts to prevent infinite loops
|
|
174
|
+
if (connectionAttempts >= MAX_CONNECTION_ATTEMPTS) {
|
|
175
|
+
console.log(`Maximum connection attempts (${MAX_CONNECTION_ATTEMPTS}) reached. Not trying again.`);
|
|
176
|
+
setError(`Failed to connect after ${MAX_CONNECTION_ATTEMPTS} attempts`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
connectionAttempts++;
|
|
180
|
+
try {
|
|
181
|
+
isConnecting = true;
|
|
182
|
+
console.log(`Connecting to LiveKit room... (attempt ${connectionAttempts})`);
|
|
183
|
+
|
|
184
|
+
// Only attempt to connect if we're disconnected
|
|
185
|
+
if (room.state === ConnectionState.Disconnected) {
|
|
186
|
+
// Update state before connection attempt
|
|
187
|
+
setConnectionState(ConnectionState.Connecting);
|
|
188
|
+
await room.connect(tokenDetails.server_url, tokenDetails.token, {
|
|
189
|
+
autoSubscribe: true // Ensure we subscribe to tracks automatically
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Explicitly set to connected if connection was successful
|
|
193
|
+
setConnectionState(room.state);
|
|
194
|
+
console.log('Connected to LiveKit room');
|
|
195
|
+
} else if (room.state === ConnectionState.Connected) {
|
|
196
|
+
console.log('Room is already connected');
|
|
197
|
+
// Ensure our state matches
|
|
198
|
+
setConnectionState(ConnectionState.Connected);
|
|
199
|
+
} else {
|
|
200
|
+
console.log('Room is in transition state:', room.state);
|
|
201
|
+
// Sync our state with the room's current state
|
|
202
|
+
setConnectionState(room.state);
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
const message = err instanceof Error ? err.message : 'Failed to connect to room';
|
|
206
|
+
setError(message);
|
|
207
|
+
console.error('Connection error:', message);
|
|
208
|
+
|
|
209
|
+
// Sync state to disconnected if we failed to connect
|
|
210
|
+
setConnectionState(room.state);
|
|
211
|
+
|
|
212
|
+
// Don't keep retrying if we hit an SDP error
|
|
213
|
+
if (message.includes('SDP') || message.includes('sdp')) {
|
|
214
|
+
console.log('SDP error detected, will not retry automatically');
|
|
215
|
+
}
|
|
216
|
+
} finally {
|
|
217
|
+
isConnecting = false;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
connectToRoom();
|
|
221
|
+
|
|
222
|
+
// No cleanup here - we don't want to disconnect when token changes or component unmounts
|
|
223
|
+
}, [tokenDetails]);
|
|
224
|
+
|
|
225
|
+
// Log connection status periodically for debugging
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
const debugInterval = setInterval(() => {
|
|
228
|
+
if (roomInstance) {
|
|
229
|
+
const state = roomInstance.state;
|
|
230
|
+
const participantCount = roomInstance.numParticipants;
|
|
231
|
+
console.log(`[DEBUG] Room state: ${state}, Participants: ${participantCount}, Stable: ${stableConnection}`);
|
|
232
|
+
}
|
|
233
|
+
}, 10000); // Every 10 seconds
|
|
234
|
+
|
|
235
|
+
return () => clearInterval(debugInterval);
|
|
236
|
+
}, [stableConnection]);
|
|
237
|
+
|
|
238
|
+
// Generate token and connect
|
|
239
|
+
const generateVoiceToken = async () => {
|
|
240
|
+
console.log('generateVoiceToken');
|
|
241
|
+
|
|
242
|
+
// Don't generate a new token if we're already connecting/connected
|
|
243
|
+
if (isConnecting || isLoading) {
|
|
244
|
+
console.log('Already connecting or loading, skipping token generation');
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Reset connection attempts when starting fresh
|
|
249
|
+
resetConnectionAttempts();
|
|
250
|
+
setStableConnection(false);
|
|
251
|
+
const userData = await getAgentData(EventKeys.USER_DATA);
|
|
252
|
+
setIsLoading(true);
|
|
253
|
+
setError(null);
|
|
254
|
+
console.log('userData', userData);
|
|
255
|
+
try {
|
|
256
|
+
const apiService = APIService.getInstance();
|
|
257
|
+
const response = await apiService.getTokenDetails({
|
|
258
|
+
app_user_id: userData?.app_user_id,
|
|
259
|
+
call_type: 'EMBEDDED'
|
|
260
|
+
});
|
|
261
|
+
if (!response.data) throw new Error('No voice token found');
|
|
262
|
+
|
|
263
|
+
// Only set token details if we're not already connected
|
|
264
|
+
const room = getRoomInstance();
|
|
265
|
+
if (room.state !== ConnectionState.Connected) {
|
|
266
|
+
setTokenDetails(response.data);
|
|
267
|
+
} else {
|
|
268
|
+
console.log('Room already connected, skipping token update');
|
|
269
|
+
}
|
|
270
|
+
} catch (err) {
|
|
271
|
+
const message = err instanceof Error ? err.message : 'Failed to generate voice token';
|
|
272
|
+
setError(message);
|
|
273
|
+
throw new Error(message);
|
|
274
|
+
} finally {
|
|
275
|
+
setIsLoading(false);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// End call
|
|
280
|
+
const endCall = async () => {
|
|
281
|
+
if (isDisconnecting) {
|
|
282
|
+
console.log('Already disconnecting, skipping');
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
console.log('Ending call');
|
|
287
|
+
isDisconnecting = true;
|
|
288
|
+
setTokenDetails(null);
|
|
289
|
+
setIsMicMuted(false);
|
|
290
|
+
resetConnectionAttempts();
|
|
291
|
+
setStableConnection(false);
|
|
292
|
+
const room = getRoomInstance();
|
|
293
|
+
if (room.state !== ConnectionState.Disconnected) {
|
|
294
|
+
// Update state before disconnection
|
|
295
|
+
setConnectionState(ConnectionState.Connecting);
|
|
296
|
+
await room.disconnect();
|
|
297
|
+
|
|
298
|
+
// Update state after disconnection
|
|
299
|
+
setConnectionState(ConnectionState.Disconnected);
|
|
300
|
+
}
|
|
301
|
+
} catch (err) {
|
|
302
|
+
setError(err instanceof Error ? err.message : 'Failed to end call');
|
|
303
|
+
// Make sure state is correctly reflected even if there's an error
|
|
304
|
+
const room = getRoomInstance();
|
|
305
|
+
setConnectionState(room.state);
|
|
306
|
+
} finally {
|
|
307
|
+
isDisconnecting = false;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// Mute microphone
|
|
312
|
+
const muteMic = () => {
|
|
313
|
+
const room = getRoomInstance();
|
|
314
|
+
if (room.localParticipant) {
|
|
315
|
+
room.localParticipant.setMicrophoneEnabled(false);
|
|
316
|
+
setIsMicMuted(true);
|
|
317
|
+
console.log('Microphone muted');
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// Unmute microphone
|
|
322
|
+
const unmuteMic = () => {
|
|
323
|
+
const room = getRoomInstance();
|
|
324
|
+
if (room.localParticipant) {
|
|
325
|
+
room.localParticipant.setMicrophoneEnabled(true);
|
|
326
|
+
setIsMicMuted(false);
|
|
327
|
+
console.log('Microphone unmuted');
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// Clean up everything (use only when the app is shutting down)
|
|
332
|
+
const cleanup = () => {
|
|
333
|
+
endCall();
|
|
334
|
+
resetRoomState();
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
initializeVoiceAgent: generateVoiceToken,
|
|
338
|
+
endCall,
|
|
339
|
+
muteMic,
|
|
340
|
+
unmuteMic,
|
|
341
|
+
isMicMuted,
|
|
342
|
+
connectionState,
|
|
343
|
+
room: getRoomInstance(),
|
|
344
|
+
tokenDetails,
|
|
345
|
+
isLoading,
|
|
346
|
+
error,
|
|
347
|
+
roomRef: {
|
|
348
|
+
current: getRoomInstance()
|
|
349
|
+
},
|
|
350
|
+
cleanup
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
//# sourceMappingURL=voiceagent.js.map
|
package/lib/module/index.js
CHANGED
|
@@ -1,61 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.useInitialize = exports.registerAgent = exports.onwid = exports.EventKeys = void 0;
|
|
40
|
-
exports.OnwidButton = OnwidButton;
|
|
41
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
42
|
-
/**
|
|
43
|
-
* @file index.tsx
|
|
44
|
-
* @description Main entry point for the Onwid React Native library.
|
|
45
|
-
* This file exports the core components and utilities for the Onwid SDK.
|
|
46
|
-
*/
|
|
47
|
-
const OnwidButton_1 = require("./component/OnwidButton");
|
|
48
|
-
const onwid_1 = __importStar(require("./Event/onwid"));
|
|
49
|
-
exports.onwid = onwid_1.default;
|
|
50
|
-
Object.defineProperty(exports, "EventKeys", { enumerable: true, get: function () { return onwid_1.EventKeys; } });
|
|
51
|
-
const initialize_1 = require("./hooks/initialize");
|
|
52
|
-
Object.defineProperty(exports, "useInitialize", { enumerable: true, get: function () { return initialize_1.useInitialize; } });
|
|
53
|
-
const initializelivekit_1 = __importDefault(require("./hooks/initializelivekit"));
|
|
54
|
-
exports.registerAgent = initializelivekit_1.default;
|
|
55
|
-
/**
|
|
56
|
-
* OnwidButton component that provides a customizable button with menu functionality
|
|
57
|
-
* @returns React component
|
|
58
|
-
*/
|
|
59
|
-
function OnwidButton() {
|
|
60
|
-
return (0, jsx_runtime_1.jsx)(OnwidButton_1.OnwidButton, {});
|
|
61
|
-
}
|
|
2
|
+
|
|
3
|
+
import { EmbedButton } from "./components/Embed/EmbedButton.js";
|
|
4
|
+
import { useInitialize } from "./hooks/initialize.js";
|
|
5
|
+
import Embed, { EventKeys } from "./events/embed.event.js";
|
|
6
|
+
export { EmbedButton, useInitialize, Embed, EventKeys as EmbedEventKeys };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* @file index.d.ts
|
|
6
|
+
* @description TypeScript declarations for the Onwid React Native library.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Component declarations
|
|
10
|
+
|
|
11
|
+
// Hook type declarations
|
|
12
|
+
|
|
13
|
+
// Hook declarations
|
|
14
|
+
|
|
15
|
+
// API type declarations
|
|
16
|
+
|
|
17
|
+
// Event system declarations
|
|
18
|
+
export let EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
19
|
+
EventKeys["USER_DATA"] = "user_data";
|
|
20
|
+
EventKeys["SCREEN_STATE"] = "state_data";
|
|
21
|
+
return EventKeys;
|
|
22
|
+
}({});
|
|
23
|
+
//# sourceMappingURL=index.types.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
const STORAGE_KEY = '@user_data';
|
|
5
|
+
export const setAgentData = async (data, key = STORAGE_KEY) => {
|
|
6
|
+
try {
|
|
7
|
+
const jsonString = JSON.stringify(data);
|
|
8
|
+
await AsyncStorage.setItem(key, jsonString);
|
|
9
|
+
console.log('Data saved to storage successfully');
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error('Storage save error:', error);
|
|
12
|
+
throw error; // Re-throw to allow caller to handle
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const getAgentData = async (key = STORAGE_KEY) => {
|
|
16
|
+
try {
|
|
17
|
+
const jsonString = await AsyncStorage.getItem(key);
|
|
18
|
+
if (!jsonString) {
|
|
19
|
+
console.log('No data stored');
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const data = JSON.parse(jsonString);
|
|
23
|
+
return data;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Storage fetch error:', error);
|
|
26
|
+
throw error; // Re-throw to allow caller to handle
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export const deleteFromDetail = async key => {
|
|
30
|
+
try {
|
|
31
|
+
await AsyncStorage.removeItem(key);
|
|
32
|
+
console.log('Storage data reset successfully');
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Storage reset error:', error);
|
|
35
|
+
throw error; // Re-throw to allow caller to handle
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=store.key.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file reanimatedHelpers.ts
|
|
5
|
+
* @description Utility functions to handle react-native-reanimated configuration and provide fallbacks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
let reanimatedAPI;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Safely loads react-native-reanimated and provides fallbacks if not available
|
|
12
|
+
*/
|
|
13
|
+
export function getReanimatedAPI() {
|
|
14
|
+
if (reanimatedAPI) {
|
|
15
|
+
return reanimatedAPI;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const reanimated = require('react-native-reanimated');
|
|
19
|
+
|
|
20
|
+
// Check if makeMutable is available (this is what was causing the original error)
|
|
21
|
+
if (!reanimated.makeMutable) {
|
|
22
|
+
throw new Error('makeMutable not found - react-native-reanimated may not be properly configured');
|
|
23
|
+
}
|
|
24
|
+
reanimatedAPI = {
|
|
25
|
+
useSharedValue: reanimated.useSharedValue,
|
|
26
|
+
useAnimatedStyle: reanimated.useAnimatedStyle,
|
|
27
|
+
withTiming: reanimated.withTiming,
|
|
28
|
+
withSpring: reanimated.withSpring,
|
|
29
|
+
withRepeat: reanimated.withRepeat,
|
|
30
|
+
withSequence: reanimated.withSequence,
|
|
31
|
+
runOnJS: reanimated.runOnJS,
|
|
32
|
+
Easing: reanimated.Easing,
|
|
33
|
+
Animated: reanimated.default,
|
|
34
|
+
isAvailable: true
|
|
35
|
+
};
|
|
36
|
+
console.log('✅ react-native-reanimated loaded successfully');
|
|
37
|
+
return reanimatedAPI;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.warn('⚠️ react-native-reanimated is not properly installed or configured:', error);
|
|
40
|
+
console.warn('📚 Please follow the setup guide: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started');
|
|
41
|
+
|
|
42
|
+
// Provide fallback implementations
|
|
43
|
+
const {
|
|
44
|
+
View
|
|
45
|
+
} = require('react-native');
|
|
46
|
+
reanimatedAPI = {
|
|
47
|
+
useSharedValue: value => ({
|
|
48
|
+
value
|
|
49
|
+
}),
|
|
50
|
+
useAnimatedStyle: () => ({}),
|
|
51
|
+
withTiming: value => value,
|
|
52
|
+
withSpring: value => value,
|
|
53
|
+
withRepeat: value => value,
|
|
54
|
+
withSequence: (...args) => args[args.length - 1],
|
|
55
|
+
runOnJS: fn => fn,
|
|
56
|
+
Easing: {
|
|
57
|
+
inOut: easing => easing,
|
|
58
|
+
ease: t => t
|
|
59
|
+
},
|
|
60
|
+
Animated: View,
|
|
61
|
+
isAvailable: false
|
|
62
|
+
};
|
|
63
|
+
return reanimatedAPI;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if react-native-reanimated is properly configured
|
|
69
|
+
*/
|
|
70
|
+
export function checkReanimatedSetup() {
|
|
71
|
+
const api = getReanimatedAPI();
|
|
72
|
+
return api.isAvailable;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Display a helpful error message if reanimated is not configured
|
|
77
|
+
*/
|
|
78
|
+
export function showReanimatedSetupError() {
|
|
79
|
+
console.error(`
|
|
80
|
+
🚨 React Native Reanimated Setup Required
|
|
81
|
+
|
|
82
|
+
The OnwidButton component requires react-native-reanimated to be properly installed and configured.
|
|
83
|
+
|
|
84
|
+
Quick Fix:
|
|
85
|
+
1. Install: npm install react-native-reanimated
|
|
86
|
+
2. Add to babel.config.js:
|
|
87
|
+
plugins: ['react-native-reanimated/plugin']
|
|
88
|
+
3. Rebuild your app
|
|
89
|
+
|
|
90
|
+
For detailed setup instructions, visit:
|
|
91
|
+
https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=reanimated.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|