@revrag-ai/embed-react-native 1.0.5
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 +20 -0
- package/Onwid.podspec +20 -0
- package/README.md +402 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +5 -0
- package/ios/Onwid.h +5 -0
- package/ios/Onwid.mm +18 -0
- package/lib/index.d.ts +77 -0
- package/lib/module/Event/onwid.js +74 -0
- package/lib/module/NativeOnwid.js +4 -0
- package/lib/module/component/OnwidButton.js +366 -0
- package/lib/module/component/audiowave.js +137 -0
- package/lib/module/component/voice.js +103 -0
- package/lib/module/hooks/initialize.js +92 -0
- package/lib/module/hooks/initialize.types.js +2 -0
- package/lib/module/hooks/initializelivekit.js +14 -0
- package/lib/module/hooks/voiceAgent.js +334 -0
- package/lib/module/hooks/voiceAgent.types.js +2 -0
- package/lib/module/index.js +61 -0
- package/lib/module/onwidApi/api.js +184 -0
- package/lib/module/onwidApi/api.types.js +2 -0
- package/lib/module/store.key.js +47 -0
- package/lib/module/style/onwidButton.style.js +230 -0
- package/lib/module/utils/reanimatedHelpers.js +87 -0
- package/lib/module/utils/utils.js +1 -0
- package/lib/typescript/Event/onwid.d.ts +13 -0
- package/lib/typescript/NativeOnwid.d.ts +6 -0
- package/lib/typescript/component/OnwidButton.d.ts +28 -0
- package/lib/typescript/component/audiowave.d.ts +6 -0
- package/lib/typescript/component/voice.d.ts +15 -0
- package/lib/typescript/hooks/initialize.d.ts +2 -0
- package/lib/typescript/hooks/initialize.types.d.ts +5 -0
- package/lib/typescript/hooks/initializelivekit.d.ts +3 -0
- package/lib/typescript/hooks/voiceAgent.d.ts +2 -0
- package/lib/typescript/hooks/voiceAgent.types.d.ts +16 -0
- package/lib/typescript/index.d.ts +27 -0
- package/lib/typescript/onwidApi/api.d.ts +53 -0
- package/lib/typescript/onwidApi/api.types.d.ts +21 -0
- package/lib/typescript/store.key.d.ts +3 -0
- package/lib/typescript/style/onwidButton.style.d.ts +98 -0
- package/lib/typescript/utils/reanimatedHelpers.d.ts +29 -0
- package/lib/typescript/utils/utils.d.ts +0 -0
- package/package.json +208 -0
- package/react-native.config.js +19 -0
- package/scripts/verify-setup.js +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 revragai
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/Onwid.podspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "Onwid"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/RevRag-ai.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
# @revrag-ai/embed-react-native
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/%40revrag-ai%2Fembed-react-native)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A powerful Voice Agent SDK for React Native that enables AI-powered voice communication with real-time speech processing. Built with LiveKit for seamless voice interactions.
|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
|
|
10
|
+
- **Real-time Voice Communication**: High-quality voice chat powered by LiveKit
|
|
11
|
+
- **AI Voice Agent Integration**: Seamless integration with AI voice assistants
|
|
12
|
+
- **Cross-platform Support**: Works on both iOS and Android
|
|
13
|
+
- **TypeScript Support**: Full TypeScript definitions included
|
|
14
|
+
- **Event-driven Architecture**: Flexible event system for custom integrations
|
|
15
|
+
- **Secure API Communication**: Protected API calls with automatic initialization
|
|
16
|
+
- **Easy Integration**: Simple hooks and components for quick setup
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @revrag-ai/embed-react-native
|
|
22
|
+
# or
|
|
23
|
+
yarn add @revrag-ai/embed-react-native
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Peer Dependencies
|
|
27
|
+
|
|
28
|
+
Make sure you have the following peer dependencies installed:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @livekit/react-native @livekit/react-native-webrtc @react-native-async-storage/async-storage lottie-react-native react-native-gesture-handler react-native-linear-gradient react-native-reanimated react-native-safe-area-context
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Important: React Native Reanimated Setup
|
|
35
|
+
|
|
36
|
+
**This library requires `react-native-reanimated` to be properly installed and configured.** If you encounter errors like "Cannot read property 'makeMutable' of undefined", follow these steps:
|
|
37
|
+
|
|
38
|
+
1. **Install react-native-reanimated:**
|
|
39
|
+
```bash
|
|
40
|
+
npm install react-native-reanimated
|
|
41
|
+
# or
|
|
42
|
+
yarn add react-native-reanimated
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. **Add Reanimated's babel plugin to your `babel.config.js`:**
|
|
46
|
+
```javascript
|
|
47
|
+
module.exports = {
|
|
48
|
+
presets: ['module:@react-native/babel-preset'],
|
|
49
|
+
plugins: [
|
|
50
|
+
'react-native-reanimated/plugin',
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
3. **For iOS:** Run `cd ios && pod install`
|
|
56
|
+
|
|
57
|
+
4. **For Android:** Add the following to `android/app/src/main/java/.../MainApplication.java`:
|
|
58
|
+
```java
|
|
59
|
+
import com.swmansion.reanimated.ReanimatedPackage;
|
|
60
|
+
|
|
61
|
+
@Override
|
|
62
|
+
protected List<ReactPackage> getPackages() {
|
|
63
|
+
return Arrays.<ReactPackage>asList(
|
|
64
|
+
new MainReactPackage(),
|
|
65
|
+
new ReanimatedPackage() // Add this line
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
5. **Clean and rebuild your project:**
|
|
71
|
+
```bash
|
|
72
|
+
# For React Native CLI
|
|
73
|
+
npx react-native run-android
|
|
74
|
+
npx react-native run-ios
|
|
75
|
+
|
|
76
|
+
# For Expo (if using)
|
|
77
|
+
expo run:android
|
|
78
|
+
expo run:ios
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For more detailed instructions, visit: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started
|
|
82
|
+
|
|
83
|
+
### Setup Verification
|
|
84
|
+
|
|
85
|
+
After installation, you can verify your setup by running:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx @revrag-ai/embed-react-native verify-setup
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This will check if all dependencies are properly installed and configured.
|
|
92
|
+
|
|
93
|
+
## 🛠️ Setup
|
|
94
|
+
|
|
95
|
+
### iOS Setup
|
|
96
|
+
|
|
97
|
+
Add the following to your `ios/Podfile`:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
pod 'RNFS', :path => '../node_modules/react-native-fs'
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Android Setup
|
|
104
|
+
|
|
105
|
+
Add the following permissions to your `android/app/src/main/AndroidManifest.xml`:
|
|
106
|
+
|
|
107
|
+
```xml
|
|
108
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
109
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
110
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 🔧 Troubleshooting
|
|
114
|
+
|
|
115
|
+
### "Cannot read property 'makeMutable' of undefined"
|
|
116
|
+
|
|
117
|
+
This error occurs when `react-native-reanimated` is not properly installed or configured. Follow these steps:
|
|
118
|
+
|
|
119
|
+
1. **Ensure react-native-reanimated is installed:**
|
|
120
|
+
```bash
|
|
121
|
+
npm list react-native-reanimated
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
2. **Check your babel.config.js includes the reanimated plugin:**
|
|
125
|
+
```javascript
|
|
126
|
+
module.exports = {
|
|
127
|
+
presets: ['module:@react-native/babel-preset'],
|
|
128
|
+
plugins: [
|
|
129
|
+
'react-native-reanimated/plugin', // <- This line is crucial
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
3. **Clear Metro cache and rebuild:**
|
|
135
|
+
```bash
|
|
136
|
+
npx react-native start --reset-cache
|
|
137
|
+
npx react-native run-android # or run-ios
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
4. **For iOS, ensure pods are installed:**
|
|
141
|
+
```bash
|
|
142
|
+
cd ios && pod install && cd ..
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Component Not Rendering
|
|
146
|
+
|
|
147
|
+
If the OnwidButton component doesn't appear or crashes:
|
|
148
|
+
|
|
149
|
+
- Ensure all peer dependencies are installed
|
|
150
|
+
- Check that your app has proper permissions for microphone access
|
|
151
|
+
- Verify your API key and server URL are correct
|
|
152
|
+
|
|
153
|
+
### Voice Connection Issues
|
|
154
|
+
|
|
155
|
+
If voice connection fails:
|
|
156
|
+
|
|
157
|
+
- Check your network connection
|
|
158
|
+
- Verify your API key is valid
|
|
159
|
+
- Ensure microphone permissions are granted
|
|
160
|
+
- Check the console for detailed error messages
|
|
161
|
+
|
|
162
|
+
## 🎯 Quick Start
|
|
163
|
+
|
|
164
|
+
### 1. Initialize the SDK
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { useInitialize } from '@revrag-ai/embed-react-native';
|
|
168
|
+
|
|
169
|
+
function App() {
|
|
170
|
+
useInitialize({
|
|
171
|
+
apiKey: 'your-api-key',
|
|
172
|
+
onwidUrl: 'https://your-onwid-server.com',
|
|
173
|
+
metadata: {
|
|
174
|
+
config: {
|
|
175
|
+
// Your configuration
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
// Your app content
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 2. Use the Voice Agent
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { useVoiceAgent } from '@revrag-ai/embed-react-native';
|
|
190
|
+
|
|
191
|
+
function VoiceComponent() {
|
|
192
|
+
const {
|
|
193
|
+
initializeVoiceAgent,
|
|
194
|
+
endCall,
|
|
195
|
+
muteMic,
|
|
196
|
+
unmuteMic,
|
|
197
|
+
isMicMuted,
|
|
198
|
+
connectionState,
|
|
199
|
+
isLoading,
|
|
200
|
+
error
|
|
201
|
+
} = useVoiceAgent();
|
|
202
|
+
|
|
203
|
+
const startVoiceCall = async () => {
|
|
204
|
+
try {
|
|
205
|
+
await initializeVoiceAgent();
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error('Failed to start voice call:', error);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<View>
|
|
213
|
+
<Button title="Start Voice Call" onPress={startVoiceCall} />
|
|
214
|
+
<Button title="End Call" onPress={endCall} />
|
|
215
|
+
<Button
|
|
216
|
+
title={isMicMuted ? "Unmute" : "Mute"}
|
|
217
|
+
onPress={isMicMuted ? unmuteMic : muteMic}
|
|
218
|
+
/>
|
|
219
|
+
<Text>Status: {connectionState}</Text>
|
|
220
|
+
{isLoading && <Text>Loading...</Text>}
|
|
221
|
+
{error && <Text>Error: {error}</Text>}
|
|
222
|
+
</View>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 3. Handle Events
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import { onwid, EventKeys } from '@revrag-ai/embed-react-native';
|
|
231
|
+
|
|
232
|
+
// Send user data
|
|
233
|
+
await onwid.Event(EventKeys.USER_DATA, {
|
|
234
|
+
app_user_id: 'user123',
|
|
235
|
+
name: 'John Doe',
|
|
236
|
+
preferences: {
|
|
237
|
+
language: 'en'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Send screen state
|
|
242
|
+
await onwid.Event(EventKeys.SCREEN_STATE, {
|
|
243
|
+
screen: 'home',
|
|
244
|
+
timestamp: Date.now()
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 4. TypeScript Usage
|
|
249
|
+
|
|
250
|
+
For TypeScript projects, you can import types for better type safety:
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
import {
|
|
254
|
+
OnwidButton,
|
|
255
|
+
useInitialize,
|
|
256
|
+
useVoiceAgent,
|
|
257
|
+
type UseInitializeProps,
|
|
258
|
+
type UseVoiceAgentReturn,
|
|
259
|
+
type ApiResponse,
|
|
260
|
+
EventKeys
|
|
261
|
+
} from '@revrag-ai/embed-react-native';
|
|
262
|
+
|
|
263
|
+
// Type-safe initialization
|
|
264
|
+
const initProps: UseInitializeProps = {
|
|
265
|
+
apiKey: 'your-api-key',
|
|
266
|
+
onwidUrl: 'https://your-onwid-server.com',
|
|
267
|
+
metadata: {
|
|
268
|
+
config: {
|
|
269
|
+
theme: 'dark'
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
function MyVoiceComponent() {
|
|
275
|
+
useInitialize(initProps);
|
|
276
|
+
|
|
277
|
+
const voiceAgent: UseVoiceAgentReturn = useVoiceAgent();
|
|
278
|
+
|
|
279
|
+
const handleStartCall = async (): Promise<void> => {
|
|
280
|
+
try {
|
|
281
|
+
await voiceAgent.initializeVoiceAgent();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error('Failed to start call:', error);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<View>
|
|
289
|
+
<OnwidButton />
|
|
290
|
+
<Button title="Start Call" onPress={handleStartCall} />
|
|
291
|
+
</View>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### 5. Use the OnWid Button Component
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
import { OnwidButton } from '@revrag-ai/embed-react-native';
|
|
300
|
+
|
|
301
|
+
function MyComponent() {
|
|
302
|
+
return (
|
|
303
|
+
<View>
|
|
304
|
+
<OnwidButton />
|
|
305
|
+
</View>
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## 📚 API Reference
|
|
311
|
+
|
|
312
|
+
### Hooks
|
|
313
|
+
|
|
314
|
+
#### `useInitialize(props: UseInitializeProps)`
|
|
315
|
+
|
|
316
|
+
Initializes the OnWid SDK with your configuration.
|
|
317
|
+
|
|
318
|
+
**Props:**
|
|
319
|
+
- `apiKey: string` - Your OnWid API key
|
|
320
|
+
- `onwidUrl: string` - Your OnWid server URL
|
|
321
|
+
- `metadata?: object` - Optional metadata configuration
|
|
322
|
+
|
|
323
|
+
#### `useVoiceAgent(): UseVoiceAgentReturn`
|
|
324
|
+
|
|
325
|
+
Provides voice agent functionality.
|
|
326
|
+
|
|
327
|
+
**Returns:**
|
|
328
|
+
- `initializeVoiceAgent: () => Promise<void>` - Start voice agent
|
|
329
|
+
- `endCall: () => Promise<void>` - End the voice call
|
|
330
|
+
- `muteMic: () => void` - Mute microphone
|
|
331
|
+
- `unmuteMic: () => void` - Unmute microphone
|
|
332
|
+
- `isMicMuted: boolean` - Microphone mute state
|
|
333
|
+
- `connectionState: ConnectionState` - Current connection state
|
|
334
|
+
- `isLoading: boolean` - Loading state
|
|
335
|
+
- `error: string | null` - Error message if any
|
|
336
|
+
|
|
337
|
+
### Components
|
|
338
|
+
|
|
339
|
+
#### `OnwidButton`
|
|
340
|
+
|
|
341
|
+
A customizable button component with built-in voice agent functionality.
|
|
342
|
+
|
|
343
|
+
### Classes
|
|
344
|
+
|
|
345
|
+
#### `APIService`
|
|
346
|
+
|
|
347
|
+
Singleton service for API communication.
|
|
348
|
+
|
|
349
|
+
```tsx
|
|
350
|
+
import { APIService } from '@revrag-ai/embed-react-native';
|
|
351
|
+
|
|
352
|
+
const apiService = APIService.getInstance();
|
|
353
|
+
await apiService.initialize();
|
|
354
|
+
```
|
|
355
|
+
### Events
|
|
356
|
+
|
|
357
|
+
#### `EventKeys`
|
|
358
|
+
|
|
359
|
+
Available event types:
|
|
360
|
+
- `USER_DATA` - User information events
|
|
361
|
+
- `SCREEN_STATE` - Screen state events
|
|
362
|
+
|
|
363
|
+
## 🔒 Security
|
|
364
|
+
|
|
365
|
+
The OnWid SDK includes built-in security features:
|
|
366
|
+
|
|
367
|
+
- Automatic API key management
|
|
368
|
+
- Secure token handling
|
|
369
|
+
- Protected API endpoints
|
|
370
|
+
- Integrity checks
|
|
371
|
+
|
|
372
|
+
## 🤝 Contributing
|
|
373
|
+
|
|
374
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
375
|
+
|
|
376
|
+
## 📄 License
|
|
377
|
+
|
|
378
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
379
|
+
|
|
380
|
+
## 🆘 Support
|
|
381
|
+
|
|
382
|
+
- 📧 Email: contact@revrag.ai
|
|
383
|
+
- 🐛 Issues: [GitHub Issues](https://github.com/RevRag-ai/embed-react-native/issues)
|
|
384
|
+
- 📖 Documentation: [Integration Guide](INTEGRATION_GUIDE.md)
|
|
385
|
+
|
|
386
|
+
## 🏷️ Version History
|
|
387
|
+
|
|
388
|
+
### 1.0.3
|
|
389
|
+
- Enhanced APIService with singleton pattern
|
|
390
|
+
- Improved error handling and initialization
|
|
391
|
+
- Better TypeScript support
|
|
392
|
+
- Fixed voice component compatibility
|
|
393
|
+
|
|
394
|
+
### 1.0.2
|
|
395
|
+
- Initial stable release
|
|
396
|
+
- Core voice agent functionality
|
|
397
|
+
- Event system implementation
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
Made with ❤️ by [RevRag AI](https://www.revrag.ai)
|
|
402
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Onwid_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Onwid_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.onwid"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
react {
|
|
80
|
+
jsRootDir = file("../src/")
|
|
81
|
+
libraryName = "Onwid"
|
|
82
|
+
codegenJavaPackageName = "com.onwid"
|
|
83
|
+
}
|
package/ios/Onwid.h
ADDED
package/ios/Onwid.mm
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import "Onwid.h"
|
|
2
|
+
|
|
3
|
+
@implementation Onwid
|
|
4
|
+
RCT_EXPORT_MODULE()
|
|
5
|
+
|
|
6
|
+
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
7
|
+
NSNumber *result = @(a * b);
|
|
8
|
+
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
13
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
14
|
+
{
|
|
15
|
+
return std::make_shared<facebook::react::NativeOnwidSpecJSI>(params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@end
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.d.ts
|
|
3
|
+
* @description TypeScript declarations for the Onwid React Native library.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ConnectionState, Room } from 'livekit-client';
|
|
7
|
+
import { RefObject } from 'react';
|
|
8
|
+
|
|
9
|
+
// Component declarations
|
|
10
|
+
export declare function OnwidButton(): JSX.Element;
|
|
11
|
+
|
|
12
|
+
// Hook type declarations
|
|
13
|
+
export interface UseInitializeProps {
|
|
14
|
+
apiKey: string;
|
|
15
|
+
agentId?: string;
|
|
16
|
+
onwidUrl?: string;
|
|
17
|
+
metadata?: any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UseVoiceAgentReturn {
|
|
21
|
+
initializeVoiceAgent: () => Promise<void>;
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
error: string | null;
|
|
24
|
+
tokenDetails: any;
|
|
25
|
+
endCall: () => Promise<void>;
|
|
26
|
+
room: Room;
|
|
27
|
+
roomRef: RefObject<Room>;
|
|
28
|
+
isMicMuted: boolean;
|
|
29
|
+
muteMic: () => void;
|
|
30
|
+
unmuteMic: () => void;
|
|
31
|
+
connectionState: ConnectionState;
|
|
32
|
+
cleanup: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Hook declarations
|
|
36
|
+
export declare const useInitialize: (props: UseInitializeProps) => void;
|
|
37
|
+
export declare const useVoiceAgent: () => UseVoiceAgentReturn;
|
|
38
|
+
|
|
39
|
+
// API type declarations
|
|
40
|
+
export interface ApiResponse<T> {
|
|
41
|
+
success: boolean;
|
|
42
|
+
data?: T;
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface RegisterRequest {
|
|
47
|
+
apiKey: string;
|
|
48
|
+
onwidUrl: string;
|
|
49
|
+
metadata?: Record<string, any>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TokenDetails {
|
|
53
|
+
token: string;
|
|
54
|
+
expiresAt: number;
|
|
55
|
+
apiKey: string;
|
|
56
|
+
config: Record<string, any>;
|
|
57
|
+
server_url: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface UpdateDataRequest {
|
|
61
|
+
eventKey: string;
|
|
62
|
+
data: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Event system declarations
|
|
66
|
+
export enum EventKeys {
|
|
67
|
+
USER_DATA = 'user_data',
|
|
68
|
+
SCREEN_STATE = 'state_data',
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export declare class OnWid {
|
|
72
|
+
Event(eventKey: string, data: any): Promise<void>;
|
|
73
|
+
on(eventKey: EventKeys, callback: (data: any) => void): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export declare const onwid: OnWid;
|
|
77
|
+
export declare const registerAgent: any;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventKeys = void 0;
|
|
4
|
+
const store_key_1 = require("../store.key");
|
|
5
|
+
const api_1 = require("../onwidApi/api");
|
|
6
|
+
// Predefined event keys
|
|
7
|
+
var EventKeys;
|
|
8
|
+
(function (EventKeys) {
|
|
9
|
+
EventKeys["USER_DATA"] = "user_data";
|
|
10
|
+
EventKeys["SCREEN_STATE"] = "state_data";
|
|
11
|
+
})(EventKeys || (exports.EventKeys = EventKeys = {}));
|
|
12
|
+
class OnWid {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.events = {};
|
|
15
|
+
}
|
|
16
|
+
// Automatically adds a default listener if none exists
|
|
17
|
+
ensureDefaultListener(eventKey) {
|
|
18
|
+
if (!this.events[eventKey]) {
|
|
19
|
+
this.events[eventKey] = [
|
|
20
|
+
(data) => {
|
|
21
|
+
console.log(`[Default] Event handled for ${eventKey}:`, data);
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async Event(eventKey, data) {
|
|
27
|
+
var _a;
|
|
28
|
+
if (!Object.values(EventKeys).includes(eventKey)) {
|
|
29
|
+
console.error(`Invalid event key: ${eventKey}`);
|
|
30
|
+
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
const key = eventKey;
|
|
33
|
+
if (key !== EventKeys.USER_DATA) {
|
|
34
|
+
const userIdentity = await (0, store_key_1.getAgentData)(EventKeys.USER_DATA);
|
|
35
|
+
if (userIdentity) {
|
|
36
|
+
data.app_user_id = userIdentity.app_user_id;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error('User identity not found');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Ensure a default listener is registered if not already
|
|
43
|
+
this.ensureDefaultListener(key);
|
|
44
|
+
console.log('response,updateUserDatniuioioioa');
|
|
45
|
+
// Trigger API call
|
|
46
|
+
try {
|
|
47
|
+
const apiService = api_1.APIService.getInstance();
|
|
48
|
+
const response = await apiService.updateUserData({
|
|
49
|
+
eventKey: key,
|
|
50
|
+
data,
|
|
51
|
+
});
|
|
52
|
+
console.log('response,updateUserData', response);
|
|
53
|
+
if (!response.success) {
|
|
54
|
+
console.error('Failed to trigger API for event:', eventKey);
|
|
55
|
+
}
|
|
56
|
+
(0, store_key_1.setAgentData)(data, key);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Error triggering API:', error);
|
|
60
|
+
}
|
|
61
|
+
// Trigger event listeners
|
|
62
|
+
(_a = this.events[key]) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(data));
|
|
63
|
+
}
|
|
64
|
+
// Still allow custom listeners (optional)
|
|
65
|
+
on(eventKey, callback) {
|
|
66
|
+
var _a;
|
|
67
|
+
if (!this.events[eventKey]) {
|
|
68
|
+
this.events[eventKey] = [];
|
|
69
|
+
}
|
|
70
|
+
(_a = this.events[eventKey]) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const onwid = new OnWid();
|
|
74
|
+
exports.default = onwid;
|