@revrag-ai/embed-react-native 1.0.15 → 1.0.17

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 (76) hide show
  1. package/dist/commonjs/api/api.js +6 -5
  2. package/dist/commonjs/api/api.js.map +1 -1
  3. package/dist/commonjs/components/Embed/EmbedButton.js +140 -318
  4. package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
  5. package/dist/commonjs/components/Embed/EmbedVoice.js +16 -4
  6. package/dist/commonjs/components/Embed/EmbedVoice.js.map +1 -1
  7. package/dist/commonjs/context/EmbedProvider.js +638 -0
  8. package/dist/commonjs/context/EmbedProvider.js.map +1 -0
  9. package/dist/commonjs/events/embed.event.js +141 -7
  10. package/dist/commonjs/events/embed.event.js.map +1 -1
  11. package/dist/commonjs/hooks/EmbedButton.animations.js +181 -0
  12. package/dist/commonjs/hooks/EmbedButton.animations.js.map +1 -0
  13. package/dist/commonjs/hooks/EmbedButton.helpers.js +90 -0
  14. package/dist/commonjs/hooks/EmbedButton.helpers.js.map +1 -0
  15. package/dist/commonjs/hooks/EmbedButton.hooks.js +165 -0
  16. package/dist/commonjs/hooks/EmbedButton.hooks.js.map +1 -0
  17. package/dist/commonjs/hooks/initialize.js +65 -25
  18. package/dist/commonjs/hooks/initialize.js.map +1 -1
  19. package/dist/commonjs/index.js +14 -0
  20. package/dist/commonjs/index.js.map +1 -1
  21. package/dist/commonjs/utils/constant.js +88 -0
  22. package/dist/commonjs/utils/constant.js.map +1 -0
  23. package/dist/commonjs/utils/reanimated.helper.js +2 -3
  24. package/dist/commonjs/utils/reanimated.helper.js.map +1 -1
  25. package/dist/module/api/api.js +6 -6
  26. package/dist/module/api/api.js.map +1 -1
  27. package/dist/module/components/Embed/EmbedButton.js +141 -320
  28. package/dist/module/components/Embed/EmbedButton.js.map +1 -1
  29. package/dist/module/components/Embed/EmbedVoice.js +16 -4
  30. package/dist/module/components/Embed/EmbedVoice.js.map +1 -1
  31. package/dist/module/context/EmbedProvider.js +626 -0
  32. package/dist/module/context/EmbedProvider.js.map +1 -0
  33. package/dist/module/events/embed.event.js +144 -5
  34. package/dist/module/events/embed.event.js.map +1 -1
  35. package/dist/module/hooks/EmbedButton.animations.js +172 -0
  36. package/dist/module/hooks/EmbedButton.animations.js.map +1 -0
  37. package/dist/module/hooks/EmbedButton.helpers.js +80 -0
  38. package/dist/module/hooks/EmbedButton.helpers.js.map +1 -0
  39. package/dist/module/hooks/EmbedButton.hooks.js +160 -0
  40. package/dist/module/hooks/EmbedButton.hooks.js.map +1 -0
  41. package/dist/module/hooks/initialize.js +66 -26
  42. package/dist/module/hooks/initialize.js.map +1 -1
  43. package/dist/module/index.js +3 -2
  44. package/dist/module/index.js.map +1 -1
  45. package/dist/module/utils/constant.js +82 -0
  46. package/dist/module/utils/constant.js.map +1 -0
  47. package/dist/module/utils/reanimated.helper.js +2 -3
  48. package/dist/module/utils/reanimated.helper.js.map +1 -1
  49. package/dist/typescript/src/api/api.d.ts +4 -3
  50. package/dist/typescript/src/api/api.d.ts.map +1 -1
  51. package/dist/typescript/src/api/types/embed.api.types.d.ts +1 -1
  52. package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
  53. package/dist/typescript/src/components/Embed/EmbedButton.d.ts +5 -25
  54. package/dist/typescript/src/components/Embed/EmbedButton.d.ts.map +1 -1
  55. package/dist/typescript/src/components/Embed/EmbedVoice.d.ts.map +1 -1
  56. package/dist/typescript/src/context/EmbedProvider.d.ts +306 -0
  57. package/dist/typescript/src/context/EmbedProvider.d.ts.map +1 -0
  58. package/dist/typescript/src/events/embed.event.d.ts +79 -1
  59. package/dist/typescript/src/events/embed.event.d.ts.map +1 -1
  60. package/dist/typescript/src/hooks/EmbedButton.animations.d.ts +38 -0
  61. package/dist/typescript/src/hooks/EmbedButton.animations.d.ts.map +1 -0
  62. package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts +49 -0
  63. package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts.map +1 -0
  64. package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts +49 -0
  65. package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts.map +1 -0
  66. package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
  67. package/dist/typescript/src/hooks/types/initialize.types.d.ts +1 -1
  68. package/dist/typescript/src/hooks/types/initialize.types.d.ts.map +1 -1
  69. package/dist/typescript/src/index.d.ts +5 -3
  70. package/dist/typescript/src/index.d.ts.map +1 -1
  71. package/dist/typescript/src/index.types.d.ts +1 -1
  72. package/dist/typescript/src/index.types.d.ts.map +1 -1
  73. package/dist/typescript/src/utils/constant.d.ts +45 -0
  74. package/dist/typescript/src/utils/constant.d.ts.map +1 -0
  75. package/dist/typescript/src/utils/reanimated.helper.d.ts.map +1 -1
  76. package/package.json +6 -2
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.updateUserData = exports.registerOnInitialize = exports.initializeApi = exports.getTokenDetails = exports.getPopupDescription = exports.APIService = void 0;
7
7
  var _storeKey = require("../store/store.key.js");
