Embed React Native SDK Integration Guide
Overview
The Embed React Native SDK is a powerful voice-enabled AI agent library that provides real-time communication capabilities. This comprehensive guide will walk you through the complete integration process from installation to deployment.Prerequisites
- Node.js 18+
- React Native 0.74 or higher
- Platform specific:
- iOS 13+
- Android API 21+
This SDK requires proper setup of audio permissions and real-time communication dependencies.
Installation
Install the Embed React Native SDK using your preferred package manager:Peer Dependencies
The SDK requires several peer dependencies to be installed in your project. Install all required dependencies:Android Configuration
1. Android Manifest Permissions
Add the following permissions to yourandroid/app/src/main/AndroidManifest.xml:
2. Build.gradle Configuration
Add Lottie dependency to yourandroid/app/build.gradle:
3. ProGuard Configuration
If you’re using ProGuard, add these rules to your
android/app/proguard-rules.pro:iOS Configuration
1. iOS Permissions
CRITICAL: Add the following permissions to your
ios/YourAppName/Info.plist. Missing NSMicrophoneUsageDescription will cause the app to crash when accessing the microphone.2. Pod Installation
After installing peer dependencies, run:3. iOS Build Settings
If you encounter build issues, update your iOS project settings inios/YourAppName/Info.plist:
- Enable Bitcode:
NO - Build Active Architecture Only:
YES(for Debug)
Babel Configuration
CRITICAL: React Native Reanimated requires specific Babel configuration. The reanimated plugin must be the last plugin in the plugins array.
babel.config.js:
After updating
babel.config.js, clean your project cache:SDK Initialization
useInitialize Hook
Initialize the SDK at the root level of your application using theuseInitialize hook:
Configuration Options
| Property | Type | Required | Description |
|---|---|---|---|
apiKey | string | ✅ | Your Embed API key |
embedUrl | string | ✅ | Your Embed server URL |
App Setup
1. Wrap App with GestureHandlerRootView
You must wrap your entire app with
GestureHandlerRootView for the SDK to work properly.2. Add EmbedButton Component
Add the floating voice agent button to your screen:Permission Validation
checkPermissions Method
The SDK provides acheckPermissions method to request and validate microphone permissions (Android only). This method automatically requests permissions if not already granted:
Method Behavior
- Android: Requests
RECORD_AUDIOpermission if not already granted - iOS: No-op (permissions handled via Info.plist)
- Throws: Error if permissions are denied or unavailable
On Android, this method will show the system permission dialog if the user hasn’t previously granted microphone access. On iOS, ensure you’ve added
NSMicrophoneUsageDescription to your Info.plist.Call
checkPermissions() before initializing voice features to ensure users can interact with the AI agent properly.Event System
The SDK provides a powerful event system with two main categories:- Sending Events: Send user context and application state to the AI agent
- Listening to Events: Monitor agent connection status and popup visibility
Available Events
Sending Events (EmbedEventKeys)
Listening Events (AgentEvent)
Event Usage Rules
CRITICAL REQUIREMENTS:
- USER_DATA event MUST be sent first before any other events
- USER_DATA must include
app_user_idfor user identification - EmbedButton should only be rendered AFTER USER_DATA event is sent
- SCREEN_STATE events can only be sent after USER_DATA is established
Event Methods
Event Flow Example
Listening to Agent Events
Monitor voice agent connection status and popup visibility changes in real-time:Event Data Structure
All listener events receive data in a consistent format:Event Listener Best Practices
Important Guidelines for Event Listeners:
- Always remove event listeners in cleanup functions to prevent memory leaks
- Use specific handler functions instead of inline callbacks for easier cleanup
- Set up listeners only after SDK initialization is complete
- Consider using
once()for one-time events if available
Navigation Integration
With Navigation Reference (Recommended)
For enhanced navigation tracking and voice agent context, pass a navigation reference:Troubleshooting
Common Issues
React Native Reanimated not working
React Native Reanimated not working
This is the most common issue. Ensure:
- ✅ React Native Reanimated plugin is the last plugin in
babel.config.js - ✅ Clear cache after babel config changes:
npx react-native start --reset-cache - ✅ Restart Metro bundler completely
- ✅ For iOS:
cd ios && pod install
User identity not found error
User identity not found error
This error occurs when you try to send events before USER_DATA:
- ✅ Send
USER_DATAevent first withapp_user_id - ✅ Wait for the event to complete before sending other events
- ✅ Only render
EmbedButtonafter USER_DATA is sent
iOS App Crashes - microphone permission
iOS App Crashes - microphone permission
This crash occurs when the app tries to access the microphone without proper permission:
- ✅ Open
ios/YourAppName/Info.plist - ✅ Add
NSMicrophoneUsageDescriptionwith a user-friendly description:
- ✅ Clean and rebuild:
cd ios && pod install && cd .. && npx react-native run-ios
iOS Network Request Failures
iOS Network Request Failures
This is caused by iOS App Transport Security (ATS). For development:Add domain exceptions to ⚠️ Never use
ios/YourApp/Info.plist for HTTP APIs, but use HTTPS in production.NSAllowsArbitraryLoads: true in production appsEmbedButton not appearing
EmbedButton not appearing
Event listeners not working
Event listeners not working
Common issues with AgentEvent listeners:
- ✅ Ensure listeners are set up after SDK initialization:
- ✅ Always clean up listeners to prevent memory leaks:
- ✅ Use the correct event names from AgentEvent enum:
- ✅ Check that events are actually being emitted by adding console logs in your handlers
Multiple event listeners firing
Multiple event listeners firing
This usually happens when listeners aren’t properly cleaned up:
- ✅ Use specific handler functions instead of inline callbacks:
- ✅ Ensure useEffect dependency arrays are correct to prevent re-registration
- ✅ Consider using a custom hook to centralize event listener management
Best Practices
Event Optimization:
- Debounce frequent events to avoid overwhelming the API
- Batch related data in single events
- Handle offline scenarios with retry logic
- Store events locally when network is unavailable
Event Listener Management:
- Always remove event listeners in cleanup functions to prevent memory leaks
- Set up listeners only after SDK initialization is complete
- Use specific handler functions instead of inline callbacks for easier cleanup
- Consider using custom hooks to centralize event listener logic
- Test that event listeners are properly cleaned up during development
Initialization Strategy:
- Show loading states during SDK initialization
- Handle initialization errors gracefully
- Send USER_DATA as early as possible in the app lifecycle
- Only render EmbedButton after successful initialization
- Set up event listeners after SDK initialization but before rendering components
Network & Security:
- Use HTTPS endpoints in production
- Test API connectivity during development
- Handle network failures gracefully
- Never bypass security requirements in production
Support
For additional help:- Email Support: contact@revrag.ai
Last Updated: June 2025