@vgroup/dialbox 0.0.84 → 0.0.85
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/esm2020/lib/components/call-progress/incoming-call/incoming-call.component.mjs +52 -31
- package/esm2020/lib/service/twilio.service.mjs +13 -1
- package/fesm2015/vgroup-dialbox.mjs +65 -31
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +63 -31
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/components/call-progress/incoming-call/incoming-call.component.d.ts +6 -2
- package/lib/service/twilio.service.d.ts +3 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, NgModule } from '@angular/core';
|
|
3
3
|
import swal from 'sweetalert2';
|
|
4
4
|
import { AsYouType } from 'libphonenumber-js';
|
|
5
|
-
import { throwError, BehaviorSubject, of,
|
|
5
|
+
import { throwError, BehaviorSubject, of, Subscription, filter, interval } from 'rxjs';
|
|
6
6
|
import * as i1 from '@angular/common/http';
|
|
7
7
|
import { HttpHeaders, HttpParams, HttpClientModule } from '@angular/common/http';
|
|
8
8
|
import { catchError, switchMap, map, tap, shareReplay } from 'rxjs/operators';
|
|
@@ -1389,6 +1389,9 @@ class TwilioService {
|
|
|
1389
1389
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
1390
1390
|
this.tokenInitialized = false;
|
|
1391
1391
|
this.tokenInitialization$ = null;
|
|
1392
|
+
this.lastCallSid = null;
|
|
1393
|
+
this.lastCallTime = 0;
|
|
1394
|
+
this.CALL_DEBOUNCE_MS = 1000; // 1 second debounce
|
|
1392
1395
|
this.initializeToken();
|
|
1393
1396
|
}
|
|
1394
1397
|
initializeToken() {
|
|
@@ -1429,6 +1432,15 @@ class TwilioService {
|
|
|
1429
1432
|
});
|
|
1430
1433
|
this.device.register();
|
|
1431
1434
|
this.device.on('incoming', (call) => {
|
|
1435
|
+
const callSid = call.parameters?.['CallSid'];
|
|
1436
|
+
const now = Date.now();
|
|
1437
|
+
// Skip if this is a duplicate call within the debounce window
|
|
1438
|
+
if (callSid && callSid === this.lastCallSid && (now - this.lastCallTime) < this.CALL_DEBOUNCE_MS) {
|
|
1439
|
+
console.log('Skipping duplicate call:', callSid);
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
this.lastCallSid = callSid;
|
|
1443
|
+
this.lastCallTime = now;
|
|
1432
1444
|
this.currentCall.next(call);
|
|
1433
1445
|
this.callType.next('INCOMING');
|
|
1434
1446
|
this.currentCallState.next('incoming');
|
|
@@ -1568,43 +1580,63 @@ class IncomingCallComponent {
|
|
|
1568
1580
|
this.closeIncomingCallDiv = new EventEmitter();
|
|
1569
1581
|
this.incomingCallsNewList = new EventEmitter();
|
|
1570
1582
|
this.selectedIncomingCallInfo = new EventEmitter();
|
|
1583
|
+
this.subscription = new Subscription();
|
|
1584
|
+
this.callHandled = new Set(); // Track handled calls by CallSid
|
|
1571
1585
|
}
|
|
1572
1586
|
ngOnInit() {
|
|
1573
|
-
// this.twilioService.currentCall.subscribe((call: any) => {
|
|
1574
|
-
// if (call) {
|
|
1575
|
-
// this.twilioCallData = call;
|
|
1576
|
-
// this.notificationSerivce.showNotification(call);
|
|
1577
|
-
// // Handle the call UI
|
|
1578
|
-
// }
|
|
1579
|
-
// });
|
|
1580
1587
|
try {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
if (this.incomingCallData && this.incomingCallData.parameters && this.incomingCallData.parameters.CallSid) {
|
|
1597
|
-
this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters && item.parameters.CallSid !== this.incomingCallData.parameters.CallSid);
|
|
1598
|
-
}
|
|
1599
|
-
this.rejectCallFromList(call);
|
|
1600
|
-
});
|
|
1601
|
-
}
|
|
1602
|
-
});
|
|
1588
|
+
// Only handle the call if we have incomingCallData
|
|
1589
|
+
if (this.incomingCallData) {
|
|
1590
|
+
this.handleIncomingCall(this.incomingCallData);
|
|
1591
|
+
}
|
|
1592
|
+
// Subscribe to new calls
|
|
1593
|
+
this.subscription.add(this.twilioService.currentCall.pipe(
|
|
1594
|
+
// Filter out duplicate calls that we've already handled
|
|
1595
|
+
filter((call) => {
|
|
1596
|
+
if (!call)
|
|
1597
|
+
return false;
|
|
1598
|
+
const callSid = call.parameters['CallSid'];
|
|
1599
|
+
return callSid && !this.callHandled.has(callSid);
|
|
1600
|
+
})).subscribe(call => {
|
|
1601
|
+
this.handleIncomingCall(call);
|
|
1602
|
+
}));
|
|
1603
1603
|
}
|
|
1604
1604
|
catch (e) {
|
|
1605
|
-
console.
|
|
1605
|
+
console.error('Error in incoming call handling:', e);
|
|
1606
1606
|
}
|
|
1607
1607
|
}
|
|
1608
|
+
handleIncomingCall(call) {
|
|
1609
|
+
if (!call)
|
|
1610
|
+
return;
|
|
1611
|
+
const callSid = call.parameters?.CallSid;
|
|
1612
|
+
if (!callSid || this.callHandled.has(callSid)) {
|
|
1613
|
+
return; // Skip if no CallSid or already handled
|
|
1614
|
+
}
|
|
1615
|
+
this.callHandled.add(callSid);
|
|
1616
|
+
this.twilioCallData = call;
|
|
1617
|
+
this.twilioAuthId = call.customParameters?.get('twilioAuthId');
|
|
1618
|
+
if (!call.parameters) {
|
|
1619
|
+
call.parameters = {};
|
|
1620
|
+
}
|
|
1621
|
+
// Send IP for the incoming call
|
|
1622
|
+
this.sendIPforIncomingCall(this.twilioAuthId, '');
|
|
1623
|
+
// Setup call event handlers
|
|
1624
|
+
const handleCallEnd = () => {
|
|
1625
|
+
if (callSid) {
|
|
1626
|
+
this.callHandled.delete(callSid);
|
|
1627
|
+
if (this.newIncomingCallsList) {
|
|
1628
|
+
this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters?.CallSid !== callSid);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
this.rejectCallFromList(call);
|
|
1632
|
+
};
|
|
1633
|
+
call.on('cancel', handleCallEnd);
|
|
1634
|
+
call.on('disconnect', handleCallEnd);
|
|
1635
|
+
}
|
|
1636
|
+
ngOnDestroy() {
|
|
1637
|
+
this.subscription.unsubscribe();
|
|
1638
|
+
this.callHandled.clear();
|
|
1639
|
+
}
|
|
1608
1640
|
acceptCallFromList(data) {
|
|
1609
1641
|
data.accept();
|
|
1610
1642
|
// data.parameters['isCallConnected'] = true;
|