8
8
  var _apiError = require("./api.error.js");
9
+ var _constant = require("../utils/constant.js");
9
10
  /**
10
11
  * APIService class that ensures proper initialization before API calls
11
12
  */
@@ -33,12 +34,12 @@ class APIService {
33
34
  return; // Already initialized
34
35
  }
35
36
  const AgentData = await (0, _storeKey.getAgentData)();
36
- if (AgentData?.embedUrl) {
37
- this.apiBaseUrl = AgentData.embedUrl;
38
- this.isInitialized = true;
39
- } else {
37
+ if (!AgentData) {
40
38
  throw new Error('API base URL not found in keychain');
41
39
  }
40
+ const resolvedEmbedUrl = AgentData.embedUrl && typeof AgentData.embedUrl === 'string' ? AgentData.embedUrl : _constant.DEFAULT_EMBED_URL;
41
+ this.apiBaseUrl = resolvedEmbedUrl;
42
+ this.isInitialized = true;
42
43
  }
43
44
 
44
45
  /**
@@ -106,7 +107,7 @@ class APIService {
106
107
  method: 'PUT',
107
108
  headers,
108
109
  body: JSON.stringify({
109
- [params.eventKey]: params.data
110
+ [params.type]: params.data
110
111
  })
111
112
  });
112
113
  if (!response.ok) {
@@ -1 +1 @@
1
- {"version":3,"names":["_storeKey","require","_apiError","APIService","instance","apiBaseUrl","isInitialized","constructor","getInstance","initialize","AgentData","getAgentData","embedUrl","Error","ensureInitialized","getHeaders","apiKey","registerOnInitialize","response","headers","fetch","method","data","json","ok","processApiError","undefined","setAgentData","success","error","updateUserData","params","app_user_id","body","JSON","stringify","eventKey","getTokenDetails","getPopupDescription","exports","initializeApi","apiService"],"sourceRoot":"../../../src","sources":["api/api.ts"],"mappings":";;;;;;AAKA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACO,MAAME,UAAU,CAAC;EACtB,OAAeC,QAAQ,GAAsB,IAAI;EACzCC,UAAU,GAAkB,IAAI;EAChCC,aAAa,GAAY,KAAK;EAE9BC,WAAWA,CAAA,EAAG,CAAC;;EAEvB;AACF;AACA;EACE,OAAcC,WAAWA,CAAA,EAAe;IACtC,IAAI,CAACL,UAAU,CAACC,QAAQ,EAAE;MACxBD,UAAU,CAACC,QAAQ,GAAG,IAAID,UAAU,CAAC,CAAC;IACxC;IACA,OAAOA,UAAU,CAACC,QAAQ;EAC5B;;EAEA;AACF;AACA;EACE,MAAaK,UAAUA,CAAA,EAAkB;IACvC,IAAI,IAAI,CAACH,aAAa,IAAI,IAAI,CAACD,UAAU,EAAE;MACzC,OAAO,CAAC;IACV;IAEA,MAAMK,SAAS,GAAG,MAAM,IAAAC,sBAAY,EAAC,CAAC;IAEtC,IAAID,SAAS,EAAEE,QAAQ,EAAE;MACvB,IAAI,CAACP,UAAU,GAAGK,SAAS,CAACE,QAAQ;MACpC,IAAI,CAACN,aAAa,GAAG,IAAI;IAC3B,CAAC,MAAM;MACL,MAAM,IAAIO,KAAK,CAAC,oCAAoC,CAAC;IACvD;EACF;;EAEA;AACF;AACA;EACE,MAAcC,iBAAiBA,CAAA,EAAkB;IA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;AACF;;AAEA;AAAAa,OAAA,CAAApC,UAAA,GAAAA,UAAA;AACO,MAAMqC,aAAa,GAAG,MAAAA,CAAA,KAAY;EACvC,MAAMC,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,MAAMiC,UAAU,CAAChC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAAC8B,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMvB,oBAAoB,GAAG,MAAAA,CAAA,KAAY;EAC9C,MAAMwB,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACxB,oBAAoB,CAAC,CAAC;AAChD,CAAC;AAACsB,OAAA,CAAAtB,oBAAA,GAAAA,oBAAA;AAEK,MAAMa,cAAc,GAAG,MAAOC,MAAyB,IAAK;EACjE,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACX,cAAc,CAACC,MAAM,CAAC;AAChD,CAAC;AAACQ,OAAA,CAAAT,cAAA,GAAAA,cAAA;AAEK,MAAMO,eAAe,GAAG,MAAON,MAGrC,IAAK;EACJ,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACJ,eAAe,CAACN,MAAM,CAAC;AACjD,CAAC;AAACQ,OAAA,CAAAF,eAAA,GAAAA,eAAA;AAEK,MAAMC,mBAAmB,GAAG,MAAOP,MAA+B,IAAK;EAC5E,MAAMU,UAAU,GAAGtC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMiC,UAAU,CAACH,mBAAmB,CAACP,MAAM,CAAC;AACrD,CAAC;AAACQ,OAAA,CAAAD,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_storeKey","require","_apiError","_constant","APIService","instance","apiBaseUrl","isInitialized","constructor","getInstance","initialize","AgentData","getAgentData","Error","resolvedEmbedUrl","embedUrl","DEFAULT_EMBED_URL","ensureInitialized","getHeaders","apiKey","registerOnInitialize","response","headers","fetch","method","data","json","ok","processApiError","undefined","setAgentData","success","error","updateUserData","params","app_user_id","body","JSON","stringify","type","getTokenDetails","getPopupDescription","exports","initializeApi","apiService"],"sourceRoot":"../../../src","sources":["api/api.ts"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAGA;AACA;AACA;AACO,MAAMG,UAAU,CAAC;EACtB,OAAeC,QAAQ,GAAsB,IAAI;EACzCC,UAAU,GAAkB,IAAI;EAChCC,aAAa,GAAY,KAAK;EAE9BC,WAAWA,CAAA,EAAG,CAAC;;EAEvB;AACF;AACA;EACE,OAAcC,WAAWA,CAAA,EAAe;IACtC,IAAI,CAACL,UAAU,CAACC,QAAQ,EAAE;MACxBD,UAAU,CAACC,QAAQ,GAAG,IAAID,UAAU,CAAC,CAAC;IACxC;IACA,OAAOA,UAAU,CAACC,QAAQ;EAC5B;;EAEA;AACF;AACA;EACE,MAAaK,UAAUA,CAAA,EAAkB;IACvC,IAAI,IAAI,CAACH,aAAa,IAAI,IAAI,CAACD,UAAU,EAAE;MACzC,OAAO,CAAC;IACV;IAEA,MAAMK,SAAS,GAAG,MAAM,IAAAC,sBAAY,EAAC,CAAC;IAEtC,IAAI,CAACD,SAAS,EAAE;MACd,MAAM,IAAIE,KAAK,CAAC,oCAAoC,CAAC;IACvD;IAEA,MAAMC,gBAAgB,GACpBH,SAAS,CAACI,QAAQ,IAAI,OAAOJ,SAAS,CAACI,QAAQ,KAAK,QAAQ,GACxDJ,SAAS,CAACI,QAAQ,GAClBC,2BAAiB;IAEvB,IAAI,CAACV,UAAU,GAAGQ,gBAAgB;IAClC,IAAI,CAACP,aAAa,GAAG,IAAI;EAC3B;;EAEA;AACF;AACA;EACE,MAAcU,iBAAiBA,CAAA,EAAkB;IAC/C,IA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ACF;AACF;;AAEA;AAAAa,OAAA,CAAAtC,UAAA,GAAAA,UAAA;AACO,MAAMuC,aAAa,GAAG,MAAAA,CAAA,KAAY;EACvC,MAAMC,UAAU,GAAGxC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,MAAMmC,UAAU,CAAClC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAACgC,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAEK,MAAMvB,oBAAoB,GAAG,MAAAA,CAAA,KAAY;EAC9C,MAAMwB,UAAU,GAAGxC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMmC,UAAU,CAACxB,oBAAoB,CAAC,CAAC;AAChD,CAAC;AAACsB,OAAA,CAAAtB,oBAAA,GAAAA,oBAAA;AAEK,MAAMa,cAAc,GAAG,MAAOC,MAAoB,IAAK;EAC5D,MAAMU,UAAU,GAAGxC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMmC,UAAU,CAACX,cAAc,CAACC,MAAM,CAAC;AAChD,CAAC;AAACQ,OAAA,CAAAT,cAAA,GAAAA,cAAA;AAEK,MAAMO,eAAe,GAAG,MAAON,MAGrC,IAAK;EACJ,MAAMU,UAAU,GAAGxC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMmC,UAAU,CAACJ,eAAe,CAACN,MAAM,CAAC;AACjD,CAAC;AAACQ,OAAA,CAAAF,eAAA,GAAAA,eAAA;AAEK,MAAMC,mBAAmB,GAAG,MAAOP,MAA+B,IAAK;EAC5E,MAAMU,UAAU,GAAGxC,UAAU,CAACK,WAAW,CAAC,CAAC;EAC3C,OAAO,MAAMmC,UAAU,CAACH,mBAAmB,CAACP,MAAM,CAAC;AACrD,CAAC;AAACQ,OAAA,CAAAD,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -11,61 +11,32 @@ var _reactNative = require("react-native");
11
11
  var _reactNativeGestureHandler = require("react-native-gesture-handler");
12
12
  var _reactNativeLinearGradient = _interopRequireDefault(require("react-native-linear-gradient"));
13
13
  var _voiceagent = require("../../hooks/voiceagent.js");
14
- var _storeKey = require("../../store/store.key.js");
15
14
  var _EmbedButtonStyle = require("../styles/EmbedButton.style.js");
16
- var _reanimatedHelper = require("../../utils/reanimated.helper.js");
17
15
  var _EmbedVoice = _interopRequireDefault(require("./EmbedVoice.js"));
18
16
  var _EmbedAudioWave = require("./EmbedAudioWave.js");
19
- var _permision = require("../../utils/permision.js");
17
+ var _embedEvent = _interopRequireWildcard(require("../../events/embed.event.js"));
18
+ var _EmbedButtonHelpers = require("../../hooks/EmbedButton.helpers.js");
19
+ var _EmbedButtonHooks = require("../../hooks/EmbedButton.hooks.js");
20
+ var _EmbedButtonAnimations = require("../../hooks/EmbedButton.animations.js");
20
21
  var _jsxRuntime = require("react/jsx-runtime");
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
21
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
24
  /**
23
- * @file OnwidButton.tsx
24
- * @description A customizable floating action button component for React Native applications.
25
- * This component provides a draggable, expandable button with animation support and gradient styling.
25
+ * @file EmbedButton.tsx
26
+ * @description A customizable floating action button component for voice agent interactions.
27
+ * Features: draggable, expandable, animated, with call controls and auto-trigger support.
26
28
  */
