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

75 lines (69 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useInitialize = useInitialize; var _api = require("../api/api.js"); var _storeKey = require("../store/store.key.js"); var _permision = require("../utils/permision.js"); var _initializeLivekit = _interopRequireDefault(require("./initialize.livekit.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * 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 */ 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 (0, _permision.checkPermissions)(); (0, _initializeLivekit.default)(); // Validate required parameters before proceeding validateInputs(); // Store API key in keychain await (0, _storeKey.setAgentData)({ apiKey, embedUrl }); // Get the APIService instance and initialize it const apiService = _api.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