@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.
Files changed (94) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +13 -382
  3. package/android/CMakeLists.txt +15 -0
  4. package/android/build.gradle +77 -25
  5. package/android/cpp-adapter.cpp +8 -0
  6. package/android/generated/java/com/revragai/embedreactnative/NativeEmbedReactNativeSpec.java +37 -0
  7. package/android/generated/jni/CMakeLists.txt +49 -0
  8. package/android/generated/jni/RNEmbedReactNativeSpec-generated.cpp +32 -0
  9. package/android/generated/jni/RNEmbedReactNativeSpec.h +31 -0
  10. package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
  11. package/android/generated/jni/react/renderer/components/RNEmbedReactNativeSpec/RNEmbedReactNativeSpecJSI.h +67 -0
  12. package/android/gradle.properties +5 -5
  13. package/cpp/revrag-ai-embed-react-native.cpp +7 -0
  14. package/cpp/revrag-ai-embed-react-native.h +8 -0
  15. package/ios/EmbedReactNative.h +9 -0
  16. package/ios/{Onwid.mm → EmbedReactNative.mm} +4 -4
  17. package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec-generated.mm +29 -0
  18. package/ios/generated/RNEmbedReactNativeSpec/RNEmbedReactNativeSpec.h +50 -0
  19. package/ios/generated/RNEmbedReactNativeSpecJSI-generated.cpp +28 -0
  20. package/ios/generated/RNEmbedReactNativeSpecJSI.h +67 -0
  21. package/lib/commonjs/NativeEmbedReactNative.js +9 -0
  22. package/lib/commonjs/api/api.js +256 -0
  23. package/lib/commonjs/api/types/embed.api.types.js +2 -0
  24. package/lib/commonjs/components/Embed/EmbedAudioWave.js +157 -0
  25. package/lib/commonjs/components/Embed/EmbedButton.js +511 -0
  26. package/lib/commonjs/components/Embed/EmbedVoice.js +131 -0
  27. package/lib/commonjs/components/styles/EmbedButton.style.js +248 -0
  28. package/lib/commonjs/events/embed.event.js +74 -0
  29. package/lib/commonjs/hooks/initialize.js +102 -0
  30. package/lib/commonjs/hooks/initialize.livekit.js +20 -0
  31. package/lib/commonjs/hooks/types/initialize.types.js +2 -0
  32. package/lib/commonjs/hooks/types/voiceAgent.types.js +6 -0
  33. package/lib/commonjs/hooks/voiceagent.js +358 -0
  34. package/lib/commonjs/index.js +34 -0
  35. package/lib/commonjs/index.types.js +22 -0
  36. package/lib/commonjs/store/store.key.js +46 -0
  37. package/lib/commonjs/utils/reanimated.helper.js +100 -0
  38. package/lib/module/NativeEmbedReactNative.js +5 -0
  39. package/lib/module/api/api.js +248 -0
  40. package/lib/module/api/types/embed.api.types.js +2 -0
  41. package/lib/module/components/Embed/EmbedAudioWave.js +152 -0
  42. package/lib/module/components/Embed/EmbedButton.js +506 -0
  43. package/lib/module/components/Embed/EmbedVoice.js +127 -0
  44. package/lib/module/components/styles/EmbedButton.style.js +243 -0
  45. package/lib/module/events/embed.event.js +70 -0
  46. package/lib/module/hooks/initialize.js +79 -75
  47. package/lib/module/hooks/{initializelivekit.js → initialize.livekit.js} +7 -4
  48. package/lib/module/hooks/types/initialize.types.js +2 -0
  49. package/lib/module/hooks/types/voiceAgent.types.js +4 -0
  50. package/lib/module/hooks/voiceagent.js +353 -0
  51. package/lib/module/index.js +6 -60
  52. package/lib/module/index.types.js +23 -0
  53. package/lib/module/store/store.key.js +38 -0
  54. package/lib/module/utils/reanimated.helper.js +94 -0
  55. package/lib/typescript/commonjs/package.json +1 -0
  56. package/lib/typescript/module/package.json +1 -0
  57. package/package.json +69 -27
  58. package/react-native.config.js +8 -14
  59. package/revrag-ai-embed-react-native.podspec +41 -0
  60. package/Onwid.podspec +0 -20
  61. package/ios/Onwid.h +0 -5
  62. package/lib/index.d.ts +0 -77
  63. package/lib/module/Event/onwid.js +0 -74
  64. package/lib/module/NativeOnwid.js +0 -4
  65. package/lib/module/component/OnwidButton.js +0 -366
  66. package/lib/module/component/audiowave.js +0 -137
  67. package/lib/module/component/voice.js +0 -103
  68. package/lib/module/hooks/initialize.types.js +0 -2
  69. package/lib/module/hooks/voiceAgent.js +0 -334
  70. package/lib/module/hooks/voiceAgent.types.js +0 -2
  71. package/lib/module/onwidApi/api.js +0 -184
  72. package/lib/module/onwidApi/api.types.js +0 -2
  73. package/lib/module/store.key.js +0 -47
  74. package/lib/module/style/onwidButton.style.js +0 -230
  75. package/lib/module/utils/reanimatedHelpers.js +0 -87
  76. package/lib/module/utils/utils.js +0 -1
  77. package/lib/typescript/Event/onwid.d.ts +0 -13
  78. package/lib/typescript/NativeOnwid.d.ts +0 -6
  79. package/lib/typescript/component/OnwidButton.d.ts +0 -28
  80. package/lib/typescript/component/audiowave.d.ts +0 -6
  81. package/lib/typescript/component/voice.d.ts +0 -15
  82. package/lib/typescript/hooks/initialize.d.ts +0 -2
  83. package/lib/typescript/hooks/initialize.types.d.ts +0 -5
  84. package/lib/typescript/hooks/initializelivekit.d.ts +0 -3
  85. package/lib/typescript/hooks/voiceAgent.d.ts +0 -2
  86. package/lib/typescript/hooks/voiceAgent.types.d.ts +0 -16
  87. package/lib/typescript/index.d.ts +0 -27
  88. package/lib/typescript/onwidApi/api.d.ts +0 -53
  89. package/lib/typescript/onwidApi/api.types.d.ts +0 -21
  90. package/lib/typescript/store.key.d.ts +0 -3
  91. package/lib/typescript/style/onwidButton.style.d.ts +0 -98
  92. package/lib/typescript/utils/reanimatedHelpers.d.ts +0 -29
  93. package/lib/typescript/utils/utils.d.ts +0 -0
  94. package/scripts/verify-setup.js +0 -90
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("@livekit/react-native");
8
+ var _react = require("react");
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ // export interface VoiceProps {
11
+ // url: string;
12
+ // token: string;
13
+ // onDisconnected: (data: string) => void;
14
+ // onConnected: (data: string) => void;
15
+ // }
16
+
17
+ // Track audio session state globally to prevent multiple starts/stops
18
+ let audioSessionActive = false;
19
+ let audioSessionStarting = false;
20
+ let audioSessionStopping = false;
21
+
22
+ // Track connection to prevent unmounting while connected
23
+ let activeConnectionToken = null;
24
+ const Voice = props => {
25
+ const {
26
+ url,
27
+ token,
28
+ onDisconnected,
29
+ onConnected,
30
+ roomRef
31
+ } = props;
32
+ const [audioSessionStarted, setAudioSessionStarted] = (0, _react.useState)(audioSessionActive);
33
+ const mountedRef = (0, _react.useRef)(true);
34
+ const connectedRef = (0, _react.useRef)(false);
35
+
36
+ // Start audio session safely - prevent multiple simultaneous starts
37
+ const startAudioSession = async () => {
38
+ if (audioSessionActive || audioSessionStarting) {
39
+ console.log('Audio session already active or starting, skipping');
40
+ return;
41
+ }
42
+ try {
43
+ audioSessionStarting = true;
44
+ console.log('Starting audio session');
45
+ await _reactNative.AudioSession.startAudioSession();
46
+ audioSessionActive = true;
47
+ if (mountedRef.current) {
48
+ setAudioSessionStarted(true);
49
+ }
50
+ } catch (err) {
51
+ console.error('Failed to start audio session:', err);
52
+ } finally {
53
+ audioSessionStarting = false;
54
+ }
55
+ };
56
+
57
+ // Stop audio session safely - prevent multiple simultaneous stops
58
+ const stopAudioSession = async () => {
59
+ if (!audioSessionActive || audioSessionStopping) {
60
+ console.log('Audio session already inactive or stopping, skipping');
61
+ return;
62
+ }
63
+ try {
64
+ audioSessionStopping = true;
65
+ console.log('Stopping audio session');
66
+ await _reactNative.AudioSession.stopAudioSession();
67
+ audioSessionActive = false;
68
+ } catch (err) {
69
+ console.error('Failed to stop audio session:', err);
70
+ } finally {
71
+ audioSessionStopping = false;
72
+ }
73
+ };
74
+
75
+ // Setup audio session
76
+ (0, _react.useEffect)(() => {
77
+ mountedRef.current = true;
78
+ startAudioSession();
79
+ return () => {
80
+ mountedRef.current = false;
81
+
82
+ // IMPORTANT: Don't stop the audio session on unmount if there might be an active call
83
+ // This prevents audio session start/stop loops when components remount
84
+ if (roomRef.current?.state !== 'connected' && !connectedRef.current) {
85
+ stopAudioSession();
86
+ } else {
87
+ console.log('Skipping audio session stop because room is still connected');
88
+ }
89
+ };
90
+ }, []);
91
+
92
+ // Track connection state changes to avoid unmounting while connected
93
+ (0, _react.useEffect)(() => {
94
+ if (token) {
95
+ activeConnectionToken = token;
96
+ }
97
+ return () => {
98
+ // Only clear token when unmounting with this specific token
99
+ if (activeConnectionToken === token) {
100
+ activeConnectionToken = null;
101
+ }
102
+ };
103
+ }, [token]);
104
+
105
+ // Only render LiveKitRoom when audio session is ready
106
+ if (!audioSessionStarted) {
107
+ return null;
108
+ }
109
+
110
+ // IMPORTANT: Never return empty fragment when connected!
111
+ // Instead, always render the LiveKitRoom component to maintain the connection
112
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.LiveKitRoom, {
113
+ serverUrl: url,
114
+ token: token,
115
+ screen: false,
116
+ audio: true,
117
+ onConnected: () => {
118
+ console.log('LiveKitRoom connected');
119
+ connectedRef.current = true;
120
+ onConnected('connected');
121
+ },
122
+ room: roomRef.current || undefined,
123
+ onDisconnected: () => {
124
+ console.log('LiveKitRoom disconnected');
125
+ connectedRef.current = false;
126
+ onDisconnected('disconnected');
127
+ }
128
+ });
129
+ };
130
+ var _default = exports.default = Voice;
131
+ //# sourceMappingURL=EmbedVoice.js.map
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.onwidButtonStyles = exports.createEmbedButtonStyles = exports.EXPANDED_WIDTH = exports.BUTTON_WIDTH = exports.BUTTON_HEIGHT = void 0;
7
+ var _reactNative = require("react-native");
8
+ const {
9
+ width: SCREEN_WIDTH
10
+ } = _reactNative.Dimensions.get('window');
11
+
12
+ // Calculate dynamic dimensions based on screen size
13
+ const calculateDimensions = () => {
14
+ const isSmallScreen = SCREEN_WIDTH < 375;
15
+ const isLargeScreen = SCREEN_WIDTH > 768;
16
+ return {
17
+ BUTTON_WIDTH: isSmallScreen ? 60 : isLargeScreen ? 60 : 60,
18
+ EXPANDED_WIDTH: SCREEN_WIDTH * (isSmallScreen ? 0.9 : isLargeScreen ? 0.7 : 0.8),
19
+ BUTTON_HEIGHT: isSmallScreen ? 60 : isLargeScreen ? 60 : 60,
20
+ SPACING: {
21
+ SMALL: isSmallScreen ? 8 : isLargeScreen ? 16 : 12,
22
+ MEDIUM: isSmallScreen ? 12 : isLargeScreen ? 20 : 16,
23
+ LARGE: isSmallScreen ? 16 : isLargeScreen ? 24 : 20
24
+ },
25
+ BORDER_RADIUS: {
26
+ SMALL: isSmallScreen ? 20 : isLargeScreen ? 30 : 25,
27
+ MEDIUM: isSmallScreen ? 25 : isLargeScreen ? 35 : 30,
28
+ LARGE: isSmallScreen ? 30 : isLargeScreen ? 40 : 35
29
+ }
30
+ };
31
+ };
32
+ const dimensions = calculateDimensions();
33
+ const BUTTON_WIDTH = exports.BUTTON_WIDTH = dimensions.BUTTON_WIDTH;
34
+ const EXPANDED_WIDTH = exports.EXPANDED_WIDTH = dimensions.EXPANDED_WIDTH;
35
+ const BUTTON_HEIGHT = exports.BUTTON_HEIGHT = dimensions.BUTTON_HEIGHT;
36
+ const createEmbedButtonStyles = customStyles => {
37
+ const {
38
+ buttonWidth = BUTTON_WIDTH,
39
+ buttonHeight = BUTTON_HEIGHT,
40
+ backgroundColor = 'transparent',
41
+ borderRadius = dimensions.BORDER_RADIUS.MEDIUM,
42
+ marginBottom = dimensions.SPACING.LARGE,
43
+ spacing = dimensions.SPACING
44
+ } = customStyles || {};
45
+ return _reactNative.StyleSheet.create({
46
+ container: {
47
+ position: 'absolute',
48
+ bottom: 0,
49
+ right: 0,
50
+ height: '100%',
51
+ width: '100%',
52
+ flexDirection: 'row',
53
+ justifyContent: 'flex-end',
54
+ alignItems: 'flex-end',
55
+ padding: spacing.MEDIUM,
56
+ backgroundColor: 'transparent',
57
+ pointerEvents: 'box-none'
58
+ },
59
+ button: {
60
+ width: buttonWidth,
61
+ height: buttonHeight,
62
+ borderRadius: borderRadius,
63
+ marginBottom: marginBottom,
64
+ backgroundColor: backgroundColor
65
+ },
66
+ pressable: {
67
+ borderRadius: 100,
68
+ padding: 5,
69
+ margin: 0,
70
+ justifyContent: 'center',
71
+ alignItems: 'center',
72
+ height: '100%',
73
+ width: '100%'
74
+ },
75
+ menu: {
76
+ position: 'absolute',
77
+ top: 0,
78
+ backgroundColor: 'white',
79
+ borderRadius: dimensions.BORDER_RADIUS.SMALL,
80
+ padding: spacing.MEDIUM
81
+ },
82
+ menuLeft: {
83
+ right: '100%',
84
+ marginRight: spacing.SMALL
85
+ },
86
+ menuRight: {
87
+ left: '100%',
88
+ marginLeft: spacing.SMALL
89
+ },
90
+ iconText: {
91
+ color: 'white',
92
+ fontSize: 20
93
+ },
94
+ buttonContent: {
95
+ flexDirection: 'row',
96
+ alignItems: 'center'
97
+ // height: '100%',
98
+ },
99
+ iconImage: {
100
+ width: buttonWidth - 10,
101
+ height: buttonHeight - 10,
102
+ resizeMode: 'contain',
103
+ justifyContent: 'center',
104
+ alignItems: 'center',
105
+ alignSelf: 'center',
106
+ margin: 0,
107
+ padding: 0
108
+ },
109
+ startCallButton: {
110
+ height: 36,
111
+ borderRadius: dimensions.BORDER_RADIUS.MEDIUM,
112
+ backgroundColor: '#000',
113
+ justifyContent: 'center',
114
+ alignItems: 'center',
115
+ paddingHorizontal: spacing.SMALL + 1,
116
+ minWidth: 80,
117
+ maxWidth: '90%'
118
+ },
119
+ startCallText: {
120
+ color: 'white',
121
+ fontSize: 12,
122
+ fontWeight: '500'
123
+ },
124
+ rowContainer: {
125
+ flexDirection: 'row',
126
+ alignItems: 'center',
127
+ justifyContent: 'center',
128
+ height: '100%',
129
+ margin: 0,
130
+ padding: 0
131
+ },
132
+ linearGradient: {
133
+ flex: 1,
134
+ borderRadius: dimensions.BORDER_RADIUS.LARGE,
135
+ flexDirection: 'row',
136
+ width: BUTTON_WIDTH
137
+ },
138
+ buttonContainer: {
139
+ flexDirection: 'row',
140
+ alignItems: 'center',
141
+ gap: 4
142
+ },
143
+ endCallButton: {
144
+ justifyContent: 'center',
145
+ alignItems: 'center',
146
+ width: 44,
147
+ height: 44
148
+ },
149
+ muteButton: {
150
+ borderRadius: 100,
151
+ justifyContent: 'center',
152
+ alignItems: 'center',
153
+ width: 44,
154
+ height: 44
155
+ },
156
+ micIcon: {
157
+ width: 24,
158
+ height: 24,
159
+ tintColor: 'white'
160
+ },
161
+ endCallIcon: {
162
+ width: 24,
163
+ height: 24,
164
+ tintColor: 'white'
165
+ },
166
+ buttonImage: {
167
+ width: '100%',
168
+ height: '100%',
169
+ resizeMode: 'contain'
170
+ },
171
+ // New styles for expanded button layout
172
+ expandedContent: {
173
+ flexDirection: 'row',
174
+ flex: 1,
175
+ alignItems: 'center',
176
+ width: '100%',
177
+ justifyContent: 'space-between'
178
+ },
179
+ leftSection: {
180
+ alignItems: 'flex-start'
181
+ },
182
+ centerSection: {
183
+ alignItems: 'center',
184
+ height: '100%'
185
+ },
186
+ rightSection: {
187
+ justifyContent: 'flex-end',
188
+ alignItems: 'center'
189
+ },
190
+ agentInfoContainer: {
191
+ height: BUTTON_HEIGHT,
192
+ flexDirection: 'row',
193
+ alignItems: 'center',
194
+ overflow: 'hidden'
195
+ },
196
+ agentTextContainer: {
197
+ justifyContent: 'center',
198
+ height: '100%',
199
+ flex: 1
200
+ },
201
+ agentNameText: {
202
+ fontFamily: 'Inter-Medium',
203
+ fontSize: 14,
204
+ fontWeight: '500',
205
+ color: 'white'
206
+ },
207
+ statusText: {
208
+ fontFamily: 'Inter-Regular',
209
+ fontSize: 10,
210
+ fontWeight: '300',
211
+ color: 'white'
212
+ },
213
+ // Chip styles
214
+ chip: {
215
+ height: 30,
216
+ borderRadius: dimensions.BORDER_RADIUS.SMALL,
217
+ marginBottom: 10,
218
+ alignSelf: 'flex-end',
219
+ overflow: 'hidden',
220
+ elevation: 3,
221
+ shadowColor: '#000',
222
+ shadowOffset: {
223
+ width: 0,
224
+ height: 2
225
+ },
226
+ shadowOpacity: 0.3,
227
+ shadowRadius: 2
228
+ },
229
+ chipGradient: {
230
+ height: '100%',
231
+ paddingHorizontal: spacing.MEDIUM,
232
+ paddingVertical: spacing.SMALL / 2,
233
+ borderRadius: dimensions.BORDER_RADIUS.SMALL,
234
+ justifyContent: 'center',
235
+ alignItems: 'center'
236
+ },
237
+ chipText: {
238
+ color: 'white',
239
+ fontSize: 12,
240
+ fontWeight: '500'
241
+ }
242
+ });
243
+ };
244
+
245
+ // Default styles export with dynamic dimensions
246
+ exports.createEmbedButtonStyles = createEmbedButtonStyles;
247
+ const onwidButtonStyles = exports.onwidButtonStyles = createEmbedButtonStyles();
248
+ //# sourceMappingURL=EmbedButton.style.js.map
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.EventKeys = void 0;
7
+ var _storeKey = require("../store/store.key.js");
8
+ var _api = require("../api/api.js");
9
+ // Predefined event keys
10
+ let EventKeys = exports.EventKeys = /*#__PURE__*/function (EventKeys) {
11
+ EventKeys["USER_DATA"] = "user_data";
12
+ EventKeys["SCREEN_STATE"] = "state_data";
13
+ return EventKeys;
14
+ }({});
15
+ class Embed {
16
+ events = {};
17
+
18
+ // Automatically adds a default listener if none exists
19
+ ensureDefaultListener(eventKey) {
20
+ if (!this.events[eventKey]) {
21
+ this.events[eventKey] = [data => {
22
+ console.log(`[Default] Event handled for ${eventKey}:`, data);
23
+ }];
24
+ }
25
+ }
26
+ async Event(eventKey, data) {
27
+ if (!Object.values(EventKeys).includes(eventKey)) {
28
+ console.error(`Invalid event key: ${eventKey}`);
29
+ throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
30
+ }
31
+ const key = eventKey;
32
+ if (key !== EventKeys.USER_DATA) {
33
+ const userIdentity = await (0, _storeKey.getAgentData)(EventKeys.USER_DATA);
34
+ if (userIdentity) {
35
+ data.app_user_id = userIdentity.app_user_id;
36
+ } else {
37
+ throw new Error('User identity not found');
38
+ }
39
+ }
40
+
41
+ // Ensure a default listener is registered if not already
42
+ this.ensureDefaultListener(key);
43
+ console.log('response,updateUserDatniuioioioa');
44
+ // Trigger API call
45
+ try {
46
+ const apiService = _api.APIService.getInstance();
47
+ const response = await apiService.updateUserData({
48
+ eventKey: key,
49
+ data
50
+ });
51
+ console.log('response,updateUserData', response);
52
+ if (!response.success) {
53
+ console.error('Failed to trigger API for event:', eventKey);
54
+ }
55
+ (0, _storeKey.setAgentData)(data, key);
56
+ } catch (error) {
57
+ console.error('Error triggering API:', error);
58
+ }
59
+
60
+ // Trigger event listeners
61
+ this.events[key]?.forEach(callback => callback(data));
62
+ }
63
+
64
+ // Still allow custom listeners (optional)
65
+ on(eventKey, callback) {
66
+ if (!this.events[eventKey]) {
67
+ this.events[eventKey] = [];
68
+ }
69
+ this.events[eventKey]?.push(callback);
70
+ }
71
+ }
72
+ const embed = new Embed();
73
+ var _default = exports.default = embed;
74
+ //# sourceMappingURL=embed.event.js.map
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useInitialize = useInitialize;
7
+ var _storeKey = require("../store/store.key.js");
8
+ var _api = require("../api/api.js");
9
+ var _initializeLivekit = _interopRequireDefault(require("./initialize.livekit.js"));
10
+ var _reactNative = require("react-native");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /**
13
+ * Custom hook for initializing the OnWid SDK
14
+ *
15
+ * Required Parameters:
16
+ * - apiKey: string - Unique identifier for the user
17
+ * - deviceId: string - Unique identifier for the device
18
+ * - metadata: object - Additional device/user information
19
+ *
20
+ * The initialization process:
21
+ * 1. Validates required input parameters
22
+ * 2. Stores API key securely in keychain
23
+ * 3. Registers the device with provided details
24
+ */
25
+
26
+ function useInitialize({
27
+ apiKey,
28
+ onwidUrl,
29
+ metadata
30
+ }) {
31
+ const checkPermissions = async () => {
32
+ try {
33
+ // Check for required permissions on Android
34
+ if (_reactNative.Platform.OS === 'android') {
35
+ const recordAudioPermission = _reactNative.PermissionsAndroid.PERMISSIONS.RECORD_AUDIO;
36
+ if (!recordAudioPermission) {
37
+ throw new Error('RECORD_AUDIO permission not available');
38
+ }
39
+ const permissions = [recordAudioPermission];
40
+ const results = await Promise.all(permissions.map(permission => _reactNative.PermissionsAndroid.request(permission)));
41
+ const allGranted = results.every(result => result === _reactNative.PermissionsAndroid.RESULTS.GRANTED);
42
+ if (!allGranted) {
43
+ throw new Error('Required permissions not granted');
44
+ }
45
+ }
46
+ } catch (err) {
47
+ const errorMessage = err instanceof Error ? err.message : 'Failed to check permissions';
48
+ throw new Error(errorMessage);
49
+ }
50
+ };
51
+
52
+ /**
53
+ * Validates required initialization parameters
54
+ * @throws Error if any required parameter is missing or invalid
55
+ */
56
+ const validateInputs = () => {
57
+ if (!apiKey || typeof apiKey !== 'string') {
58
+ throw new Error('apiKey is required and must be a string');
59
+ }
60
+ if (!onwidUrl || typeof onwidUrl !== 'string') {
61
+ throw new Error('onwidUrl is required and must be a string');
62
+ }
63
+ if (metadata && typeof metadata === 'object' && !metadata.config) {
64
+ throw new Error('metadata must contain a config object');
65
+ }
66
+ };
67
+ const initialize = async () => {
68
+ try {
69
+ await checkPermissions();
70
+ (0, _initializeLivekit.default)();
71
+
72
+ // Validate required parameters before proceeding
73
+ validateInputs();
74
+
75
+ // Store API key in keychain
76
+ await (0, _storeKey.setAgentData)({
77
+ apiKey,
78
+ onwidUrl
79
+ });
80
+
81
+ // Get the APIService instance and initialize it
82
+ const apiService = _api.APIService.getInstance();
83
+ await apiService.initialize();
84
+ console.log('registerOnInitialize');
85
+ // Register new device with provided details
86
+ const registerResponse = await apiService.registerOnInitialize();
87
+ if (!registerResponse.success) {
88
+ throw new Error(registerResponse.error || 'Device registration failed');
89
+ }
90
+ if (registerResponse.data) {
91
+ // todo: store config
92
+ }
93
+ } catch (err) {
94
+ const errorMessage = err instanceof Error ? err.message : 'Initialization failed';
95
+ throw new Error(errorMessage);
96
+ }
97
+ };
98
+
99
+ // Initialize immediately when hook is called
100
+ initialize().catch(console.error);
101
+ }
102
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("@livekit/react-native");
8
+ // This module imports the `registerGlobals` function from the LiveKit React Native library.
9
+ // The `registerGlobals` function is used to register global settings and configurations
10
+ // for the LiveKit service, which is essential for managing real-time audio and video
11
+ // communication in the application. The `registerAgent` constant is created as an alias
12
+ // for `registerGlobals`, allowing for easier reference in other parts of the application.
13
+ // Finally, the `registerAgent` is exported as the default export of this module, making
14
+ // it available for use in other modules that require the registration of LiveKit globals.
15
+
16
+ // The registerAgent constant is an alias for the registerGlobals function,
17
+ // which is used to set up global configurations for the LiveKit service.
18
+ const registerAgent = _reactNative.registerGlobals;
19
+ var _default = exports.default = registerAgent;
20
+ //# sourceMappingURL=initialize.livekit.js.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=initialize.types.js.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=voiceAgent.types.js.map