27
29
 
28
- // Get reanimated API with fallbacks
29
- const {
30
- useSharedValue,
31
- useAnimatedStyle,
32
- withTiming,
33
- withSpring,
34
- withRepeat,
35
- withSequence,
36
- runOnJS,
37
- Easing,
38
- Animated,
39
- isAvailable: isReanimatedAvailable
40
- } = (0, _reanimatedHelper.getReanimatedAPI)();
30
+ // Helpers and constants
41
31
 
42
- // Show warning if reanimated is not available
43
- if (!isReanimatedAvailable) {
44
- (0, _reanimatedHelper.showReanimatedSetupError)();
45
- }
46
- const {
47
- width: SCREEN_WIDTH,
48
- height: SCREEN_HEIGHT
49
- } = _reactNative.Dimensions.get('window');
50
- const BUTTON_WIDTH = 60;
51
- const EXPANDED_WIDTH = SCREEN_WIDTH * 0.9;
52
- const BUTTON_HEIGHT = 60;
53
- const GRADIENT_COLORS = ['#1E0844', '#B391F3'];
54
-
55
- // Define mic icons as base64 images for portability
56
- const MIC_ON_ICON = 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/Mute+button.png';
57
- const MIC_OFF_ICON = 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/unmute.png';
32
+ // Custom hooks
58
33
 
