@revrag-ai/embed-react-native 1.0.12 → 1.0.14
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/dist/commonjs/api/api.error.js +233 -0
- package/dist/commonjs/api/api.error.js.map +1 -0
- package/dist/commonjs/api/api.js +38 -94
- package/dist/commonjs/api/api.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedAudioWave.js +10 -1
- package/dist/commonjs/components/Embed/EmbedAudioWave.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedButton.js +52 -88
- package/dist/commonjs/components/Embed/EmbedButton.js.map +1 -1
- package/dist/commonjs/components/Embed/EmbedVoice.js +7 -9
- package/dist/commonjs/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/commonjs/components/styles/EmbedButton.style.js +237 -54
- package/dist/commonjs/components/styles/EmbedButton.style.js.map +1 -1
- package/dist/commonjs/events/embed.event.js +7 -6
- package/dist/commonjs/events/embed.event.js.map +1 -1
- package/dist/commonjs/hooks/initialize.js +18 -7
- package/dist/commonjs/hooks/initialize.js.map +1 -1
- package/dist/commonjs/hooks/voiceagent.js +20 -55
- package/dist/commonjs/hooks/voiceagent.js.map +1 -1
- package/dist/commonjs/index.types.js +0 -1
- package/dist/commonjs/index.types.js.map +1 -1
- package/dist/commonjs/utils/reanimated.helper.js.map +1 -1
- package/dist/module/api/api.error.js +226 -0
- package/dist/module/api/api.error.js.map +1 -0
- package/dist/module/api/api.js +36 -93
- package/dist/module/api/api.js.map +1 -1
- package/dist/module/components/Embed/EmbedAudioWave.js +10 -1
- package/dist/module/components/Embed/EmbedAudioWave.js.map +1 -1
- package/dist/module/components/Embed/EmbedButton.js +52 -88
- package/dist/module/components/Embed/EmbedButton.js.map +1 -1
- package/dist/module/components/Embed/EmbedVoice.js +7 -9
- package/dist/module/components/Embed/EmbedVoice.js.map +1 -1
- package/dist/module/components/styles/EmbedButton.style.js +236 -53
- package/dist/module/components/styles/EmbedButton.style.js.map +1 -1
- package/dist/module/events/embed.event.js +7 -6
- package/dist/module/events/embed.event.js.map +1 -1
- package/dist/module/hooks/initialize.js +18 -7
- package/dist/module/hooks/initialize.js.map +1 -1
- package/dist/module/hooks/voiceagent.js +20 -55
- package/dist/module/hooks/voiceagent.js.map +1 -1
- package/dist/module/index.types.js +0 -1
- package/dist/module/index.types.js.map +1 -1
- package/dist/module/utils/reanimated.helper.js.map +1 -1
- package/dist/typescript/src/api/api.d.ts +6 -0
- package/dist/typescript/src/api/api.d.ts.map +1 -1
- package/dist/typescript/src/api/api.error.d.ts +107 -0
- package/dist/typescript/src/api/api.error.d.ts.map +1 -0
- package/dist/typescript/src/api/types/embed.api.types.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedAudioWave.d.ts.map +1 -1
- package/dist/typescript/src/components/Embed/EmbedButton.d.ts +7 -0
- 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/components/styles/EmbedButton.style.d.ts +70 -0
- package/dist/typescript/src/components/styles/EmbedButton.style.d.ts.map +1 -1
- package/dist/typescript/src/events/embed.event.d.ts.map +1 -1
- package/dist/typescript/src/hooks/initialize.d.ts +2 -2
- package/dist/typescript/src/hooks/initialize.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/initialize.types.d.ts +4 -0
- package/dist/typescript/src/hooks/types/initialize.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/types/voiceAgent.types.d.ts +3 -1
- package/dist/typescript/src/hooks/types/voiceAgent.types.d.ts.map +1 -1
- package/dist/typescript/src/hooks/voiceagent.d.ts.map +1 -1
- package/dist/typescript/src/index.d.ts +1 -1
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/index.types.d.ts +8 -4
- package/dist/typescript/src/index.types.d.ts.map +1 -1
- package/dist/typescript/src/utils/reanimated.helper.d.ts.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processApiError = exports.isApiErrorResponse = exports.HTTP_STATUS_CODES = exports.ERROR_TYPES = exports.ApiErrorHandler = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* API Error handling system
|
|
9
|
+
* Centralizes all error handling logic with status codes and definitions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* HTTP Status Code definitions
|
|
14
|
+
*/
|
|
15
|
+
const HTTP_STATUS_CODES = exports.HTTP_STATUS_CODES = {
|
|
16
|
+
// 2xx Success
|
|
17
|
+
200: 'OK',
|
|
18
|
+
201: 'Created',
|
|
19
|
+
204: 'No Content',
|
|
20
|
+
// 4xx Client Errors
|
|
21
|
+
400: 'Bad Request',
|
|
22
|
+
401: 'Unauthorized',
|
|
23
|
+
403: 'Forbidden',
|
|
24
|
+
404: 'Not Found',
|
|
25
|
+
408: 'Request Timeout',
|
|
26
|
+
422: 'Unprocessable Entity',
|
|
27
|
+
429: 'Too Many Requests',
|
|
28
|
+
// 5xx Server Errors
|
|
29
|
+
500: 'Internal Server Error',
|
|
30
|
+
502: 'Bad Gateway',
|
|
31
|
+
503: 'Service Unavailable',
|
|
32
|
+
504: 'Gateway Timeout'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Predefined error types and their definitions
|
|
37
|
+
*/
|
|
38
|
+
const ERROR_TYPES = exports.ERROR_TYPES = {
|
|
39
|
+
NETWORK: {
|
|
40
|
+
code: 'NETWORK_ERROR',
|
|
41
|
+
message: 'Network request failed. Please check your internet connection and try again.',
|
|
42
|
+
type: 'NETWORK'
|
|
43
|
+
},
|
|
44
|
+
ATS: {
|
|
45
|
+
code: 'ATS_ERROR',
|
|
46
|
+
message: 'Network request blocked by iOS App Transport Security. Please configure ATS exceptions in Info.plist for HTTP endpoints, or use HTTPS instead.',
|
|
47
|
+
type: 'ATS'
|
|
48
|
+
},
|
|
49
|
+
TIMEOUT: {
|
|
50
|
+
code: 'TIMEOUT_ERROR',
|
|
51
|
+
message: 'Request timeout. The API server may be slow to respond or unreachable.',
|
|
52
|
+
type: 'TIMEOUT'
|
|
53
|
+
},
|
|
54
|
+
AUTH: {
|
|
55
|
+
code: 'AUTH_ERROR',
|
|
56
|
+
message: 'Authentication failed. Please check your API credentials.',
|
|
57
|
+
type: 'AUTH'
|
|
58
|
+
},
|
|
59
|
+
SERVER: {
|
|
60
|
+
code: 'SERVER_ERROR',
|
|
61
|
+
message: 'Server error occurred. Please try again later.',
|
|
62
|
+
type: 'SERVER'
|
|
63
|
+
},
|
|
64
|
+
VALIDATION: {
|
|
65
|
+
code: 'VALIDATION_ERROR',
|
|
66
|
+
message: 'Invalid request data. Please check your input.',
|
|
67
|
+
type: 'VALIDATION'
|
|
68
|
+
},
|
|
69
|
+
UNKNOWN: {
|
|
70
|
+
code: 'UNKNOWN_ERROR',
|
|
71
|
+
message: 'An unknown error occurred. Please try again.',
|
|
72
|
+
type: 'UNKNOWN'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Enhanced error handler that categorizes and formats errors
|
|
78
|
+
*/
|
|
79
|
+
class ApiErrorHandler {
|
|
80
|
+
/**
|
|
81
|
+
* Handle HTTP response errors
|
|
82
|
+
*/
|
|
83
|
+
static handleHttpError(response, responseData) {
|
|
84
|
+
const statusCode = response.status;
|
|
85
|
+
const statusText = HTTP_STATUS_CODES[statusCode] || 'Unknown Status';
|
|
86
|
+
|
|
87
|
+
// Extract error message from response data if available
|
|
88
|
+
const serverMessage = responseData?.error || responseData?.message || '';
|
|
89
|
+
|
|
90
|
+
// Determine error type based on status code
|
|
91
|
+
let errorType = 'SERVER';
|
|
92
|
+
let code;
|
|
93
|
+
let baseMessage;
|
|
94
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
95
|
+
if (statusCode === 401 || statusCode === 403) {
|
|
96
|
+
errorType = 'AUTH';
|
|
97
|
+
code = ERROR_TYPES.AUTH.code;
|
|
98
|
+
baseMessage = ERROR_TYPES.AUTH.message;
|
|
99
|
+
} else if (statusCode === 408) {
|
|
100
|
+
errorType = 'TIMEOUT';
|
|
101
|
+
code = ERROR_TYPES.TIMEOUT.code;
|
|
102
|
+
baseMessage = ERROR_TYPES.TIMEOUT.message;
|
|
103
|
+
} else if (statusCode === 422) {
|
|
104
|
+
errorType = 'VALIDATION';
|
|
105
|
+
code = ERROR_TYPES.VALIDATION.code;
|
|
106
|
+
baseMessage = ERROR_TYPES.VALIDATION.message;
|
|
107
|
+
} else {
|
|
108
|
+
errorType = 'VALIDATION';
|
|
109
|
+
code = ERROR_TYPES.VALIDATION.code;
|
|
110
|
+
baseMessage = ERROR_TYPES.VALIDATION.message;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
code = ERROR_TYPES.SERVER.code;
|
|
114
|
+
baseMessage = ERROR_TYPES.SERVER.message;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
code,
|
|
118
|
+
message: serverMessage || `${baseMessage} (${statusCode}: ${statusText})`,
|
|
119
|
+
statusCode,
|
|
120
|
+
details: serverMessage ? `HTTP ${statusCode}: ${statusText}` : undefined,
|
|
121
|
+
type: errorType
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Handle network and other runtime errors
|
|
127
|
+
*/
|
|
128
|
+
static handleRuntimeError(error, apiBaseUrl) {
|
|
129
|
+
const errorMessage = error.message.toLowerCase();
|
|
130
|
+
|
|
131
|
+
// iOS ATS related errors
|
|
132
|
+
if (errorMessage.includes('the resource could not be loaded') || errorMessage.includes('app transport security')) {
|
|
133
|
+
return {
|
|
134
|
+
...ERROR_TYPES.ATS,
|
|
135
|
+
message: `${ERROR_TYPES.ATS.message} Error: ${error.message}`,
|
|
136
|
+
details: `API endpoint: ${apiBaseUrl}`
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Network connectivity errors
|
|
141
|
+
if (errorMessage.includes('network request failed') || errorMessage.includes('failed to fetch') || errorMessage.includes('fetch')) {
|
|
142
|
+
return {
|
|
143
|
+
...ERROR_TYPES.NETWORK,
|
|
144
|
+
message: `${ERROR_TYPES.NETWORK.message} API endpoint: ${apiBaseUrl}. Error: ${error.message}`,
|
|
145
|
+
details: `Endpoint: ${apiBaseUrl}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Timeout errors
|
|
150
|
+
if (errorMessage.includes('timeout') || errorMessage.includes('aborted')) {
|
|
151
|
+
return {
|
|
152
|
+
...ERROR_TYPES.TIMEOUT,
|
|
153
|
+
message: `${ERROR_TYPES.TIMEOUT.message} Error: ${error.message}`,
|
|
154
|
+
details: `Endpoint: ${apiBaseUrl}`
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Authentication errors
|
|
159
|
+
if (errorMessage.includes('unauthorized') || errorMessage.includes('authentication') || errorMessage.includes('api key')) {
|
|
160
|
+
return {
|
|
161
|
+
...ERROR_TYPES.AUTH,
|
|
162
|
+
message: `${ERROR_TYPES.AUTH.message} Error: ${error.message}`
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Default to unknown error
|
|
167
|
+
return {
|
|
168
|
+
...ERROR_TYPES.UNKNOWN,
|
|
169
|
+
message: `${ERROR_TYPES.UNKNOWN.message} Error: ${error.message}`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Format error for API response
|
|
175
|
+
*/
|
|
176
|
+
static formatErrorResponse(apiError) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
error: apiError.message,
|
|
180
|
+
errorCode: apiError.code,
|
|
181
|
+
statusCode: apiError.statusCode,
|
|
182
|
+
type: apiError.type
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Main error processing method
|
|
188
|
+
*/
|
|
189
|
+
static async processApiError(error, response, apiBaseUrl) {
|
|
190
|
+
let apiError;
|
|
191
|
+
if (response && !response.ok) {
|
|
192
|
+
// HTTP error - try to get response data
|
|
193
|
+
let responseData;
|
|
194
|
+
try {
|
|
195
|
+
responseData = await response.json();
|
|
196
|
+
} catch (e) {
|
|
197
|
+
// If JSON parsing fails, use response text or status
|
|
198
|
+
responseData = {
|
|
199
|
+
error: response.statusText
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
apiError = this.handleHttpError(response, responseData);
|
|
203
|
+
} else if (error instanceof Error) {
|
|
204
|
+
// Runtime error
|
|
205
|
+
apiError = this.handleRuntimeError(error, apiBaseUrl);
|
|
206
|
+
} else {
|
|
207
|
+
// Unknown error type
|
|
208
|
+
apiError = {
|
|
209
|
+
...ERROR_TYPES.UNKNOWN,
|
|
210
|
+
message: `${ERROR_TYPES.UNKNOWN.message} Details: ${String(error)}`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return this.formatErrorResponse(apiError);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Convenience function for processing API errors
|
|
219
|
+
*/
|
|
220
|
+
exports.ApiErrorHandler = ApiErrorHandler;
|
|
221
|
+
const processApiError = async (error, response, apiBaseUrl) => {
|
|
222
|
+
return ApiErrorHandler.processApiError(error, response, apiBaseUrl);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Type guard to check if a response is an error response
|
|
227
|
+
*/
|
|
228
|
+
exports.processApiError = processApiError;
|
|
229
|
+
const isApiErrorResponse = response => {
|
|
230
|
+
return response && typeof response === 'object' && response.success === false;
|
|
231
|
+
};
|
|
232
|
+
exports.isApiErrorResponse = isApiErrorResponse;
|
|
233
|
+
//# sourceMappingURL=api.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HTTP_STATUS_CODES","exports","ERROR_TYPES","NETWORK","code","message","type","ATS","TIMEOUT","AUTH","SERVER","VALIDATION","UNKNOWN","ApiErrorHandler","handleHttpError","response","responseData","statusCode","status","statusText","serverMessage","error","errorType","baseMessage","details","undefined","handleRuntimeError","apiBaseUrl","errorMessage","toLowerCase","includes","formatErrorResponse","apiError","success","errorCode","processApiError","ok","json","e","Error","String","isApiErrorResponse"],"sourceRoot":"../../../src","sources":["api/api.error.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAyBA;AACA;AACA;AACO,MAAMA,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EAC/B;EACA,GAAG,EAAE,IAAI;EACT,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,YAAY;EAEjB;EACA,GAAG,EAAE,aAAa;EAClB,GAAG,EAAE,cAAc;EACnB,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,WAAW;EAChB,GAAG,EAAE,iBAAiB;EACtB,GAAG,EAAE,sBAAsB;EAC3B,GAAG,EAAE,mBAAmB;EAExB;EACA,GAAG,EAAE,uBAAuB;EAC5B,GAAG,EAAE,aAAa;EAClB,GAAG,EAAE,qBAAqB;EAC1B,GAAG,EAAE;AACP,CAAU;;AAEV;AACA;AACA;AACO,MAAME,WAAW,GAAAD,OAAA,CAAAC,WAAA,GAAG;EACzBC,OAAO,EAAE;IACPC,IAAI,EAAE,eAAe;IACrBC,OAAO,EACL,8EAA8E;IAChFC,IAAI,EAAE;EACR,CAAC;EACDC,GAAG,EAAE;IACHH,IAAI,EAAE,WAAW;IACjBC,OAAO,EACL,gJAAgJ;IAClJC,IAAI,EAAE;EACR,CAAC;EACDE,OAAO,EAAE;IACPJ,IAAI,EAAE,eAAe;IACrBC,OAAO,EACL,wEAAwE;IAC1EC,IAAI,EAAE;EACR,CAAC;EACDG,IAAI,EAAE;IACJL,IAAI,EAAE,YAAY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QAAQ,IAAIA,QAAQ,CAACkB,OAAO,KAAK,KAAK;AAC/E,CAAC;AAAChC,OAAA,CAAAwC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/dist/commonjs/api/api.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.updateUserData = exports.registerOnInitialize = exports.initializeApi = exports.getTokenDetails = exports.APIService = void 0;
|
|
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
|
+
var _apiError = require("./api.error.js");
|
|
8
9
|
/**
|
|
9
10
|
* APIService class that ensures proper initialization before API calls
|
|
10
11
|
*/
|
|
@@ -32,11 +33,9 @@ class APIService {
|
|
|
32
33
|
return; // Already initialized
|
|
33
34
|
}
|
|
34
35
|
const AgentData = await (0, _storeKey.getAgentData)();
|
|
35
|
-
console.log('AgentData', AgentData);
|
|
36
36
|
if (AgentData?.embedUrl) {
|
|
37
37
|
this.apiBaseUrl = AgentData.embedUrl;
|
|
38
38
|
this.isInitialized = true;
|
|
39
|
-
console.log('API_BASE_URL initialized:', this.apiBaseUrl);
|
|
40
39
|
} else {
|
|
41
40
|
throw new Error('API base URL not found in keychain');
|
|
42
41
|
}
|
|
@@ -71,52 +70,25 @@ class APIService {
|
|
|
71
70
|
* @returns Promise with registration response
|
|
72
71
|
*/
|
|
73
72
|
async registerOnInitialize() {
|
|
73
|
+
let response;
|
|
74
74
|
try {
|
|
75
75
|
await this.ensureInitialized();
|
|
76
|
-
console.log('registerOnInitialize ApiData', this.apiBaseUrl);
|
|
77
76
|
const headers = await this.getHeaders();
|
|
78
|
-
|
|
77
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/initialize`, {
|
|
79
78
|
method: 'GET',
|
|
80
79
|
headers: headers
|
|
81
80
|
});
|
|
82
81
|
const data = await response.json();
|
|
83
|
-
console.log('dat config data after register', data);
|
|
84
|
-
await (0, _storeKey.setAgentData)(data, '@config_data');
|
|
85
82
|
if (!response.ok) {
|
|
86
|
-
|
|
87
|
-
throw new Error(data.error || 'Registration failed');
|
|
83
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
88
84
|
}
|
|
85
|
+
await (0, _storeKey.setAgentData)(data, '@config_data');
|
|
89
86
|
return {
|
|
90
87
|
success: true,
|
|
91
88
|
data: data
|
|
92
89
|
};
|
|
93
90
|
} catch (error) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// Enhanced error handling for common iOS network issues
|
|
97
|
-
let errorMessage = 'Unknown error occurred';
|
|
98
|
-
if (error instanceof Error) {
|
|
99
|
-
errorMessage = error.message;
|
|
100
|
-
|
|
101
|
-
// iOS ATS related errors
|
|
102
|
-
if (error.message.includes('The resource could not be loaded') || error.message.includes('App Transport Security')) {
|
|
103
|
-
errorMessage = `Network request blocked by iOS App Transport Security. ` + `Please configure ATS exceptions in Info.plist for HTTP endpoints, ` + `or use HTTPS instead. Error: ${error.message}`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Network connectivity errors
|
|
107
|
-
if (error.message.includes('Network request failed') || error.message.includes('Failed to fetch')) {
|
|
108
|
-
errorMessage = `Network request failed. Please check your internet connection ` + `and ensure the API endpoint (${this.apiBaseUrl}) is accessible. ` + `Error: ${error.message}`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Timeout errors
|
|
112
|
-
if (error.message.includes('timeout')) {
|
|
113
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
success: false,
|
|
118
|
-
error: errorMessage
|
|
119
|
-
};
|
|
91
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
120
92
|
}
|
|
121
93
|
}
|
|
122
94
|
|
|
@@ -126,53 +98,25 @@ class APIService {
|
|
|
126
98
|
* @returns Promise with update response
|
|
127
99
|
*/
|
|
128
100
|
async updateUserData(params) {
|
|
101
|
+
let response;
|
|
129
102
|
try {
|
|
130
103
|
await this.ensureInitialized();
|
|
131
|
-
console.log('params', params, `${this.apiBaseUrl}/embedded-agent/user-context/update?app_user_id=${params.data.app_user_id}`);
|
|
132
|
-
console.log('updateUserData');
|
|
133
104
|
const headers = await this.getHeaders();
|
|
134
|
-
|
|
105
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/user-context/update?app_user_id=${params.data.app_user_id}`, {
|
|
135
106
|
method: 'PUT',
|
|
136
107
|
headers,
|
|
137
108
|
body: JSON.stringify({
|
|
138
109
|
[params.eventKey]: params.data
|
|
139
110
|
})
|
|
140
111
|
});
|
|
141
|
-
const data = await response.json();
|
|
142
|
-
console.log('data after update', data);
|
|
143
112
|
if (!response.ok) {
|
|
144
|
-
|
|
113
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
145
114
|
}
|
|
146
115
|
return {
|
|
147
116
|
success: true
|
|
148
117
|
};
|
|
149
118
|
} catch (error) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// Enhanced error handling for common iOS network issues
|
|
153
|
-
let errorMessage = 'Unknown error occurred';
|
|
154
|
-
if (error instanceof Error) {
|
|
155
|
-
errorMessage = error.message;
|
|
156
|
-
|
|
157
|
-
// iOS ATS related errors
|
|
158
|
-
if (error.message.includes('The resource could not be loaded') || error.message.includes('App Transport Security')) {
|
|
159
|
-
errorMessage = `Network request blocked by iOS App Transport Security. ` + `Please configure ATS exceptions in Info.plist for HTTP endpoints, ` + `or use HTTPS instead. Error: ${error.message}`;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Network connectivity errors
|
|
163
|
-
if (error.message.includes('Network request failed') || error.message.includes('Failed to fetch')) {
|
|
164
|
-
errorMessage = `Network request failed. Please check your internet connection ` + `and ensure the API endpoint (${this.apiBaseUrl}) is accessible. ` + `Error: ${error.message}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Timeout errors
|
|
168
|
-
if (error.message.includes('timeout')) {
|
|
169
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
success: false,
|
|
174
|
-
error: errorMessage
|
|
175
|
-
};
|
|
119
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
176
120
|
}
|
|
177
121
|
}
|
|
178
122
|
|
|
@@ -182,51 +126,46 @@ class APIService {
|
|
|
182
126
|
* @returns Promise with token details
|
|
183
127
|
*/
|
|
184
128
|
async getTokenDetails(params) {
|
|
129
|
+
let response;
|
|
185
130
|
try {
|
|
186
131
|
await this.ensureInitialized();
|
|
187
132
|
const headers = await this.getHeaders();
|
|
188
|
-
|
|
189
|
-
const response = await fetch(`${this.apiBaseUrl}/embedded-agent/token`, {
|
|
133
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/token`, {
|
|
190
134
|
method: 'POST',
|
|
191
135
|
headers,
|
|
192
136
|
body: JSON.stringify(params)
|
|
193
137
|
});
|
|
194
138
|
const data = await response.json();
|
|
195
|
-
console.log('data', data);
|
|
196
139
|
if (!response.ok) {
|
|
197
|
-
|
|
140
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
198
141
|
}
|
|
199
142
|
return {
|
|
200
143
|
success: true,
|
|
201
144
|
data: data
|
|
202
145
|
};
|
|
203
146
|
} catch (error) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Timeout errors
|
|
222
|
-
if (error.message.includes('timeout')) {
|
|
223
|
-
errorMessage = `Request timeout. The API server may be slow to respond or unreachable. ` + `Error: ${error.message}`;
|
|
224
|
-
}
|
|
147
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async getPopupDescription(params) {
|
|
151
|
+
let response;
|
|
152
|
+
try {
|
|
153
|
+
await this.ensureInitialized();
|
|
154
|
+
const headers = await this.getHeaders();
|
|
155
|
+
response = await fetch(`${this.apiBaseUrl}/embedded-agent/dynamic-popup?app_user_id=${params.app_user_id}`, {
|
|
156
|
+
method: 'GET',
|
|
157
|
+
headers
|
|
158
|
+
});
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
if (!response.ok) {
|
|
161
|
+
return await (0, _apiError.processApiError)(null, response, this.apiBaseUrl || undefined);
|
|
225
162
|
}
|
|
226
163
|
return {
|
|
227
|
-
success:
|
|
228
|
-
|
|
164
|
+
success: true,
|
|
165
|
+
data: data
|
|
229
166
|
};
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return await (0, _apiError.processApiError)(error, response, this.apiBaseUrl || undefined);
|
|
230
169
|
}
|
|
231
170
|
}
|
|
232
171
|
}
|
|
@@ -253,4 +192,9 @@ const getTokenDetails = async params => {
|
|
|
253
192
|
return await apiService.getTokenDetails(params);
|
|
254
193
|
};
|
|
255
194
|
exports.getTokenDetails = getTokenDetails;
|
|
195
|
+
const getPopupDescription = async params => {
|
|
196
|
+
const apiService = APIService.getInstance();
|
|
197
|
+
return await apiService.getPopupDescription(params);
|
|
198
|
+
};
|
|
199
|
+
exports.getPopupDescription = getPopupDescription;
|
|
256
200
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_storeKey","require","APIService","instance","apiBaseUrl","isInitialized","constructor","getInstance","initialize","AgentData","getAgentData","
|
|
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;IAC/C,IAAI,CAAC,IAAI,CAACR,aAAa,IAAI,CAAC,IAAI,CAACD,UAAU,EAAE;MAC3C,MAAM,I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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":[]}
|
|
@@ -7,6 +7,16 @@ exports.WaveformVisualizer = void 0;
|
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
// This module defines a custom hook for generating and animating a waveform visualization
|
|
11
|
+
// based on the audio activity in a LiveKit room. It uses the LiveKit SDK to track
|
|
12
|
+
// audio levels and update the waveform accordingly. The hook provides a set of animated
|
|
13
|
+
// values that can be used to render the waveform in a React Native component.
|
|
14
|
+
|
|
15
|
+
// The hook takes a room reference as an input and uses it to track the audio activity
|
|
16
|
+
// of the remote participants in the room. It checks the audio level of each participant
|
|
17
|
+
// and updates the waveform accordingly. The hook also handles the animation of the waveform
|
|
18
|
+
// by updating the heights of the bars based on the audio activity.
|
|
19
|
+
|
|
10
20
|
// React Native compatible waveform simulator
|
|
11
21
|
const useReactNativeAudioWaveform = roomRef => {
|
|
12
22
|
const [isAudioActive, setIsAudioActive] = (0, _react.useState)(false);
|
|
@@ -108,7 +118,6 @@ const WaveformVisualizer = ({
|
|
|
108
118
|
animatedBars,
|
|
109
119
|
currentHeights
|
|
110
120
|
} = useReactNativeAudioWaveform(roomRef);
|
|
111
|
-
console.log('animatedBars', animatedBars);
|
|
112
121
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
113
122
|
style: {
|
|
114
123
|
flexDirection: 'row',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_jsxRuntime","useReactNativeAudioWaveform","roomRef","isAudioActive","setIsAudioActive","useState","intervalRef","useRef","currentHeights","setCurrentHeights","Array","fill","barCount","animatedBars","map","Animated","Value","current","useEffect","checkAudioActivity","room","state","isAgentSpeaking","remoteParticipants","forEach","participant","audioTrackPublications","from","getTrackPublications","values","remoteAudioTrack","find","pub","track","kind","isMuted","audioLevel","setInterval","clearInterval","animateWaveform","targetHeights","_","index","timeOffset","Date","now","baseHeight","amplitude","height","Math","abs","sin","max","min","animations","animatedValue","targetHeight","timing","toValue","duration","useNativeDriver","parallel","start","animationInterval","isActive","WaveformVisualizer","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_jsxRuntime","useReactNativeAudioWaveform","roomRef","isAudioActive","setIsAudioActive","useState","intervalRef","useRef","currentHeights","setCurrentHeights","Array","fill","barCount","animatedBars","map","Animated","Value","current","useEffect","checkAudioActivity","room","state","isAgentSpeaking","remoteParticipants","forEach","participant","audioTrackPublications","from","getTrackPublications","values","remoteAudioTrack","find","pub","track","kind","isMuted","audioLevel","setInterval","clearInterval","animateWaveform","targetHeights","_","index","timeOffset","Date","now","baseHeight","amplitude","height","Math","abs","sin","max","min","animations","animatedValue","targetHeight","timing","toValue","duration","useNativeDriver","parallel","start","animationInterval","isActive","WaveformVisualizer","jsx","View","style","flexDirection","alignItems","alignSelf","justifyContent","zIndex","children","animatedHeight","idx","currentHeightValue","conditionalValue","width","borderRadius","interpolate","inputRange","outputRange","backgroundColor","margin","exports"],"sourceRoot":"../../../../src","sources":["components/Embed/EmbedAudioWave.tsx"],"mappings":";;;;;;AAUA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA8C,IAAAE,WAAA,GAAAF,OAAA;AAX9C;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AASA;AACA,MAAMG,2BAA2B,GAAIC,OAA8B,IAAK;EACtE,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAG,IAAAC,eAAQ,EAAC,KAAK,CAAC;EACzD,MAAMC,WAAW,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EACvD,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAG,IAAAJ,eAAQ,EAClDK,KAAK,CAAC,EAAE,CAAC,CAACC,IAAI,CAAC,CAAC,CAClB,CAAC;;EAED;EACA,MAAMC,QAAQ,GAAG,EAAE;EACnB,MAAMC,YAAY,GAAG,IAAAN,aAAM,EACzBG,KAAK,CAACE,QAAQ,CAAC,CACZD,IAAI,CAAC,CAAC,CAAC,CACPG,GAAG,CAAC,MAAM,IAAIC,qBAAQ,CAACC,KAAK,CAAC,CAAC,CAAC,CACpC,CAAC,CAACC,OAAO;EAET,IAAAC,gBAAS,EAAC,MAAM;IACd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