@revrag-ai/embed-react-native 1.0.16 → 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.
- package/README.md +6 -108
- package/dist/commonjs/api/api.js +6 -5
- package/dist/commonjs/api/api.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedButton.js +138 -345
- package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedVoice.js +16 -4
- package/dist/commonjs/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/commonjs/context/EmbedProvider.js +638 -0
- package/dist/commonjs/context/EmbedProvider.js.map +1 -0
- package/dist/commonjs/events/embed.event.js +141 -54
- package/dist/commonjs/events/embed.event.js.map +1 -1
- package/dist/commonjs/hooks/EmbedButton.animations.js +181 -0
- package/dist/commonjs/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js +90 -0
- package/dist/commonjs/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js +165 -0
- package/dist/commonjs/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/commonjs/hooks/initialize.js +65 -25
- package/dist/commonjs/hooks/initialize.js.map +1 -1
- package/dist/commonjs/hooks/voiceagent.js +1 -18
- package/dist/commonjs/hooks/voiceagent.js.map +1 -1
- package/dist/commonjs/index.js +16 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/index.types.js +1 -2
- package/dist/commonjs/index.types.js.map +1 -1
- package/dist/commonjs/utils/constant.js +88 -0
- package/dist/commonjs/utils/constant.js.map +1 -0
- package/dist/commonjs/utils/reanimated.helper.js +2 -3
- package/dist/commonjs/utils/reanimated.helper.js.map +1 -1
- package/dist/module/api/api.js +6 -6
- package/dist/module/api/api.js.map +1 -1
- package/dist/module/components/Embed/EmbedButton.js +140 -347
- package/dist/module/components/Embed/EmbedButton.js.map +1 -1
- package/dist/module/components/Embed/EmbedVoice.js +16 -4
- package/dist/module/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/module/context/EmbedProvider.js +626 -0
- package/dist/module/context/EmbedProvider.js.map +1 -0
- package/dist/module/events/embed.event.js +143 -53
- package/dist/module/events/embed.event.js.map +1 -1
- package/dist/module/hooks/EmbedButton.animations.js +172 -0
- package/dist/module/hooks/EmbedButton.animations.js.map +1 -0
- package/dist/module/hooks/EmbedButton.helpers.js +80 -0
- package/dist/module/hooks/EmbedButton.helpers.js.map +1 -0
- package/dist/module/hooks/EmbedButton.hooks.js +160 -0
- package/dist/module/hooks/EmbedButton.hooks.js.map +1 -0
- package/dist/module/hooks/initialize.js +66 -26
- package/dist/module/hooks/initialize.js.map +1 -1
- package/dist/module/hooks/voiceagent.js +1 -17
- package/dist/module/hooks/voiceagent.js.map +1 -1
- package/dist/module/index.js +4 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/index.types.js +1 -2
- package/dist/module/index.types.js.map +1 -1
- package/dist/module/utils/constant.js +82 -0
- package/dist/module/utils/constant.js.map +1 -0
- package/dist/module/utils/reanimated.helper.js +2 -3
- package/dist/module/utils/reanimated.helper.js.map +1 -1
- package/dist/typescript/src/api/api.d.ts +4 -3
- package/dist/typescript/src/api/api.d.ts.map +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts +1 -1
- package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts +5 -25
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedVoice.d.ts.map +1 -1
- package/dist/typescript/src/context/EmbedProvider.d.ts +306 -0
- package/dist/typescript/src/context/EmbedProvider.d.ts.map +1 -0
- package/dist/typescript/src/events/embed.event.d.ts +74 -10
- package/dist/typescript/src/events/embed.event.d.ts.map +1 -1
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts +38 -0
- package/dist/typescript/src/hooks/EmbedButton.animations.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.helpers.d.ts.map +1 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts +49 -0
- package/dist/typescript/src/hooks/EmbedButton.hooks.d.ts.map +1 -0
- package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/voiceagent.d.ts.map +1 -1
- package/dist/typescript/src/index.d.ts +10 -4
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/index.types.d.ts +2 -3
- package/dist/typescript/src/index.types.d.ts.map +1 -1
- package/dist/typescript/src/utils/constant.d.ts +45 -0
- package/dist/typescript/src/utils/constant.d.ts.map +1 -0
- package/dist/typescript/src/utils/reanimated.helper.d.ts.map +1 -1
- package/package.json +6 -3
- package/react-native.config.js +1 -0
- package/dist/commonjs/events/eventEmitter.js +0 -43
- package/dist/commonjs/events/eventEmitter.js.map +0 -1
- package/dist/module/events/eventEmitter.js +0 -39
- package/dist/module/events/eventEmitter.js.map +0 -1
- package/dist/typescript/src/events/eventEmitter.d.ts +0 -9
- package/dist/typescript/src/events/eventEmitter.d.ts.map +0 -1
|
@@ -2,69 +2,164 @@
|
|
|
2
2
|
|
|
3
3
|
import { getAgentData, setAgentData } from "../store/store.key.js";
|
|
4
4
|
import { APIService } from "../api/api.js";
|
|
5
|
-
import
|
|
6
|
-
// Predefined event keys
|
|
5
|
+
import { buildEventPayload } from "../utils/constant.js";
|
|
6
|
+
// Predefined event keys for sending data to the agent
|
|
7
7
|
export let EventKeys = /*#__PURE__*/function (EventKeys) {
|
|
8
8
|
EventKeys["USER_DATA"] = "user_data";
|
|
9
9
|
EventKeys["SCREEN_STATE"] = "screen_state";
|
|
10
10
|
EventKeys["OFFER_STATE"] = "offer_state";
|
|
11
|
-
EventKeys["
|
|
11
|
+
EventKeys["CUSTOM_EVENT"] = "custom_event";
|
|
12
12
|
EventKeys["FORM_STATE"] = "form_state";
|
|
13
|
+
EventKeys["ACTION_STATE"] = "action_state";
|
|
14
|
+
EventKeys["ERROR_STATE"] = "error_state";
|
|
15
|
+
EventKeys["SUCCESS_STATE"] = "success_state";
|
|
16
|
+
EventKeys["WARNING_STATE"] = "warning_state";
|
|
17
|
+
EventKeys["INFO_STATE"] = "info_state";
|
|
18
|
+
EventKeys["DEBUG_STATE"] = "debug_state";
|
|
13
19
|
return EventKeys;
|
|
14
20
|
}({});
|
|
21
|
+
|
|
22
|
+
// Agent event keys for listening to agent state changes
|
|
15
23
|
export let AgentEvent = /*#__PURE__*/function (AgentEvent) {
|
|
16
24
|
AgentEvent["AGENT_CONNECTED"] = "agent_connected";
|
|
17
25
|
AgentEvent["AGENT_DISCONNECTED"] = "agent_disconnected";
|
|
18
26
|
AgentEvent["POPUP_MESSAGE_VISIBLE"] = "popup_message_visible";
|
|
19
27
|
return AgentEvent;
|
|
20
28
|
}({});
|
|
21
|
-
// // Event data structure for listener events
|
|
22
|
-
// export interface EmbedEventData {
|
|
23
|
-
// timestamp: number; // Unix timestamp when event occurred
|
|
24
|
-
// value: boolean; // Boolean state (connected/visible = true)
|
|
25
|
-
// metadata?: {
|
|
26
|
-
// // Additional context data
|
|
27
|
-
// connectionState?: string; // LiveKit connection state
|
|
28
|
-
// roomId?: string; // Voice room identifier
|
|
29
|
-
// trigger?: 'user_interaction' | 'auto_open' | 'call_ended';
|
|
30
|
-
// previousState?: boolean; // Previous state before change
|
|
31
|
-
// // ... other contextual information
|
|
32
|
-
// [key: string]: any;
|
|
33
|
-
// };
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// Listener callback type
|
|
37
|
-
// export type EmbedEventListener = (data: EmbedEventData) => void;
|
|
38
29
|
|
|
30
|
+
// Event data interfaces
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Agent Event Emitter
|
|
34
|
+
* Handles listening to agent state changes (connection, disconnection, popup visibility)
|
|
35
|
+
* Also sends agent events to the backend API
|
|
36
|
+
*/
|
|
37
|
+
class AgentEventEmitter {
|
|
38
|
+
agentListeners = {};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Add an event listener for agent events
|
|
42
|
+
* @param eventKey - The agent event to listen for
|
|
43
|
+
* @param callback - Callback function to execute when event fires
|
|
44
|
+
*/
|
|
45
|
+
on(eventKey, callback) {
|
|
46
|
+
if (!this.agentListeners[eventKey]) {
|
|
47
|
+
this.agentListeners[eventKey] = [];
|
|
48
|
+
}
|
|
49
|
+
this.agentListeners[eventKey]?.push(callback);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Remove an event listener for agent events
|
|
54
|
+
* @param eventKey - The agent event to stop listening to
|
|
55
|
+
* @param callback - The callback function to remove
|
|
56
|
+
*/
|
|
57
|
+
off(eventKey, callback) {
|
|
58
|
+
if (!this.agentListeners[eventKey]) return;
|
|
59
|
+
const index = this.agentListeners[eventKey]?.indexOf(callback);
|
|
60
|
+
if (index !== undefined && index > -1) {
|
|
61
|
+
this.agentListeners[eventKey]?.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Emit an agent event to all registered listeners AND send to backend
|
|
67
|
+
* @param eventKey - The agent event to emit
|
|
68
|
+
* @param data - Data to pass to listeners
|
|
69
|
+
* @internal - Used internally by the library
|
|
70
|
+
*/
|
|
71
|
+
async emit(eventKey, data) {
|
|
72
|
+
// Trigger local event listeners first
|
|
73
|
+
this.agentListeners[eventKey]?.forEach(callback => {
|
|
74
|
+
try {
|
|
75
|
+
callback(data);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error(`Error in agent event listener for ${eventKey}:`, error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Send to backend API
|
|
82
|
+
await this.sendToBackend(eventKey, data);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Send agent event data to backend API
|
|
87
|
+
* @param eventKey - The agent event type
|
|
88
|
+
* @param data - Event data
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
async sendToBackend(eventKey, data) {
|
|
92
|
+
try {
|
|
93
|
+
// Get user identity to include app_user_id
|
|
94
|
+
const userIdentity = await getAgentData(EventKeys.USER_DATA);
|
|
95
|
+
if (!userIdentity?.app_user_id) {
|
|
96
|
+
console.warn(`[AgentEvent] Cannot send ${eventKey} to backend: User identity not found`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Prepare payload with app_user_id
|
|
101
|
+
const payload = {
|
|
102
|
+
...data,
|
|
103
|
+
app_user_id: userIdentity.app_user_id,
|
|
104
|
+
eventKey: eventKey,
|
|
105
|
+
eventType: 'agent_event'
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Send to API
|
|
109
|
+
const apiService = APIService.getInstance();
|
|
110
|
+
const paramsData = buildEventPayload(payload);
|
|
111
|
+
const response = await apiService.updateUserData(paramsData);
|
|
112
|
+
if (!response.success) {
|
|
113
|
+
console.error(`[AgentEvent] Failed to send ${eventKey} to backend:`, response.error);
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error(`[AgentEvent] Error sending ${eventKey} to backend:`, error);
|
|
117
|
+
// Fail silently - agent events should not break the app
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Remove all listeners for a specific event
|
|
123
|
+
* @param eventKey - The agent event to clear listeners for
|
|
124
|
+
*/
|
|
125
|
+
removeAllListeners(eventKey) {
|
|
126
|
+
if (eventKey) {
|
|
127
|
+
delete this.agentListeners[eventKey];
|
|
128
|
+
} else {
|
|
129
|
+
this.agentListeners = {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
39
133
|
class Embed {
|
|
40
134
|
events = {};
|
|
41
|
-
|
|
42
|
-
|
|
135
|
+
|
|
136
|
+
// Agent event emitter for listening to agent state changes
|
|
137
|
+
|
|
138
|
+
constructor() {
|
|
139
|
+
this.event = new AgentEventEmitter();
|
|
140
|
+
}
|
|
43
141
|
|
|
44
142
|
// Automatically adds a default listener if none exists
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// }
|
|
54
|
-
// }
|
|
143
|
+
ensureDefaultListener(eventKey) {
|
|
144
|
+
if (!this.events[eventKey]) {
|
|
145
|
+
this.events[eventKey] = [data => {
|
|
146
|
+
// todo: handle default event
|
|
147
|
+
console.info('default event this', data);
|
|
148
|
+
}];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
55
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Send an event to the AI agent
|
|
154
|
+
* @param eventKey - The event type to send
|
|
155
|
+
* @param data - Event data payload
|
|
156
|
+
*/
|
|
56
157
|
async Event(eventKey, data) {
|
|
57
|
-
console.log('eventKey', eventKey, data);
|
|
58
158
|
if (!Object.values(EventKeys).includes(eventKey)) {
|
|
59
159
|
// todo: handle invalid event key
|
|
60
160
|
throw new Error(`Invalid event key: ${eventKey}. Must be one of: ${Object.values(EventKeys).join(', ')}`);
|
|
61
161
|
}
|
|
62
162
|
const key = eventKey;
|
|
63
|
-
|
|
64
|
-
// Restrict all events except USER_DATA until USER_DATA is initialized
|
|
65
|
-
if (key !== EventKeys.USER_DATA && !this.userDataInitialized) {
|
|
66
|
-
throw new Error(`Cannot trigger ${eventKey} event. USER_DATA event must be triggered first to initialize user identity.`);
|
|
67
|
-
}
|
|
68
163
|
if (key !== EventKeys.USER_DATA) {
|
|
69
164
|
const userIdentity = await getAgentData(EventKeys.USER_DATA);
|
|
70
165
|
if (userIdentity) {
|
|
@@ -75,26 +170,23 @@ class Embed {
|
|
|
75
170
|
}
|
|
76
171
|
|
|
77
172
|
// Ensure a default listener is registered if not already
|
|
78
|
-
|
|
173
|
+
this.ensureDefaultListener(key);
|
|
79
174
|
|
|
80
175
|
// Trigger API call
|
|
81
176
|
try {
|
|
82
177
|
const apiService = APIService.getInstance();
|
|
178
|
+
const paramsData = buildEventPayload({
|
|
179
|
+
...data,
|
|
180
|
+
eventKey: key
|
|
181
|
+
});
|
|
83
182
|
const response = await apiService.updateUserData({
|
|
84
|
-
|
|
85
|
-
data
|
|
183
|
+
...paramsData
|
|
86
184
|
});
|
|
87
185
|
if (!response.success) {
|
|
88
186
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
89
187
|
}
|
|
90
188
|
setAgentData(data, key);
|
|
91
|
-
|
|
92
|
-
// Mark USER_DATA as initialized after successful processing
|
|
93
|
-
if (key === EventKeys.USER_DATA) {
|
|
94
|
-
this.userDataInitialized = true;
|
|
95
|
-
}
|
|
96
189
|
} catch (error) {
|
|
97
|
-
console.log('data_Event_error', key, data);
|
|
98
190
|
throw new Error(`Failed to trigger API for event: ${eventKey}`);
|
|
99
191
|
// todo: handle error triggering API
|
|
100
192
|
}
|
|
@@ -103,18 +195,16 @@ class Embed {
|
|
|
103
195
|
this.events[key]?.forEach(callback => callback(data));
|
|
104
196
|
}
|
|
105
197
|
|
|
106
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Add listener for data events (legacy support)
|
|
200
|
+
* @deprecated Use event.on() for agent events instead
|
|
201
|
+
*/
|
|
107
202
|
on(eventKey, callback) {
|
|
108
203
|
if (!this.events[eventKey]) {
|
|
109
204
|
this.events[eventKey] = [];
|
|
110
205
|
}
|
|
111
206
|
this.events[eventKey]?.push(callback);
|
|
112
207
|
}
|
|
113
|
-
|
|
114
|
-
// Check if USER_DATA has been initialized
|
|
115
|
-
isUserDataInitialized() {
|
|
116
|
-
return this.userDataInitialized;
|
|
117
|
-
}
|
|
118
208
|
}
|
|
119
209
|
const embed = new Embed();
|
|
120
210
|
export default embed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAgentData","setAgentData","APIService","
|
|
1
|
+
{"version":3,"names":["getAgentData","setAgentData","APIService","buildEventPayload","EventKeys","AgentEvent","AgentEventEmitter","agentListeners","on","eventKey","callback","push","off","index","indexOf","undefined","splice","emit","data","forEach","error","console","sendToBackend","userIdentity","USER_DATA","app_user_id","warn","payload","eventType","apiService","getInstance","paramsData","response","updateUserData","success","removeAllListeners","Embed","events","constructor","event","ensureDefaultListener","info","Event","Object","values","includes","Error","join","key","embed"],"sourceRoot":"../../../src","sources":["events/embed.event.ts"],"mappings":";;AAAA,SAASA,YAAY,EAAEC,YAAY,QAAQ,uBAAoB;AAC/D,SAASC,UAAU,QAAQ,eAAY;AACvC,SAASC,iBAAiB,QAAQ,sBAAmB;AAIrD;AACA,WAAYC,SAAS,0BAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAATA,SAAS;EAAA,OAATA,SAAS;AAAA;;AAcrB;AACA,WAAYC,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA;;AAMtB;;AAmBA;AACA;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,CAAC;EACdC,cAAc,GAA8C,CAAC,CAAC;;EAEtE;AACF;AACA;AACA;AACA;EACEC,EAAEA,CAACC,QAAoB,EAAEC,QAAuB,EAAQ;IACtD,IAAI,CAAC,IAAI,CAACH,cAAc,CAACE,QAAQ,CAAC,EAAE;MAClC,IAAI,CAACF,cAAc,CAACE,QAAQ,CAAC,GAAG,EAAE;IACpC;IACA,IAAI,CAACF,cAAc,CAACE,QAAQ,CAAC,EAAEE,IAAI,CAACD,QAAQ,CAAC;EAC/C;;EAEA;AACF;AACA;AACA;AACA;EACEE,GAAGA,CAACH,QAAoB,EAAEC,QAAu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,EAAEC,QAAuB,EAAE;IAC/C,IAAI,CAAC,IAAI,CAAC2B,MAAM,CAAC5B,QAAQ,CAAC,EAAE;MAC1B,IAAI,CAAC4B,MAAM,CAAC5B,QAAQ,CAAC,GAAG,EAAE;IAC5B;IACA,IAAI,CAAC4B,MAAM,CAAC5B,QAAQ,CAAC,EAAEE,IAAI,CAACD,QAAQ,CAAC;EACvC;AACF;AAEA,MAAMuC,KAAK,GAAG,IAAIb,KAAK,CAAC,CAAC;AACzB,eAAea,KAAK","ignoreList":[]}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file EmbedButton.animations.ts
|
|
5
|
+
* @description Animation logic and hooks for the EmbedButton component
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
10
|
+
import { getReanimatedAPI, showReanimatedSetupError } from "../utils/reanimated.helper.js";
|
|
11
|
+
import { BUTTON_DIMENSIONS, calculateMaxX, calculateMaxY, clamp, SCREEN_WIDTH } from "./EmbedButton.helpers.js";
|
|
12
|
+
|
|
13
|
+
// Get reanimated API with fallbacks
|
|
14
|
+
const {
|
|
15
|
+
useSharedValue,
|
|
16
|
+
useAnimatedStyle,
|
|
17
|
+
withTiming,
|
|
18
|
+
withSpring,
|
|
19
|
+
withRepeat,
|
|
20
|
+
withSequence,
|
|
21
|
+
runOnJS,
|
|
22
|
+
Easing,
|
|
23
|
+
Animated,
|
|
24
|
+
isAvailable: isReanimatedAvailable
|
|
25
|
+
} = getReanimatedAPI();
|
|
26
|
+
|
|
27
|
+
// Show warning if reanimated is not available
|
|
28
|
+
if (!isReanimatedAvailable) {
|
|
29
|
+
showReanimatedSetupError();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Export the Animated component for use in the main component
|
|
33
|
+
export { Animated };
|
|
34
|
+
|
|
35
|
+
// ==================== ANIMATION VALUES HOOK ====================
|
|
36
|
+
/**
|
|
37
|
+
* Hook to initialize and manage all animation shared values
|
|
38
|
+
*/
|
|
39
|
+
export const useAnimationValues = () => {
|
|
40
|
+
const isPressed = useSharedValue(false);
|
|
41
|
+
const offset = useSharedValue({
|
|
42
|
+
x: 0,
|
|
43
|
+
y: 0
|
|
44
|
+
});
|
|
45
|
+
const start = useSharedValue({
|
|
46
|
+
x: 0,
|
|
47
|
+
y: 0
|
|
48
|
+
});
|
|
49
|
+
const menuAnimation = useSharedValue(0);
|
|
50
|
+
const buttonWidth = useSharedValue(BUTTON_DIMENSIONS.WIDTH);
|
|
51
|
+
const buttonScale = useSharedValue(1);
|
|
52
|
+
return {
|
|
53
|
+
isPressed,
|
|
54
|
+
offset,
|
|
55
|
+
start,
|
|
56
|
+
menuAnimation,
|
|
57
|
+
buttonWidth,
|
|
58
|
+
buttonScale
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// ==================== BUTTON ANIMATIONS ====================
|
|
63
|
+
/**
|
|
64
|
+
* Hook to handle button expand/collapse animations
|
|
65
|
+
*/
|
|
66
|
+
export const useButtonAnimations = (isOpen, menuAnimation, buttonWidth) => {
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
menuAnimation.value = withTiming(isOpen ? 0.8 : 0, {
|
|
69
|
+
duration: 300
|
|
70
|
+
});
|
|
71
|
+
buttonWidth.value = withTiming(isOpen ? BUTTON_DIMENSIONS.EXPANDED_WIDTH : BUTTON_DIMENSIONS.WIDTH);
|
|
72
|
+
}, [isOpen, menuAnimation, buttonWidth]);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ==================== BREATHING ANIMATION ====================
|
|
76
|
+
/**
|
|
77
|
+
* Hook to handle breathing animation when auto-popup is shown
|
|
78
|
+
*/
|
|
79
|
+
export const useBreathingAnimation = (isOpen, isAutoOpen, buttonScale) => {
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!isOpen && isAutoOpen) {
|
|
82
|
+
// Start breathing animation
|
|
83
|
+
buttonScale.value = withRepeat(withSequence(withTiming(1.1, {
|
|
84
|
+
duration: 1500,
|
|
85
|
+
easing: Easing.inOut(Easing.ease)
|
|
86
|
+
}), withTiming(1, {
|
|
87
|
+
duration: 1500,
|
|
88
|
+
easing: Easing.inOut(Easing.ease)
|
|
89
|
+
})), -1,
|
|
90
|
+
// Infinite repeat
|
|
91
|
+
false);
|
|
92
|
+
} else {
|
|
93
|
+
// Reset animation
|
|
94
|
+
buttonScale.value = withTiming(1, {
|
|
95
|
+
duration: 300
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, [buttonScale, isAutoOpen, isOpen]);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// ==================== ANIMATED STYLES ====================
|
|
102
|
+
/**
|
|
103
|
+
* Hook to create animated styles for the button
|
|
104
|
+
*/
|
|
105
|
+
export const useButtonAnimatedStyles = (isOpen, offset, buttonWidth, isPressed, buttonScale) => {
|
|
106
|
+
return useAnimatedStyle(() => {
|
|
107
|
+
const maxX = calculateMaxX(isOpen);
|
|
108
|
+
const clampedX = clamp(offset.value.x, -maxX, 0);
|
|
109
|
+
return {
|
|
110
|
+
width: buttonWidth.value,
|
|
111
|
+
height: BUTTON_DIMENSIONS.HEIGHT,
|
|
112
|
+
transform: [{
|
|
113
|
+
translateX: clampedX
|
|
114
|
+
}, {
|
|
115
|
+
translateY: offset.value.y
|
|
116
|
+
}, {
|
|
117
|
+
scale: withSpring(isPressed.value ? 0.95 : buttonScale.value)
|
|
118
|
+
}],
|
|
119
|
+
justifyContent: isOpen ? 'space-between' : 'flex-start',
|
|
120
|
+
overflow: 'hidden'
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Hook to create animated styles for the popup text
|
|
127
|
+
*/
|
|
128
|
+
export const usePopupAnimatedStyles = (offset, isPressed) => {
|
|
129
|
+
return useAnimatedStyle(() => {
|
|
130
|
+
const maxX = SCREEN_WIDTH;
|
|
131
|
+
const clampedX = clamp(offset.value.x, -maxX, 0);
|
|
132
|
+
return {
|
|
133
|
+
transform: [{
|
|
134
|
+
translateX: clampedX
|
|
135
|
+
}, {
|
|
136
|
+
translateY: offset.value.y
|
|
137
|
+
}, {
|
|
138
|
+
scale: withSpring(isPressed.value ? 1 : 1)
|
|
139
|
+
}]
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// ==================== GESTURE HANDLER ====================
|
|
145
|
+
/**
|
|
146
|
+
* Create pan gesture for drag functionality
|
|
147
|
+
*/
|
|
148
|
+
export const createPanGesture = (isPressed, offset, start, isOpen, setIsAutoOpen) => {
|
|
149
|
+
return Gesture.Pan().onBegin(() => {
|
|
150
|
+
isPressed.value = true;
|
|
151
|
+
if (setIsAutoOpen) {
|
|
152
|
+
runOnJS(setIsAutoOpen)(false);
|
|
153
|
+
}
|
|
154
|
+
}).onUpdate(e => {
|
|
155
|
+
const maxX = calculateMaxX(isOpen);
|
|
156
|
+
const maxY = calculateMaxY();
|
|
157
|
+
const newX = clamp(e.translationX + start.value.x, -maxX, 0);
|
|
158
|
+
const newY = clamp(e.translationY + start.value.y, -maxY, 0);
|
|
159
|
+
offset.value = {
|
|
160
|
+
x: newX,
|
|
161
|
+
y: newY
|
|
162
|
+
};
|
|
163
|
+
}).onEnd(() => {
|
|
164
|
+
start.value = {
|
|
165
|
+
x: offset.value.x,
|
|
166
|
+
y: offset.value.y
|
|
167
|
+
};
|
|
168
|
+
}).onFinalize(() => {
|
|
169
|
+
isPressed.value = false;
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
//# sourceMappingURL=EmbedButton.animations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","Gesture","getReanimatedAPI","showReanimatedSetupError","BUTTON_DIMENSIONS","calculateMaxX","calculateMaxY","clamp","SCREEN_WIDTH","useSharedValue","useAnimatedStyle","withTiming","withSpring","withRepeat","withSequence","runOnJS","Easing","Animated","isAvailable","isReanimatedAvailable","useAnimationValues","isPressed","offset","x","y","start","menuAnimation","buttonWidth","WIDTH","buttonScale","useButtonAnimations","isOpen","value","duration","EXPANDED_WIDTH","useBreathingAnimation","isAutoOpen","easing","inOut","ease","useButtonAnimatedStyles","maxX","clampedX","width","height","HEIGHT","transform","translateX","translateY","scale","justifyContent","overflow","usePopupAnimatedStyles","createPanGesture","setIsAutoOpen","Pan","onBegin","onUpdate","e","maxY","newX","translationX","newY","translationY","onEnd","onFinalize"],"sourceRoot":"../../../src","sources":["hooks/EmbedButton.animations.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SACEC,gBAAgB,EAChBC,wBAAwB,QACnB,+BAA4B;AACnC,SACEC,iBAAiB,EACjBC,aAAa,EACbC,aAAa,EACbC,KAAK,EACLC,YAAY,QACP,0BAAuB;;AAE9B;AACA,MAAM;EACJC,cAAc;EACdC,gBAAgB;EAChBC,UAAU;EACVC,UAAU;EACVC,UAAU;EACVC,YAAY;EACZC,OAAO;EACPC,MAAM;EACNC,QAAQ;EACRC,WAAW,EAAEC;AACf,CAAC,GAAGjB,gBAAgB,CAAC,CAAC;;AAEtB;AACA,IAAI,CAACiB,qBAAqB,EAAE;EAC1BhB,wBAAwB,CAAC,CAAC;AAC5B;;AAEA;AACA,SAASc,QAAQ;;AAEjB;AACA;AACA;AACA;AACA,OAAO,MAAMG,kBAAkB,GAAGA,CAAA,KAAM;EACtC,MAAMC,SAAS,GAAGZ,cAAc,CAAC,KAAK,CAAC;EACvC,MAAMa,MAAM,GAAGb,cAAc,CAAC;IAAEc,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC,CAAC;EAC7C,MAAMC,KAAK,GAAGhB,cAAc,CAAC;IAAEc,CAAC,EAAE,CAAC;IAAEC,CAAC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KAAK,CAACO,KAAK,GAAG;MACZT,CAAC,EAAED,MAAM,CAACU,KAAK,CAACT,CAAC;MACjBC,CAAC,EAAEF,MAAM,CAACU,KAAK,CAACR;IAClB,CAAC;EACH,CAAC,CAAC,CACDyC,UAAU,CAAC,MAAM;IAChB5C,SAAS,CAACW,KAAK,GAAG,KAAK;EACzB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file EmbedButton.helpers.ts
|
|
5
|
+
* @description Helper functions and utilities for the EmbedButton component
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Dimensions } from 'react-native';
|
|
9
|
+
|
|
10
|
+
// ==================== CONSTANTS ====================
|
|
11
|
+
export const {
|
|
12
|
+
width: SCREEN_WIDTH,
|
|
13
|
+
height: SCREEN_HEIGHT
|
|
14
|
+
} = Dimensions.get('window');
|
|
15
|
+
export const BUTTON_DIMENSIONS = {
|
|
16
|
+
WIDTH: 60,
|
|
17
|
+
HEIGHT: 60,
|
|
18
|
+
EXPANDED_WIDTH: SCREEN_WIDTH * 0.9
|
|
19
|
+
};
|
|
20
|
+
export const ICON_URLS = {
|
|
21
|
+
MIC_ON: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/Mute+button.png',
|
|
22
|
+
MIC_OFF: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/unmute.png',
|
|
23
|
+
END_CALL: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/end+button.png',
|
|
24
|
+
AMPLIFY_ANIMATION: 'https://revrag-dev.s3.ap-south-1.amazonaws.com/Avatars/amplify.json'
|
|
25
|
+
};
|
|
26
|
+
export const DEFAULT_GRADIENT_COLORS = ['#1E0844', '#B391F3'];
|
|
27
|
+
export const DEFAULT_POPUP_DELAY_MS = 15000;
|
|
28
|
+
|
|
29
|
+
// ==================== TYPES ====================
|
|
30
|
+
|
|
31
|
+
// ==================== HELPER FUNCTIONS ====================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Safely parse delay value to ensure it's a valid number
|
|
35
|
+
*/
|
|
36
|
+
export const parseDelayMs = delay => {
|
|
37
|
+
if (typeof delay === 'number') {
|
|
38
|
+
return delay;
|
|
39
|
+
}
|
|
40
|
+
const parsed = Number(delay);
|
|
41
|
+
return Number.isFinite(parsed) ? parsed : DEFAULT_POPUP_DELAY_MS;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Format seconds to MM:SS format
|
|
46
|
+
*/
|
|
47
|
+
export const formatDuration = seconds => {
|
|
48
|
+
const minutes = Math.floor(seconds / 60);
|
|
49
|
+
const remainingSeconds = seconds % 60;
|
|
50
|
+
return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Calculate the max X position for button drag constraints
|
|
55
|
+
*/
|
|
56
|
+
export const calculateMaxX = isOpen => {
|
|
57
|
+
'worklet';
|
|
58
|
+
|
|
59
|
+
const width = isOpen ? BUTTON_DIMENSIONS.EXPANDED_WIDTH : BUTTON_DIMENSIONS.WIDTH;
|
|
60
|
+
return SCREEN_WIDTH - width - 35;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Calculate the max Y position for button drag constraints
|
|
65
|
+
*/
|
|
66
|
+
export const calculateMaxY = () => {
|
|
67
|
+
'worklet';
|
|
68
|
+
|
|
69
|
+
return SCREEN_HEIGHT - 150;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Clamp a value between a min and max
|
|
74
|
+
*/
|
|
75
|
+
export const clamp = (value, min, max) => {
|
|
76
|
+
'worklet';
|
|
77
|
+
|
|
78
|
+
return Math.min(Math.max(value, min), max);
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=EmbedButton.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Dimensions","width","SCREEN_WIDTH","height","SCREEN_HEIGHT","get","BUTTON_DIMENSIONS","WIDTH","HEIGHT","EXPANDED_WIDTH","ICON_URLS","MIC_ON","MIC_OFF","END_CALL","AMPLIFY_ANIMATION","DEFAULT_GRADIENT_COLORS","DEFAULT_POPUP_DELAY_MS","parseDelayMs","delay","parsed","Number","isFinite","formatDuration","seconds","minutes","Math","floor","remainingSeconds","toString","padStart","calculateMaxX","isOpen","calculateMaxY","clamp","value","min","max"],"sourceRoot":"../../../src","sources":["hooks/EmbedButton.helpers.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,SAASA,UAAU,QAAQ,cAAc;;AAEzC;AACA,OAAO,MAAM;EAAEC,KAAK,EAAEC,YAAY;EAAEC,MAAM,EAAEC;AAAc,CAAC,GACzDJ,UAAU,CAACK,GAAG,CAAC,QAAQ,CAAC;AAE1B,OAAO,MAAMC,iBAAiB,GAAG;EAC/BC,KAAK,EAAE,EAAE;EACTC,MAAM,EAAE,EAAE;EACVC,cAAc,EAAEP,YAAY,GAAG;AACjC,CAAU;AAEV,OAAO,MAAMQ,SAAS,GAAG;EACvBC,MAAM,EACJ,wEAAwE;EAC1EC,OAAO,EAAE,mEAAmE;EAC5EC,QAAQ,EACN,uEAAuE;EACzEC,iBAAiB,EACf;AACJ,CAAU;AAEV,OAAO,MAAMC,uBAAuB,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;AAE7D,OAAO,MAAMC,sBAAsB,GAAG,KAAK;;AAE3C;;AAYA;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAIC,KAAkC,IAAa;EAC1E,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC7B,OAAOA,KAAK;EACd;EAEA,MAAMC,MAAM,GAAGC,MAAM,CAACF,KAAK,CAAC;EAC5B,OAAOE,MAAM,CAACC,QAAQ,CAACF,MAAM,CAAC,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