UNPKG

@revrag-ai/embed-react-native

Version:

A powerful React Native library for integrating AI-powered voice agents into mobile applications. Features real-time voice communication, intelligent speech processing, customizable UI components, and comprehensive event handling for building conversation

69 lines (64 loc) 2.08 kB
"use strict"; /** * Custom hook for initializing the OnWid SDK * * Required Parameters: * - apiKey: string - Unique identifier for the user * * The initialization process: * 1. Validates required input parameters * 2. Stores API key securely in keychain * 3. Registers the device with provided details */ import { APIService } from "../api/api.js"; import { setAgentData } from "../store/store.key.js"; import { checkPermissions } from "../utils/permision.js"; import registerAgent from "./initialize.livekit.js"; export function useInitialize({ apiKey, embedUrl }) { /** * Validates required initialization parameters * @throws Error if any required parameter is missing or invalid */ const validateInputs = () => { if (!apiKey || typeof apiKey !== 'string') { throw new Error('apiKey is required and must be a string'); } if (!embedUrl || typeof embedUrl !== 'string') { throw new Error('embedUrl is required and must be a string'); } }; const initialize = async () => { try { await checkPermissions(); registerAgent(); // Validate required parameters before proceeding validateInputs(); // Store API key in keychain await setAgentData({ apiKey, embedUrl }); // Get the APIService instance and initialize it const apiService = APIService.getInstance(); await apiService.initialize(); console.log('registerOnInitialize'); // Register new device with provided details const registerResponse = await apiService.registerOnInitialize(); if (!registerResponse.success) { throw new Error(registerResponse.error || 'Device registration failed'); } if (registerResponse.data) { // todo: store config } } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Initialization failed'; throw new Error(errorMessage); } }; // Initialize immediately when hook is called initialize().catch(console.error); } //# sourceMappingURL=initialize.js.map