@vgroup/dialbox 0.1.22 → 0.1.24

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.
@@ -1572,41 +1572,32 @@ class IncomingCallComponent {
1572
1572
  this.selectedIncomingCallInfo = new EventEmitter();
1573
1573
  }
1574
1574
  ngOnInit() {
1575
- // this.twilioService.currentCall.subscribe((call: any) => {
1576
- // if (call) {
1577
- // this.twilioCallData = call;
1578
- // this.notificationSerivce.showNotification(call);
1579
- // // Handle the call UI
1580
- // }
1581
- // });
1582
1575
  try {
1583
1576
  this.twilioService.currentCall.subscribe(call => {
1584
- if (call) {
1585
- const callSid = call.parameters?.['CallSid'];
1586
- if (!callSid)
1587
- return;
1588
- // Check if this call already exists in the list
1589
- const callExists = this.newIncomingCallsList?.some((item) => item.parameters?.['CallSid'] === callSid);
1590
- if (callExists) {
1591
- console.log('Call already exists in the list:', callSid);
1592
- return;
1577
+ if (call && call.parameters['CallSid']) {
1578
+ if (!this.newIncomingCallsList) {
1579
+ this.newIncomingCallsList = [];
1593
1580
  }
1594
- this.twilioCallData = call;
1595
- this.twilioAuthId = call.customParameters?.get('twilioAuthId');
1596
- if (!call.parameters) {
1597
- call.parameters = {};
1581
+ const callSid = call.parameters['CallSid'];
1582
+ const existingCall = this.newIncomingCallsList.find((c) => c.parameters['CallSid'] === callSid);
1583
+ if (!existingCall) {
1584
+ this.newIncomingCallsList.push(call);
1585
+ this.incomingCallsNewList.emit(this.newIncomingCallsList);
1586
+ if (!this.twilioCallData) {
1587
+ this.twilioCallData = call;
1588
+ this.twilioAuthId = call.customParameters.get('twilioAuthId');
1589
+ if (!call.parameters) {
1590
+ call.parameters = {};
1591
+ }
1592
+ this.sendIPforIncomingCall(this.twilioAuthId, '');
1593
+ }
1594
+ call.on('cancel', () => {
1595
+ this.removeCallFromList(callSid);
1596
+ });
1597
+ call.on('disconnect', () => {
1598
+ this.removeCallFromList(callSid);
1599
+ });
1598
1600
  }
1599
- // Add call to the list
1600
- this.newIncomingCallsList = [...(this.newIncomingCallsList || []), call];
1601
- this.incomingCallsNewList.emit(this.newIncomingCallsList);
1602
- this.sendIPforIncomingCall(this.twilioAuthId, '');
1603
- // Set up event handlers for the call
1604
- call.on('cancel', () => {
1605
- this.handleCallEnd(call, callSid);
1606
- });
1607
- call.on('disconnect', () => {
1608
- this.handleCallEnd(call, callSid);
1609
- });
1610
1601
  }
1611
1602
  });
1612
1603
  }
@@ -1629,52 +1620,30 @@ class IncomingCallComponent {
1629
1620
  }
1630
1621
  });
1631
1622
  }
1632
- // Helper method to handle call end events
1633
- handleCallEnd(call, callSid) {
1634
- if (!callSid)
1635
- return;
1636
- // Remove call from the list
1623
+ removeCallFromList(callSid) {
1637
1624
  if (this.newIncomingCallsList) {
1638
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters?.['CallSid'] !== callSid);
1639
- this.incomingCallsNewList.emit([...this.newIncomingCallsList]);
1640
- // Close UI if no more calls
1625
+ this.newIncomingCallsList = this.newIncomingCallsList.filter((c) => c.parameters['CallSid'] !== callSid);
1626
+ this.incomingCallsNewList.emit(this.newIncomingCallsList);
1641
1627
  if (this.newIncomingCallsList.length === 0) {
1642
- this.closeIncomingCallDiv.emit({ show: 0, call });
1628
+ this.closeIncomingCallDiv.emit({ show: 0, call: null });
1643
1629
  }
1644
1630
  }
1645
1631
  }
1646
1632
  rejectCallFromList(data) {
1647
1633
  if (!data)
1648
1634
  return;
1649
- const callSid = data.parameters?.['CallSid'];
1650
- if (!callSid)
1651
- return;
1652
- try {
1653
- // Try to reject or disconnect the call
1654
- if (typeof data.reject === 'function') {
1655
- data.reject();
1656
- }
1657
- else if (typeof data.disconnect === 'function') {
1658
- data.disconnect();
1659
- }
1660
- // Update call status
1661
- if (data.parameters) {
1662
- data.parameters['isCallConnected'] = false;
1663
- }
1664
- // Update call status on the server
1665
- if (data.customParameters) {
1666
- const twilioAuthId = data.customParameters.get('twilioAuthId');
1667
- if (twilioAuthId) {
1668
- this.sendIPforIncomingCall(twilioAuthId, 'completed');
1669
- }
1670
- }
1671
- // Remove call from the list
1672
- this.handleCallEnd(data, callSid);
1635
+ if (data.reject)
1636
+ data.reject();
1637
+ if (data.disconnect)
1638
+ data.disconnect();
1639
+ if (data.parameters) {
1640
+ data.parameters['isCallConnected'] = false; // Should be false when rejecting
1673
1641
  }
1674
- catch (error) {
1675
- console.error('Error rejecting call:', error);
1676
- // Make sure to clean up even if there's an error
1677
- this.handleCallEnd(data, callSid);
1642
+ if (data.customParameters) {
1643
+ this.sendIPforIncomingCall(data.customParameters.get('twilioAuthId'), 'answered');
1644
+ }
1645
+ if (this.newIncomingCallsList && data && data.parameters && data.parameters.CallSid) {
1646
+ this.removeCallFromList(data.parameters.CallSid);
1678
1647
  }
1679
1648
  }
1680
1649
  closeIncomingCallWrapper(val) {
@@ -2169,6 +2138,9 @@ class CallProgressComponent {
2169
2138
  incomingCallsNewList(data) {
2170
2139
  this.newIncomingCallsList = data;
2171
2140
  this.incomingCallsNewInfo.emit(this.newIncomingCallsList);
2141
+ if (!data || data.length === 0) {
2142
+ this.incomingCallDiv = false;
2143
+ }
2172
2144
  }
2173
2145
  selectedIncomingCallInfo(data) {
2174
2146
  this.selectedIncomingCall = data;