59
- // Add end call icon
60
- const END_CALL_ICON = 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/end+button.png';
61
- const AMPLIFY_ANIMATION = 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/amplify.json';
34
+ // Animation hooks
62
35
 
63
- /**
64
- * Default styles configuration for the button
65
- */
36
+ // ==================== STYLES CONFIG ====================
66
37
  const defaultStyles = {
67
- buttonWidth: 60,
68
- buttonHeight: 60,
38
+ buttonWidth: _EmbedButtonHelpers.BUTTON_DIMENSIONS.WIDTH,
39
+ buttonHeight: _EmbedButtonHelpers.BUTTON_DIMENSIONS.HEIGHT,
69
40
  borderRadius: 100,
70
41
  marginBottom: 20,
71
42
  spacing: {
@@ -78,37 +49,17 @@ const defaultStyles = {
78
49
  }
79
50
  };
80
51
 
52
+ // ==================== MAIN COMPONENT ====================
81
53
  /**
82
- * OnwidButton Component
54
+ * EmbedButton - Main voice agent floating action button
83
55
  *
84
- * A floating action button that can be dragged around the screen and expanded to show additional content.
85
- * Features include:
86
- * - Draggable functionality
87
- * - Expandable menu
88
- * - Animated transitions
89
- * - Gradient background
90
- * - Customizable styling
91
- *
92
- * @component
93
56
  * @example
94
57
  * ```tsx
95
- * <OnwidButton
96
- * isOpen={false}
97
- * onPress={(isOpen) => console.log('Button pressed:', isOpen)}
98
- * menuComponent={<YourMenuComponent />}
99
- * />
58
+ * <EmbedButton />
100
59
  * ```
101
60
  */
102
-
103
- /**
104
- * Generates random sentences for testing or placeholder content
105
- * @param count - Number of sentences to generate (default: 1)
106
- * @param minWords - Minimum words per sentence (default: 5)
107
- * @param maxWords - Maximum words per sentence (default: 15)
108
- * @returns Array of random sentences
109
- */
110
-
111
61
  function EmbedButton() {
62
+ // ==================== VOICE AGENT STATE ====================
112
63
  const {
113
64
  initializeVoiceAgent,
114
65
  tokenDetails,
@@ -118,278 +69,143 @@ function EmbedButton() {
118
69
  muteMic,
119
70
  unmuteMic,
120
71
  connectionState,
121
- roomRef,
122
- getPopupDescription
72
+ roomRef
123
73
  } = (0, _voiceagent.useVoiceAgent)();
124
- // State management
125
- const [configData, setConfigData] = (0, _react.useState)(null);
126
- const [popupDescription, setPopupDescription] = (0, _react.useState)('');
74
+
75
+ // ==================== LOCAL STATE ====================
127
76
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
128
- const [callDuration, setCallDuration] = (0, _react.useState)(0);
129
- const timerRef = (0, _react.useRef)(null);
130
77
  const lottieRef = (0, _react.useRef)(null);
78
+ const styles = (0, _react.useMemo)(() => (0, _EmbedButtonStyle.createEmbedButtonStyles)(defaultStyles), []);
131
79
 
132
- // Animation values
133
- const isPressed = useSharedValue(false);
134
- const offset = useSharedValue({
135
- x: 0,
136
- y: 0
80
+ // ==================== CUSTOM HOOKS ====================
81
+ const configData = (0, _EmbedButtonHooks.useConfigData)();
82
+ const {
83
+ callDuration,
84
+ resetDuration
85
+ } = (0, _EmbedButtonHooks.useCallDuration)(connectionState);
86
+ const {
87
+ handleStartCall,
88
+ handleEndCall,
89
+ handleMicToggle
90
+ } = (0, _EmbedButtonHooks.useCallManagement)({
91
+ initializeVoiceAgent,
92
+ endCall,
93
+ muteMic,
94
+ unmuteMic,
95
+ isMicMuted,
96
+ resetDuration,
97
+ setIsOpen
137
98
  });
138
- const start = useSharedValue({
139
- x: 0,
140
- y: 0
99
+ const {
100
+ isAutoOpen,
101
+ setIsAutoOpen
102
+ } = (0, _EmbedButtonHooks.useInactivityBehavior)({
103
+ configData,
104
+ isOpen,
105
+ isLoading,
106
+ hasActiveToken: !!tokenDetails?.token,
107
+ onStartCall: handleStartCall
141
108
  });
142
- const menuAnimation = useSharedValue(0);
143
- const buttonWidth = useSharedValue(BUTTON_WIDTH);
144
- const buttonScale = useSharedValue(1);
145
- // Styles
146
- const styles = (0, _EmbedButtonStyle.createEmbedButtonStyles)(defaultStyles);
147
- const [isAutoOpen, setIsAutoOpen] = (0, _react.useState)(false);
148
- (0, _react.useEffect)(() => {
149
- const autoOpenTimer = setTimeout(async () => {
150
- if (!isOpen) {
151
- const response = await getPopupDescription();
152
- if (response) {
153
- setPopupDescription(response);
154
- setIsAutoOpen(true);
155
- } else {
156
- // todo: handle no popup description found
157
- console.warn('No popup description found');
158
- }
159
- }
160
- }, 15000); // 15 seconds
161
109
 
162
- return () => {
163
- clearTimeout(autoOpenTimer);
164
- };
165
- }, [isOpen]);
166
-
167
- /**
168
- * Fetch agent configuration data
169
- */
170
- (0, _react.useEffect)(() => {
171
- const fetchAgentData = async () => {
172
- try {
173
- const data = await (0, _storeKey.getAgentData)('@config_data');
174
- setConfigData(data?.ui_config);
175
- } catch (error) {
176
- // todo: handle error fetching agent data
177
- }
178
- };
179
- fetchAgentData();
180
- }, []);
110
+ // ==================== ANIMATIONS ====================
111
+ const animationValues = (0, _EmbedButtonAnimations.useAnimationValues)();
112
+ const {
113
+ isPressed,
114
+ offset,
115
+ start,
116
+ menuAnimation,
117
+ buttonWidth,
118
+ buttonScale
119
+ } = animationValues;
120
+ (0, _EmbedButtonAnimations.useButtonAnimations)(isOpen, menuAnimation, buttonWidth);
121
+ (0, _EmbedButtonAnimations.useBreathingAnimation)(isOpen, isAutoOpen, buttonScale);
122
+ const buttonAnimatedStyles = (0, _EmbedButtonAnimations.useButtonAnimatedStyles)(isOpen, offset, buttonWidth, isPressed, buttonScale);
123
+ const popupAnimatedStyles = (0, _EmbedButtonAnimations.usePopupAnimatedStyles)(offset, isPressed);
124
+ const panGesture = (0, _react.useMemo)(() => (0, _EmbedButtonAnimations.createPanGesture)(isPressed, offset, start, isOpen, setIsAutoOpen), [isPressed, offset, start, isOpen, setIsAutoOpen]);
181
125
 
182
- /**
183
- * Set up a timer to track call duration when connected
184
- */
126
+ // ==================== AGENT EVENT EMISSIONS ====================
127
+ // Emit agent connected/disconnected events based on connection state
185
128
  (0, _react.useEffect)(() => {
186
- if (connectionState === 'connected' && !timerRef.current) {
187
- timerRef.current = setInterval(() => {
188
- setCallDuration(prev => prev + 1);
189
- }, 1000);
190
- } else if (connectionState !== 'connected' && timerRef.current) {
191
- clearInterval(timerRef.current);
192
- timerRef.current = null;
193
-
194
- // If we were previously connected and now disconnected, show an error
195
- if (callDuration > 0) {
196
- // todo: handle call disconnected
197
- }
198
- }
199
- return () => {
200
- if (timerRef.current) {
201
- clearInterval(timerRef.current);
202
- timerRef.current = null;
129
+ const emitConnectionEvent = async () => {
130
+ if (connectionState === 'connected') {
131
+ await _embedEvent.default.event.emit(_embedEvent.AgentEvent.AGENT_CONNECTED, {
132
+ timestamp: new Date().toISOString(),
133
+ metadata: {
134
+ callDuration: 0
135
+ }
136
+ });
137
+ } else if (connectionState === 'disconnected' && callDuration > 0) {
138
+ // Only emit disconnected if we were previously connected
139
+ await _embedEvent.default.event.emit(_embedEvent.AgentEvent.AGENT_DISCONNECTED, {
140
+ timestamp: new Date().toISOString(),
141
+ metadata: {
142
+ callDuration
143
+ }
144
+ });
203
145
  }
204
146
  };
205
- }, [connectionState, callDuration]);
206
-
207
- /**
208
- * Handle menu animation and button width transitions
209
- */
210
- (0, _react.useEffect)(() => {
211
- menuAnimation.value = withTiming(isOpen ? 0.8 : 0, {
212
- duration: 300
147
+ emitConnectionEvent().catch(error => {
148
+ console.error('Error emitting connection event:', error);
213
149
  });
214
- buttonWidth.value = withTiming(isOpen ? EXPANDED_WIDTH : BUTTON_WIDTH);
215
- }, [isOpen, menuAnimation, buttonWidth]);
150
+ }, [connectionState, callDuration]);
216
151
 
217
- // Add breathing animation when button is closed but isAutoOpen is true
152
+ // Emit popup visibility events when isAutoOpen changes
218
153
  (0, _react.useEffect)(() => {
219
- if (!isOpen && isAutoOpen) {
220
- // Start breathing animation with faster speed
221
- buttonScale.value = withRepeat(withSequence(withTiming(1.1, {
222
- duration: 1500,
223
- // Reduced from 1000ms to 600ms
224
- easing: Easing.inOut(Easing.ease)
225
- }), withTiming(1, {
226
- duration: 1500,
227
- // Reduced from 1000ms to 600ms
228
- easing: Easing.inOut(Easing.ease)
229
- })), -1,
230
- // Infinite repeat
231
- false // Don't reverse
232
- );
233
- } else {
234
- // Reset animation
235
- buttonScale.value = withTiming(1, {
236
- duration: 300
154
+ const emitPopupEvent = async () => {
155
+ await _embedEvent.default.event.emit(_embedEvent.AgentEvent.POPUP_MESSAGE_VISIBLE, {
156
+ value: isAutoOpen,
157
+ metadata: {
158
+ trigger: isAutoOpen ? 'auto_inactivity' : 'manual_dismiss'
159
+ }
237
160
  });
238
- }
239
- }, [isOpen, isAutoOpen]);
240
-
241
- /**
242
- * Animated styles for the button
243
- */
244
- const animatedStyles = useAnimatedStyle(() => {
245
- const maxX = SCREEN_WIDTH - (isOpen ? EXPANDED_WIDTH : BUTTON_WIDTH) - 35;
246
- const clampedX = Math.min(Math.max(offset.value.x, -maxX), 0);
247
- return {
248
- width: buttonWidth.value,
249
- height: BUTTON_HEIGHT,
250
- transform: [{
251
- translateX: clampedX
252
- }, {
253
- translateY: offset.value.y
254
- }, {
255
- scale: withSpring(isPressed.value ? 0.95 : buttonScale.value)
256
- }],
257
- justifyContent: isOpen ? 'space-between' : 'flex-start',
258
- overflow: 'hidden'
259
161
  };
260
- });
261
-
262
- /**
263
- * Animated styles for the text
264
- */
265
- const animatedTextStyles = useAnimatedStyle(() => {
266
- const maxX = SCREEN_WIDTH;
267
- const clampedX = Math.min(Math.max(offset.value.x, -maxX), 0);
268
- return {
269
- transform: [{
270
- translateX: clampedX
271
- }, {
272
- translateY: offset.value.y
273
- }, {
274
- scale: withSpring(isPressed.value ? 1 : 1)
275
- }]
276
- };
277
- });
278
-
279
- /**
280
- * Pan gesture handler for drag functionality
281
- */
282
- const gesture = _reactNativeGestureHandler.Gesture.Pan().onBegin(() => {
283
- isPressed.value = true;
284
- if (isAutoOpen) {
285
- runOnJS(setIsAutoOpen)(false);
286
- }
287
- }).onUpdate(e => {
288
- const maxX = SCREEN_WIDTH - (isOpen ? EXPANDED_WIDTH : BUTTON_WIDTH) - 0;
289
- const newX = Math.min(Math.max(e.translationX + start.value.x, -maxX), 0);
290
- const maxY = SCREEN_HEIGHT - 150;
291
- const newY = Math.min(Math.max(e.translationY + start.value.y, -maxY), 0);
292
- offset.value = {
293
- x: newX,
294
- y: newY
295
- };
296
- }).onEnd(() => {
297
- start.value = {
298
- x: offset.value.x,
299
- y: offset.value.y
300
- };
301
- }).onFinalize(() => {
302
- isPressed.value = false;
303
- });
162
+ emitPopupEvent().catch(error => {
163
+ console.error('Error emitting popup visibility event:', error);
164
+ });
165
+ }, [isAutoOpen]);
304
166
 
305
- /**
306
- * Handle button press events
307
- */
308
- const handlePress = () => {
167
+ // ==================== HANDLERS ====================
168
+ const handleButtonPress = () => {
309
169
  setIsOpen(!isOpen);
310
170
  setIsAutoOpen(false);
311
171
  };
312
- const handleStartCall = async () => {
313
- await (0, _permision.checkPermissions)();
314
- setCallDuration(0);
315
- await initializeVoiceAgent();
316
- };
317
-
318
- /**
319
- * Render the button icon/animation
320
- */
321
-
322
- const remoteSource = (0, _react.useMemo)(() => ({
323
- uri: configData?.icon_animation || AMPLIFY_ANIMATION
324
- }), [configData?.icon_animation]);
325
- const renderIcon = () => {
326
- // When isAutoOpen is true, we don't play the Lottie animation
327
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
328
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lottieReactNative.default, {
329
- ref: lottieRef,
330
- source: remoteSource,
331
- autoPlay: true,
332
- loop: true,
333
- style: styles.iconImage,
334
- enableMergePathsAndroidForKitKatAndAbove: true,
335
- enableSafeModeAndroid: true
336
- })
337
- });
338
- };
339
172
  const handleConnected = () => {
340
- // todo: handle call connected
341
- };
342
- const handleEndCall = async () => {
343
- setIsOpen(false);
344
- if (timerRef.current) {
345
- clearInterval(timerRef.current);
346
- timerRef.current = null;
347
- }
348
- setCallDuration(0);
349
- await endCall();
350
- };
351
- const handleMicToggle = () => {
352
- if (isMicMuted) {
353
- unmuteMic();
354
- } else {
355
- muteMic();
356
- }
173
+ // Hook for handling successful connection
357
174
  };
358
175
 
359
- // Format duration to MM:SS
360
- const formatDuration = seconds => {
361
- const minutes = Math.floor(seconds / 60);
362
- const remainingSeconds = seconds % 60;
363
- return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
364
- };
176
+ // ==================== COMPUTED VALUES ====================
177
+ const lottieSource = (0, _react.useMemo)(() => ({
178
+ uri: configData?.icon_animation || _EmbedButtonHelpers.ICON_URLS.AMPLIFY_ANIMATION
179
+ }), [configData?.icon_animation]);
180
+ const statusText = (0, _react.useMemo)(() => {
181
+ if (isLoading) return 'Connecting...';
182
+ if (tokenDetails?.token) return (0, _EmbedButtonHelpers.formatDuration)(callDuration);
183
+ return configData?.agent_type || 'Onboarding Agent';
184
+ }, [isLoading, tokenDetails?.token, callDuration, configData?.agent_type]);
185
+ const gradientColors = configData?.gradient || _EmbedButtonHelpers.DEFAULT_GRADIENT_COLORS;
186
+ const agentName = configData?.agent_name || 'Your AI Agent';
187
+ const popupText = configData?.popup_description || 'Any doubts? Ask agent now';
188
+ const connectButtonText = configData?.connect_button_title || 'Start Call';
365
189
 
366
- // Get the status text based on current state
367
- const getStatusText = () => {
368
- if (isLoading) {
369
- return 'Connecting...';
370
- } else if (tokenDetails?.token) {
371
- return `${formatDuration(callDuration)}`;
372
- } else {
373
- return configData?.agent_type || 'Onboarding Agent';
374
- }
375
- };
190
+ // ==================== EARLY RETURNS ====================
376
191
  if (!configData) return null;
192
+
193
+ // ==================== RENDER ====================
377
194
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
378
195
  style: styles.container,
379
- children: [isAutoOpen && !isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(Animated.View, {
380
- style: [animatedTextStyles, styles.popupContainer],
196
+ children: [isAutoOpen && !isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_EmbedButtonAnimations.Animated.View, {
197
+ style: [popupAnimatedStyles, styles.popupContainer],
381
198
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
382
199
  style: styles.popupText,
383
- children: popupDescription || 'Revrag'
200
+ children: popupText
384
201
  })
385
202
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeGestureHandler.GestureDetector, {
386
- gesture: gesture,
387
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Animated.View, {
388
- style: [styles.button, animatedStyles, styles.buttonContent, {
389
- pointerEvents: 'auto'
390
- }],
203
+ gesture: panGesture,
204
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_EmbedButtonAnimations.Animated.View, {
205
+ pointerEvents: "auto",
206
+ style: [styles.button, buttonAnimatedStyles, styles.buttonContent],
391
207
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNativeLinearGradient.default, {
392
- colors: configData?.gradient || GRADIENT_COLORS,
208
+ colors: gradientColors,
393
209
  start: {
394
210
  x: 0,
395
211
  y: 0
@@ -405,25 +221,33 @@ function EmbedButton() {
405
221
  y: 0.5
406
222
  },
407
223
  children: [tokenDetails?.token && /*#__PURE__*/(0, _jsxRuntime.jsx)(_EmbedVoice.default, {
408
- url: tokenDetails?.server_url,
409
- token: tokenDetails?.token,
224
+ url: tokenDetails.server_url,
225
+ token: tokenDetails.token,
410
226
  onDisconnected: handleEndCall,
411
227
  roomRef: roomRef,
412
228
  onConnected: handleConnected
413
229
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
414
- onPress: handlePress,
230
+ onPress: handleButtonPress,
415
231
  style: styles.pressable,
416
- children: renderIcon()
232
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_lottieReactNative.default, {
233
+ ref: lottieRef,
234
+ source: lottieSource,
235
+ autoPlay: true,
236
+ loop: true,
237
+ style: styles.iconImage,
238
+ enableMergePathsAndroidForKitKatAndAbove: true,
239
+ enableSafeModeAndroid: true
240
+ })
417
241
  }), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
418
242
  style: styles.expandedContentContainer,
419
243
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
420
244
  style: styles.leftContentSection,
421
245
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
422
246
  style: [styles.agentNameText, styles.leftAlignedText],
423
- children: configData?.agent_name || 'Revrag'
247
+ children: agentName
424
248
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
425
249
  style: [styles.leftAlignedText, styles.statusText],
426
- children: getStatusText()
250
+ children: statusText
427
251
  })]
428
252
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
429
253
  style: styles.middleContentSection,
@@ -439,7 +263,7 @@ function EmbedButton() {
439
263
  style: styles.startCallButton,
440
264
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
441
265
  style: styles.startCallText,
442
- children: configData?.start_call_text || 'Start Call'
266
+ children: connectButtonText
443
267
  })
444
268
  })
445
269
  }), tokenDetails?.token && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
@@ -449,7 +273,7 @@ function EmbedButton() {
449
273
  onPress: handleMicToggle,
450
274
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
451
275
  source: {
452
- uri: isMicMuted ? MIC_OFF_ICON : MIC_ON_ICON
276
+ uri: isMicMuted ? _EmbedButtonHelpers.ICON_URLS.MIC_OFF : _EmbedButtonHelpers.ICON_URLS.MIC_ON
453
277
  },
454
278
  style: styles.buttonImage
455
279
  })
@@ -458,7 +282,7 @@ function EmbedButton() {
458
282
  style: styles.endCallButton,
459
283
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
460
284
  source: {
461
- uri: END_CALL_ICON
285
+ uri: _EmbedButtonHelpers.ICON_URLS.END_CALL
462
286
  },
463
287
  style: styles.buttonImage
464
288
  })
@@ -471,7 +295,5 @@ function EmbedButton() {
471
295
  })]
472
296
  });
473
297
  }
474
-
475
- // Export default for easier imports
476
298
  var _default = exports.default = EmbedButton;
477
299
  //# sourceMappingURL=EmbedButton.js.map