call-control-sdk 2.0.0 → 2.1.0
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 +12 -22
- package/dist/index.d.mts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.js +586 -94
- package/dist/index.mjs +593 -96
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,407 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
-
// src/lib/
|
|
5
|
+
// src/lib/hooks/eventsTracker.ts
|
|
6
|
+
var EventTrackerSDK = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
__publicField(this, "config", null);
|
|
9
|
+
__publicField(this, "ticketId", null);
|
|
10
|
+
__publicField(this, "baseUrl", "");
|
|
11
|
+
__publicField(this, "eventQueue", []);
|
|
12
|
+
__publicField(this, "isOnline", true);
|
|
13
|
+
__publicField(this, "retryQueue", []);
|
|
14
|
+
__publicField(this, "flushTimer", null);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Initialize the EventTracker SDK
|
|
18
|
+
* @param config Configuration object
|
|
19
|
+
*/
|
|
20
|
+
async init(config) {
|
|
21
|
+
this.config = {
|
|
22
|
+
autoTrack: true,
|
|
23
|
+
retryAttempts: 3,
|
|
24
|
+
queueSize: 100,
|
|
25
|
+
flushInterval: 5e3,
|
|
26
|
+
...config
|
|
27
|
+
};
|
|
28
|
+
this.baseUrl = config.baseUrl || (typeof window !== "undefined" ? window.location.origin : "");
|
|
29
|
+
this.setupNetworkDetection();
|
|
30
|
+
const ticket = await this.createTicket();
|
|
31
|
+
this.startPeriodicFlush();
|
|
32
|
+
console.log("EventTracker SDK initialized successfully");
|
|
33
|
+
return ticket;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if the SDK is initialized
|
|
37
|
+
*/
|
|
38
|
+
isInitialized() {
|
|
39
|
+
return this.config !== null && this.ticketId !== null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the current configuration
|
|
43
|
+
*/
|
|
44
|
+
getConfig() {
|
|
45
|
+
return this.config;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the current ticket ID
|
|
49
|
+
*/
|
|
50
|
+
getTicketId() {
|
|
51
|
+
return this.ticketId;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a new ticket
|
|
55
|
+
*/
|
|
56
|
+
async createTicket() {
|
|
57
|
+
if (!this.config) {
|
|
58
|
+
throw new Error("EventTracker not initialized");
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const response = await this.makeRequest("/api/v1/et/init", {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
"X-API-Key": this.config.apiKey
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
agentId: this.config.agentId,
|
|
69
|
+
sessionId: this.config.sessionId
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Failed to initialize: ${response.status} ${response.statusText}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const data = await response.json();
|
|
78
|
+
this.ticketId = data.ticketId;
|
|
79
|
+
if (this.config.autoTrack) {
|
|
80
|
+
this.setupAutoTracking();
|
|
81
|
+
}
|
|
82
|
+
return this.ticketId;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error("EventTracker initialization failed:", error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Log an event
|
|
90
|
+
* @param eventType The type of event
|
|
91
|
+
* @param eventData Optional event data
|
|
92
|
+
*/
|
|
93
|
+
async logEvent(eventType, eventData) {
|
|
94
|
+
if (!this.config || !this.ticketId) {
|
|
95
|
+
console.warn("EventTracker not initialized, skipping event:", eventType);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const event = {
|
|
99
|
+
eventType,
|
|
100
|
+
eventData,
|
|
101
|
+
timestamp: Date.now()
|
|
102
|
+
};
|
|
103
|
+
this.eventQueue.push(event);
|
|
104
|
+
if (this.eventQueue.length > (this.config.queueSize || 100)) {
|
|
105
|
+
this.eventQueue.shift();
|
|
106
|
+
}
|
|
107
|
+
if (this.isOnline) {
|
|
108
|
+
try {
|
|
109
|
+
await this.sendEvent(event);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.warn("Failed to send event, will retry later:", error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Send an event to the server
|
|
117
|
+
*/
|
|
118
|
+
async sendEvent(event) {
|
|
119
|
+
if (!this.config || !this.ticketId) return;
|
|
120
|
+
try {
|
|
121
|
+
const response = await this.makeRequest("/api/v1/et/event", {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: {
|
|
124
|
+
"Content-Type": "application/json",
|
|
125
|
+
"X-API-Key": this.config.apiKey
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
ticketId: this.ticketId,
|
|
129
|
+
eventType: event.eventType,
|
|
130
|
+
eventData: event.eventData
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`Failed to log event: ${response.status} ${response.statusText}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const index = this.eventQueue.findIndex(
|
|
139
|
+
(e) => e.timestamp === event.timestamp
|
|
140
|
+
);
|
|
141
|
+
if (index > -1) {
|
|
142
|
+
this.eventQueue.splice(index, 1);
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error("Event logging failed:", error);
|
|
146
|
+
this.retryQueue.push(() => this.sendEvent(event));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Close the current ticket
|
|
151
|
+
*/
|
|
152
|
+
async closeTicket() {
|
|
153
|
+
if (!this.config || !this.ticketId) {
|
|
154
|
+
throw new Error("EventTracker not initialized");
|
|
155
|
+
}
|
|
156
|
+
await this.flush();
|
|
157
|
+
try {
|
|
158
|
+
const response = await this.makeRequest("/api/v1/et/close", {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/json",
|
|
162
|
+
"X-API-Key": this.config.apiKey
|
|
163
|
+
},
|
|
164
|
+
body: JSON.stringify({
|
|
165
|
+
ticketId: this.ticketId
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
if (!response.ok) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`Failed to close ticket: ${response.status} ${response.statusText}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
this.ticketId = null;
|
|
174
|
+
this.stopPeriodicFlush();
|
|
175
|
+
console.log("Ticket closed successfully");
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error("Ticket close failed:", error);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Flush all pending events
|
|
183
|
+
*/
|
|
184
|
+
async flush() {
|
|
185
|
+
if (!this.isOnline || this.eventQueue.length === 0) return;
|
|
186
|
+
const eventsToFlush = [...this.eventQueue];
|
|
187
|
+
for (const event of eventsToFlush) {
|
|
188
|
+
await this.sendEvent(event);
|
|
189
|
+
}
|
|
190
|
+
const retryItems = [...this.retryQueue];
|
|
191
|
+
this.retryQueue = [];
|
|
192
|
+
for (const retryFn of retryItems) {
|
|
193
|
+
try {
|
|
194
|
+
await retryFn();
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error("Retry failed:", error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Make an HTTP request with retry logic
|
|
202
|
+
*/
|
|
203
|
+
async makeRequest(url, options) {
|
|
204
|
+
const fullUrl = `${this.baseUrl}${url}`;
|
|
205
|
+
const maxRetries = this.config?.retryAttempts || 3;
|
|
206
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
207
|
+
try {
|
|
208
|
+
const response = await fetch(fullUrl, options);
|
|
209
|
+
return response;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (attempt === maxRetries) {
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
const delay = Math.min(1e3 * Math.pow(2, attempt - 1), 1e4);
|
|
215
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
throw new Error("Max retries exceeded");
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Set up automatic event tracking
|
|
222
|
+
*/
|
|
223
|
+
setupAutoTracking() {
|
|
224
|
+
if (typeof window === "undefined" || !this.config?.autoTrack) return;
|
|
225
|
+
const autoTrackConfig = this.config.autoTrack === true ? {} : this.config.autoTrack;
|
|
226
|
+
if (autoTrackConfig.pageVisits !== false) {
|
|
227
|
+
this.logEvent("pageVisit", {
|
|
228
|
+
url: window.location.href,
|
|
229
|
+
title: document.title,
|
|
230
|
+
referrer: document.referrer,
|
|
231
|
+
userAgent: navigator.userAgent,
|
|
232
|
+
viewport: {
|
|
233
|
+
width: window.innerWidth,
|
|
234
|
+
height: window.innerHeight
|
|
235
|
+
},
|
|
236
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
237
|
+
}).catch((error) => console.warn("Failed to track page visit:", error));
|
|
238
|
+
}
|
|
239
|
+
if (autoTrackConfig.clicks !== false) {
|
|
240
|
+
document.addEventListener("click", (event) => {
|
|
241
|
+
const target = event.target;
|
|
242
|
+
if (target.tagName === "BUTTON" || target.tagName === "A" || target.onclick || target.getAttribute("role") === "button") {
|
|
243
|
+
this.logEvent("click", {
|
|
244
|
+
element: target.tagName,
|
|
245
|
+
text: target.textContent?.trim().substring(0, 100),
|
|
246
|
+
// Limit text length
|
|
247
|
+
href: target.getAttribute("href"),
|
|
248
|
+
id: target.id,
|
|
249
|
+
className: target.className,
|
|
250
|
+
role: target.getAttribute("role"),
|
|
251
|
+
position: {
|
|
252
|
+
x: event.clientX,
|
|
253
|
+
y: event.clientY
|
|
254
|
+
},
|
|
255
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
256
|
+
}).catch((error) => console.warn("Failed to track click:", error));
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (autoTrackConfig.forms !== false) {
|
|
261
|
+
document.addEventListener("submit", (event) => {
|
|
262
|
+
const target = event.target;
|
|
263
|
+
const formData = new FormData(target);
|
|
264
|
+
const formFields = {};
|
|
265
|
+
formData.forEach((value, key) => {
|
|
266
|
+
formFields[key] = value.toString();
|
|
267
|
+
});
|
|
268
|
+
this.logEvent("formSubmission", {
|
|
269
|
+
formId: target.id,
|
|
270
|
+
action: target.action,
|
|
271
|
+
method: target.method,
|
|
272
|
+
fields: Object.keys(formFields),
|
|
273
|
+
fieldCount: Object.keys(formFields).length,
|
|
274
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
275
|
+
}).catch(
|
|
276
|
+
(error) => console.warn("Failed to track form submission:", error)
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (autoTrackConfig.inputs !== false) {
|
|
281
|
+
let inputTimer;
|
|
282
|
+
document.addEventListener("input", (event) => {
|
|
283
|
+
const target = event.target;
|
|
284
|
+
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT") {
|
|
285
|
+
clearTimeout(inputTimer);
|
|
286
|
+
inputTimer = setTimeout(() => {
|
|
287
|
+
this.logEvent("fieldChange", {
|
|
288
|
+
element: target.tagName,
|
|
289
|
+
type: target.getAttribute("type"),
|
|
290
|
+
name: target.getAttribute("name"),
|
|
291
|
+
id: target.id,
|
|
292
|
+
valueLength: target.value?.length || 0,
|
|
293
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
294
|
+
}).catch(
|
|
295
|
+
(error) => console.warn("Failed to track field change:", error)
|
|
296
|
+
);
|
|
297
|
+
}, 1e3);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
const sessionStartTime = Date.now();
|
|
302
|
+
window.addEventListener("beforeunload", () => {
|
|
303
|
+
const sessionDuration = Date.now() - sessionStartTime;
|
|
304
|
+
this.logEvent("pageUnload", {
|
|
305
|
+
url: window.location.href,
|
|
306
|
+
sessionDuration,
|
|
307
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
308
|
+
});
|
|
309
|
+
if (this.ticketId) {
|
|
310
|
+
navigator.sendBeacon(
|
|
311
|
+
`${this.baseUrl}/api/v1/et/close`,
|
|
312
|
+
JSON.stringify({
|
|
313
|
+
ticketId: this.ticketId
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
if (autoTrackConfig.visibility !== false) {
|
|
319
|
+
document.addEventListener("visibilitychange", () => {
|
|
320
|
+
this.logEvent("visibilityChange", {
|
|
321
|
+
hidden: document.hidden,
|
|
322
|
+
visibilityState: document.visibilityState,
|
|
323
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (autoTrackConfig.errors !== false) {
|
|
328
|
+
window.addEventListener("error", (event) => {
|
|
329
|
+
this.logEvent("jsError", {
|
|
330
|
+
message: event.message,
|
|
331
|
+
filename: event.filename,
|
|
332
|
+
lineno: event.lineno,
|
|
333
|
+
colno: event.colno,
|
|
334
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
338
|
+
this.logEvent("unhandledRejection", {
|
|
339
|
+
reason: event.reason?.toString(),
|
|
340
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
if (autoTrackConfig.performance !== false && typeof window.performance !== "undefined" && window.performance.navigation) {
|
|
345
|
+
window.addEventListener("load", () => {
|
|
346
|
+
setTimeout(() => {
|
|
347
|
+
const navigation = window.performance.navigation;
|
|
348
|
+
const timing = window.performance.timing;
|
|
349
|
+
this.logEvent("performanceMetrics", {
|
|
350
|
+
navigationTime: timing.navigationStart,
|
|
351
|
+
loadTime: timing.loadEventEnd - timing.navigationStart,
|
|
352
|
+
domReady: timing.domContentLoadedEventEnd - timing.navigationStart,
|
|
353
|
+
renderTime: timing.loadEventEnd - timing.domContentLoadedEventEnd,
|
|
354
|
+
navigationType: navigation.type,
|
|
355
|
+
redirectCount: navigation.redirectCount,
|
|
356
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
357
|
+
});
|
|
358
|
+
}, 1e3);
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Set up network detection
|
|
364
|
+
*/
|
|
365
|
+
setupNetworkDetection() {
|
|
366
|
+
if (typeof window === "undefined") return;
|
|
367
|
+
this.isOnline = navigator.onLine;
|
|
368
|
+
window.addEventListener("online", () => {
|
|
369
|
+
this.isOnline = true;
|
|
370
|
+
console.log("EventTracker: Back online, flushing queued events");
|
|
371
|
+
this.flush();
|
|
372
|
+
});
|
|
373
|
+
window.addEventListener("offline", () => {
|
|
374
|
+
this.isOnline = false;
|
|
375
|
+
console.log("EventTracker: Offline, queueing events");
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Start periodic flush timer
|
|
380
|
+
*/
|
|
381
|
+
startPeriodicFlush() {
|
|
382
|
+
if (this.flushTimer) {
|
|
383
|
+
clearInterval(this.flushTimer);
|
|
384
|
+
}
|
|
385
|
+
const interval = this.config?.flushInterval || 5e3;
|
|
386
|
+
this.flushTimer = setInterval(() => {
|
|
387
|
+
this.flush();
|
|
388
|
+
}, interval);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Stop periodic flush timer
|
|
392
|
+
*/
|
|
393
|
+
stopPeriodicFlush() {
|
|
394
|
+
if (this.flushTimer) {
|
|
395
|
+
clearInterval(this.flushTimer);
|
|
396
|
+
this.flushTimer = null;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
var eventTracker = new EventTrackerSDK();
|
|
401
|
+
if (typeof window !== "undefined") {
|
|
402
|
+
window.EventTracker = eventTracker;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/lib/hooks/sdk-state.ts
|
|
6
406
|
var SDKStateManager = class {
|
|
7
407
|
constructor() {
|
|
8
408
|
__publicField(this, "state");
|
|
@@ -135,7 +535,11 @@ import {
|
|
|
135
535
|
Tooltip,
|
|
136
536
|
Fade,
|
|
137
537
|
useTheme,
|
|
138
|
-
Button
|
|
538
|
+
Button,
|
|
539
|
+
Badge,
|
|
540
|
+
Chip,
|
|
541
|
+
Avatar,
|
|
542
|
+
TextField
|
|
139
543
|
} from "@mui/material";
|
|
140
544
|
import {
|
|
141
545
|
PauseCircle,
|
|
@@ -144,15 +548,15 @@ import {
|
|
|
144
548
|
MicOff,
|
|
145
549
|
MoreVert,
|
|
146
550
|
CallEnd,
|
|
147
|
-
KeyboardArrowDown,
|
|
148
551
|
Cached,
|
|
149
552
|
FreeBreakfast,
|
|
150
553
|
AirlineSeatIndividualSuite,
|
|
151
554
|
TransferWithinAStation,
|
|
152
555
|
Groups,
|
|
153
|
-
Phone,
|
|
154
556
|
DragIndicator,
|
|
155
|
-
|
|
557
|
+
WifiCalling3,
|
|
558
|
+
Layers,
|
|
559
|
+
Phone
|
|
156
560
|
} from "@mui/icons-material";
|
|
157
561
|
|
|
158
562
|
// src/lib/hooks/useSDKState.ts
|
|
@@ -204,11 +608,10 @@ function useDraggable(initialPosition, onPositionChange) {
|
|
|
204
608
|
const handleMove = (moveClientX, moveClientY) => {
|
|
205
609
|
const deltaX = moveClientX - dragStart.current.x;
|
|
206
610
|
const deltaY = moveClientY - dragStart.current.y;
|
|
207
|
-
|
|
611
|
+
updatePosition({
|
|
208
612
|
x: elementStart.current.x + deltaX,
|
|
209
613
|
y: elementStart.current.y + deltaY
|
|
210
|
-
};
|
|
211
|
-
updatePosition(newPosition);
|
|
614
|
+
});
|
|
212
615
|
};
|
|
213
616
|
const handleMouseMove = (e) => {
|
|
214
617
|
e.preventDefault();
|
|
@@ -269,6 +672,10 @@ function CallControlPanel({ onDataChange }) {
|
|
|
269
672
|
const theme = useTheme();
|
|
270
673
|
const state = useSDKState();
|
|
271
674
|
const [anchorEl, setAnchorEl] = useState3(null);
|
|
675
|
+
const [phoneNumber, setPhoneNumber] = useState3("");
|
|
676
|
+
const [dialerAnchorEl, setDialerAnchorEl] = useState3(
|
|
677
|
+
null
|
|
678
|
+
);
|
|
272
679
|
const [moreOptionsAnchorEl, setMoreOptionsAnchorEl] = useState3(null);
|
|
273
680
|
const [callDuration, setCallDuration] = useState3(0);
|
|
274
681
|
const { position, isDragging, dragRef, handleMouseDown, handleTouchStart } = useDraggable(
|
|
@@ -306,9 +713,9 @@ function CallControlPanel({ onDataChange }) {
|
|
|
306
713
|
case "break":
|
|
307
714
|
return "warning";
|
|
308
715
|
case "idle":
|
|
309
|
-
return "
|
|
716
|
+
return "info";
|
|
310
717
|
default:
|
|
311
|
-
return "
|
|
718
|
+
return "info";
|
|
312
719
|
}
|
|
313
720
|
}, []);
|
|
314
721
|
const handleHoldToggle = () => {
|
|
@@ -319,13 +726,17 @@ function CallControlPanel({ onDataChange }) {
|
|
|
319
726
|
};
|
|
320
727
|
const handleStatusChange = (newStatus) => {
|
|
321
728
|
sdkStateManager.setStatus(newStatus);
|
|
322
|
-
|
|
729
|
+
setMoreOptionsAnchorEl(null);
|
|
323
730
|
};
|
|
324
731
|
const handleEndCall = () => {
|
|
325
732
|
sdkStateManager.endCall();
|
|
326
733
|
};
|
|
327
|
-
const handleStartCall = () => {
|
|
328
|
-
|
|
734
|
+
const handleStartCall = (number) => {
|
|
735
|
+
if (number.length !== 10) {
|
|
736
|
+
alert("Invalid phone number");
|
|
737
|
+
} else {
|
|
738
|
+
sdkStateManager.startCall();
|
|
739
|
+
}
|
|
329
740
|
};
|
|
330
741
|
const handleMoreClick = (event) => {
|
|
331
742
|
setAnchorEl(event.currentTarget);
|
|
@@ -339,6 +750,12 @@ function CallControlPanel({ onDataChange }) {
|
|
|
339
750
|
const handleMoreOptionsClose = () => {
|
|
340
751
|
setMoreOptionsAnchorEl(null);
|
|
341
752
|
};
|
|
753
|
+
const handleOpenDialer = (event) => {
|
|
754
|
+
setDialerAnchorEl(event.currentTarget);
|
|
755
|
+
};
|
|
756
|
+
const handleCloseDialer = () => {
|
|
757
|
+
setDialerAnchorEl(null);
|
|
758
|
+
};
|
|
342
759
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
343
760
|
/* @__PURE__ */ jsx(Fade, { in: true, timeout: 300, children: /* @__PURE__ */ jsx(
|
|
344
761
|
Paper,
|
|
@@ -356,7 +773,7 @@ function CallControlPanel({ onDataChange }) {
|
|
|
356
773
|
transition: theme.transitions.create(["box-shadow", "transform"], {
|
|
357
774
|
duration: theme.transitions.duration.short
|
|
358
775
|
}),
|
|
359
|
-
transform: isDragging ? "scale(1.01)" : "scale(1)",
|
|
776
|
+
// transform: isDragging ? "scale(1.01)" : "scale(1)",
|
|
360
777
|
minWidth: 320,
|
|
361
778
|
userSelect: "none"
|
|
362
779
|
},
|
|
@@ -391,24 +808,33 @@ function CallControlPanel({ onDataChange }) {
|
|
|
391
808
|
alignItems: "center"
|
|
392
809
|
},
|
|
393
810
|
children: [
|
|
811
|
+
/* @__PURE__ */ jsx(DragIndicator, {}),
|
|
812
|
+
" ",
|
|
394
813
|
/* @__PURE__ */ jsx(
|
|
395
|
-
|
|
814
|
+
Box,
|
|
396
815
|
{
|
|
397
816
|
sx: {
|
|
398
817
|
marginRight: "10px"
|
|
399
|
-
}
|
|
818
|
+
},
|
|
819
|
+
children: /* @__PURE__ */ jsx(Tooltip, { title: "Dial", children: /* @__PURE__ */ jsx(
|
|
820
|
+
IconButton,
|
|
821
|
+
{
|
|
822
|
+
onClick: (e) => {
|
|
823
|
+
handleOpenDialer(e);
|
|
824
|
+
},
|
|
825
|
+
children: /* @__PURE__ */ jsx(WifiCalling3, { color: "success" })
|
|
826
|
+
}
|
|
827
|
+
) })
|
|
400
828
|
}
|
|
401
829
|
),
|
|
402
|
-
" ",
|
|
403
830
|
formatDuration(callDuration)
|
|
404
831
|
]
|
|
405
832
|
}
|
|
406
833
|
),
|
|
407
|
-
/* @__PURE__ */ jsx(Tooltip, { title: "Status", children: /* @__PURE__ */
|
|
834
|
+
/* @__PURE__ */ jsx(Tooltip, { title: "Status", children: /* @__PURE__ */ jsx(
|
|
408
835
|
Button,
|
|
409
836
|
{
|
|
410
837
|
sx: {
|
|
411
|
-
backgroundColor: getStatusColor(state.status),
|
|
412
838
|
fontWeight: "bold",
|
|
413
839
|
borderRadius: "16px",
|
|
414
840
|
display: "flex",
|
|
@@ -416,25 +842,20 @@ function CallControlPanel({ onDataChange }) {
|
|
|
416
842
|
justifyContent: "space-between",
|
|
417
843
|
marginRight: "8px"
|
|
418
844
|
},
|
|
419
|
-
|
|
420
|
-
e.stopPropagation();
|
|
421
|
-
handleMoreClick(e);
|
|
422
|
-
},
|
|
845
|
+
color: getStatusColor(state.status),
|
|
423
846
|
variant: "outlined",
|
|
424
|
-
children:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
/* @__PURE__ */ jsx(KeyboardArrowDown, {})
|
|
437
|
-
]
|
|
847
|
+
children: /* @__PURE__ */ jsx(
|
|
848
|
+
Typography,
|
|
849
|
+
{
|
|
850
|
+
width: 50,
|
|
851
|
+
variant: "body2",
|
|
852
|
+
sx: {
|
|
853
|
+
color: getStatusColor(state.status),
|
|
854
|
+
fontWeight: "bold"
|
|
855
|
+
},
|
|
856
|
+
children: state.status.toUpperCase()
|
|
857
|
+
}
|
|
858
|
+
)
|
|
438
859
|
}
|
|
439
860
|
) })
|
|
440
861
|
]
|
|
@@ -494,6 +915,23 @@ function CallControlPanel({ onDataChange }) {
|
|
|
494
915
|
children: state.isMuted ? /* @__PURE__ */ jsx(MicOff, {}) : /* @__PURE__ */ jsx(Mic, {})
|
|
495
916
|
}
|
|
496
917
|
) }),
|
|
918
|
+
/* @__PURE__ */ jsx(Tooltip, { title: "Queue", children: /* @__PURE__ */ jsx(
|
|
919
|
+
IconButton,
|
|
920
|
+
{
|
|
921
|
+
onClick: (e) => {
|
|
922
|
+
e.stopPropagation();
|
|
923
|
+
handleMoreClick(e);
|
|
924
|
+
},
|
|
925
|
+
color: "default",
|
|
926
|
+
sx: {
|
|
927
|
+
bgcolor: "action.hover",
|
|
928
|
+
"&:hover": {
|
|
929
|
+
bgcolor: "warning"
|
|
930
|
+
}
|
|
931
|
+
},
|
|
932
|
+
children: /* @__PURE__ */ jsx(Layers, {})
|
|
933
|
+
}
|
|
934
|
+
) }),
|
|
497
935
|
/* @__PURE__ */ jsx(Tooltip, { title: "More Options", children: /* @__PURE__ */ jsx(
|
|
498
936
|
IconButton,
|
|
499
937
|
{
|
|
@@ -513,14 +951,16 @@ function CallControlPanel({ onDataChange }) {
|
|
|
513
951
|
{
|
|
514
952
|
onClick: (e) => {
|
|
515
953
|
e.stopPropagation();
|
|
516
|
-
(state.callStartTime
|
|
954
|
+
if (state.callStartTime) {
|
|
955
|
+
handleEndCall();
|
|
956
|
+
}
|
|
517
957
|
},
|
|
518
958
|
color: "error",
|
|
519
959
|
sx: {
|
|
520
|
-
bgcolor: state.callStartTime ? "error.main" : "
|
|
960
|
+
bgcolor: state.callStartTime ? "error.main" : "gray",
|
|
521
961
|
color: "white",
|
|
522
962
|
"&:hover": {
|
|
523
|
-
bgcolor: state.callStartTime ? "error.light" : "
|
|
963
|
+
bgcolor: state.callStartTime ? "error.light" : "gray"
|
|
524
964
|
}
|
|
525
965
|
},
|
|
526
966
|
children: /* @__PURE__ */ jsx(CallEnd, {})
|
|
@@ -534,64 +974,115 @@ function CallControlPanel({ onDataChange }) {
|
|
|
534
974
|
)
|
|
535
975
|
}
|
|
536
976
|
) }),
|
|
537
|
-
/* @__PURE__ */
|
|
977
|
+
/* @__PURE__ */ jsx(
|
|
978
|
+
Menu,
|
|
979
|
+
{
|
|
980
|
+
anchorEl: dialerAnchorEl,
|
|
981
|
+
open: Boolean(dialerAnchorEl),
|
|
982
|
+
onClose: handleCloseDialer,
|
|
983
|
+
onClick: (e) => e.stopPropagation(),
|
|
984
|
+
children: /* @__PURE__ */ jsxs(
|
|
985
|
+
Box,
|
|
986
|
+
{
|
|
987
|
+
sx: {
|
|
988
|
+
all: "unset",
|
|
989
|
+
padding: "10px",
|
|
990
|
+
"&hover": {
|
|
991
|
+
backgroundColor: "white"
|
|
992
|
+
}
|
|
993
|
+
},
|
|
994
|
+
children: [
|
|
995
|
+
/* @__PURE__ */ jsx(
|
|
996
|
+
TextField,
|
|
997
|
+
{
|
|
998
|
+
size: "small",
|
|
999
|
+
value: phoneNumber,
|
|
1000
|
+
placeholder: "Enter Mobile No.",
|
|
1001
|
+
onChange: (e) => {
|
|
1002
|
+
setPhoneNumber(e.target.value);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
),
|
|
1006
|
+
/* @__PURE__ */ jsx(
|
|
1007
|
+
IconButton,
|
|
1008
|
+
{
|
|
1009
|
+
color: "info",
|
|
1010
|
+
onClick: () => {
|
|
1011
|
+
handleStartCall(phoneNumber);
|
|
1012
|
+
},
|
|
1013
|
+
children: /* @__PURE__ */ jsx(Phone, { color: "success" })
|
|
1014
|
+
}
|
|
1015
|
+
)
|
|
1016
|
+
]
|
|
1017
|
+
}
|
|
1018
|
+
)
|
|
1019
|
+
}
|
|
1020
|
+
),
|
|
1021
|
+
/* @__PURE__ */ jsx(
|
|
538
1022
|
Menu,
|
|
539
1023
|
{
|
|
540
1024
|
anchorEl,
|
|
541
1025
|
open: Boolean(anchorEl),
|
|
542
1026
|
onClose: handleMoreClose,
|
|
543
1027
|
onClick: (e) => e.stopPropagation(),
|
|
544
|
-
children:
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
{
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
1028
|
+
children: /* @__PURE__ */ jsxs(
|
|
1029
|
+
Box,
|
|
1030
|
+
{
|
|
1031
|
+
sx: {
|
|
1032
|
+
all: "unset",
|
|
1033
|
+
padding: "0px 10px",
|
|
1034
|
+
"&hover": {
|
|
1035
|
+
backgroundColor: "white"
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
children: [
|
|
1039
|
+
/* @__PURE__ */ jsx(Badge, { badgeContent: 100, color: "secondary", children: /* @__PURE__ */ jsx(
|
|
1040
|
+
Chip,
|
|
1041
|
+
{
|
|
1042
|
+
avatar: /* @__PURE__ */ jsx(Avatar, { children: "Q" }),
|
|
1043
|
+
variant: "outlined",
|
|
1044
|
+
label: "Waiting"
|
|
1045
|
+
}
|
|
1046
|
+
) }),
|
|
1047
|
+
/* @__PURE__ */ jsx(
|
|
1048
|
+
Badge,
|
|
554
1049
|
{
|
|
1050
|
+
badgeContent: 100,
|
|
1051
|
+
color: "warning",
|
|
555
1052
|
sx: {
|
|
556
|
-
|
|
557
|
-
alignItems: "center",
|
|
558
|
-
gap: 1
|
|
1053
|
+
margin: "10px"
|
|
559
1054
|
},
|
|
560
|
-
children:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
1055
|
+
children: /* @__PURE__ */ jsx(
|
|
1056
|
+
Chip,
|
|
1057
|
+
{
|
|
1058
|
+
avatar: /* @__PURE__ */ jsx(Avatar, { children: "C" }),
|
|
1059
|
+
label: "Pending",
|
|
1060
|
+
variant: "outlined"
|
|
1061
|
+
}
|
|
1062
|
+
)
|
|
1063
|
+
}
|
|
1064
|
+
),
|
|
1065
|
+
/* @__PURE__ */ jsx(
|
|
1066
|
+
Badge,
|
|
1067
|
+
{
|
|
1068
|
+
badgeContent: 100,
|
|
1069
|
+
color: "info",
|
|
1070
|
+
sx: {
|
|
1071
|
+
margin: "10px"
|
|
1072
|
+
},
|
|
1073
|
+
children: /* @__PURE__ */ jsx(
|
|
1074
|
+
Chip,
|
|
1075
|
+
{
|
|
1076
|
+
avatar: /* @__PURE__ */ jsx(Avatar, { children: "C" }),
|
|
1077
|
+
variant: "outlined",
|
|
1078
|
+
label: "Upcoming"
|
|
1079
|
+
}
|
|
1080
|
+
)
|
|
564
1081
|
}
|
|
565
1082
|
)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
MenuItem,
|
|
570
|
-
{
|
|
571
|
-
onClick: () => handleStatusChange("break"),
|
|
572
|
-
sx: {
|
|
573
|
-
backgroundColor: state.status === "break" ? "#0038f01c" : "initial"
|
|
574
|
-
},
|
|
575
|
-
children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
576
|
-
/* @__PURE__ */ jsx(FreeBreakfast, { color: "error" }),
|
|
577
|
-
/* @__PURE__ */ jsx(Typography, { children: "Break" })
|
|
578
|
-
] })
|
|
579
|
-
}
|
|
580
|
-
),
|
|
581
|
-
/* @__PURE__ */ jsx(
|
|
582
|
-
MenuItem,
|
|
583
|
-
{
|
|
584
|
-
onClick: () => handleStatusChange("idle"),
|
|
585
|
-
sx: {
|
|
586
|
-
backgroundColor: state.status === "idle" ? "#0038f01c" : "initial"
|
|
587
|
-
},
|
|
588
|
-
children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
589
|
-
/* @__PURE__ */ jsx(AirlineSeatIndividualSuite, { color: "warning" }),
|
|
590
|
-
/* @__PURE__ */ jsx(Typography, { children: "Idle" })
|
|
591
|
-
] })
|
|
592
|
-
}
|
|
593
|
-
)
|
|
594
|
-
]
|
|
1083
|
+
]
|
|
1084
|
+
}
|
|
1085
|
+
)
|
|
595
1086
|
}
|
|
596
1087
|
),
|
|
597
1088
|
/* @__PURE__ */ jsxs(
|
|
@@ -610,9 +1101,13 @@ function CallControlPanel({ onDataChange }) {
|
|
|
610
1101
|
/* @__PURE__ */ jsx(Groups, { color: "secondary" }),
|
|
611
1102
|
/* @__PURE__ */ jsx(Typography, { children: "Conference Call" })
|
|
612
1103
|
] }) }),
|
|
613
|
-
/* @__PURE__ */ jsx(MenuItem, { onClick: () =>
|
|
614
|
-
/* @__PURE__ */ jsx(
|
|
615
|
-
/* @__PURE__ */ jsx(Typography, { children: "
|
|
1104
|
+
/* @__PURE__ */ jsx(MenuItem, { onClick: () => handleStatusChange("break"), children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
1105
|
+
/* @__PURE__ */ jsx(FreeBreakfast, { color: "secondary" }),
|
|
1106
|
+
/* @__PURE__ */ jsx(Typography, { children: "Break" })
|
|
1107
|
+
] }) }),
|
|
1108
|
+
/* @__PURE__ */ jsx(MenuItem, { onClick: () => handleStatusChange("idle"), children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
|
|
1109
|
+
/* @__PURE__ */ jsx(AirlineSeatIndividualSuite, { color: "secondary" }),
|
|
1110
|
+
/* @__PURE__ */ jsx(Typography, { children: "Idle" })
|
|
616
1111
|
] }) })
|
|
617
1112
|
]
|
|
618
1113
|
}
|
|
@@ -621,14 +1116,16 @@ function CallControlPanel({ onDataChange }) {
|
|
|
621
1116
|
}
|
|
622
1117
|
|
|
623
1118
|
// src/index.ts
|
|
624
|
-
function
|
|
1119
|
+
function initSDK(sdkApiKey, tenantId, agentId, baseUrl) {
|
|
625
1120
|
sdkStateManager.initialize(sdkApiKey);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
1121
|
+
eventTracker.init({
|
|
1122
|
+
apiKey: sdkApiKey,
|
|
1123
|
+
tenantId,
|
|
1124
|
+
agentId,
|
|
1125
|
+
baseUrl
|
|
1126
|
+
});
|
|
629
1127
|
}
|
|
630
1128
|
export {
|
|
631
1129
|
CallControlPanel,
|
|
632
|
-
|
|
633
|
-
updateCallData
|
|
1130
|
+
initSDK
|
|
634
1131
|
};
|