@vgroup/dialbox 0.1.20 → 0.1.22

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.
@@ -1582,23 +1582,30 @@ class IncomingCallComponent {
1582
1582
  try {
1583
1583
  this.twilioService.currentCall.subscribe(call => {
1584
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;
1593
+ }
1585
1594
  this.twilioCallData = call;
1586
- this.twilioAuthId = call.customParameters.get('twilioAuthId');
1595
+ this.twilioAuthId = call.customParameters?.get('twilioAuthId');
1587
1596
  if (!call.parameters) {
1588
1597
  call.parameters = {};
1589
1598
  }
1599
+ // Add call to the list
1600
+ this.newIncomingCallsList = [...(this.newIncomingCallsList || []), call];
1601
+ this.incomingCallsNewList.emit(this.newIncomingCallsList);
1590
1602
  this.sendIPforIncomingCall(this.twilioAuthId, '');
1603
+ // Set up event handlers for the call
1591
1604
  call.on('cancel', () => {
1592
- if (this.incomingCallData && this.incomingCallData.parameters && this.incomingCallData.parameters.CallSid) {
1593
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters && item.parameters.CallSid !== this.incomingCallData.parameters.CallSid);
1594
- }
1595
- this.rejectCallFromList(call);
1605
+ this.handleCallEnd(call, callSid);
1596
1606
  });
1597
1607
  call.on('disconnect', () => {
1598
- if (this.incomingCallData && this.incomingCallData.parameters && this.incomingCallData.parameters.CallSid) {
1599
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters && item.parameters.CallSid !== this.incomingCallData.parameters.CallSid);
1600
- }
1601
- this.rejectCallFromList(call);
1608
+ this.handleCallEnd(call, callSid);
1602
1609
  });
1603
1610
  }
1604
1611
  });
@@ -1622,47 +1629,52 @@ class IncomingCallComponent {
1622
1629
  }
1623
1630
  });
1624
1631
  }
1625
- async rejectCallFromList(data) {
1632
+ // Helper method to handle call end events
1633
+ handleCallEnd(call, callSid) {
1634
+ if (!callSid)
1635
+ return;
1636
+ // Remove call from the list
1637
+ 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
1641
+ if (this.newIncomingCallsList.length === 0) {
1642
+ this.closeIncomingCallDiv.emit({ show: 0, call });
1643
+ }
1644
+ }
1645
+ }
1646
+ rejectCallFromList(data) {
1626
1647
  if (!data)
1627
1648
  return;
1649
+ const callSid = data.parameters?.['CallSid'];
1650
+ if (!callSid)
1651
+ return;
1628
1652
  try {
1629
- // First try to reject the call if it's incoming
1653
+ // Try to reject or disconnect the call
1630
1654
  if (typeof data.reject === 'function') {
1631
1655
  data.reject();
1632
1656
  }
1633
- // If reject doesn't work (e.g., for connected calls), try disconnect
1634
1657
  else if (typeof data.disconnect === 'function') {
1635
1658
  data.disconnect();
1636
1659
  }
1637
- // Update call parameters
1660
+ // Update call status
1638
1661
  if (data.parameters) {
1639
1662
  data.parameters['isCallConnected'] = false;
1640
1663
  }
1641
- // Send call status update if we have auth ID
1664
+ // Update call status on the server
1642
1665
  if (data.customParameters) {
1643
1666
  const twilioAuthId = data.customParameters.get('twilioAuthId');
1644
1667
  if (twilioAuthId) {
1645
- await this.sendIPforIncomingCall(twilioAuthId, 'completed');
1668
+ this.sendIPforIncomingCall(twilioAuthId, 'completed');
1646
1669
  }
1647
1670
  }
1648
1671
  // Remove call from the list
1649
- if (this.newIncomingCallsList && data.parameters?.CallSid) {
1650
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters?.CallSid !== data.parameters.CallSid);
1651
- this.incomingCallsNewList.emit([...this.newIncomingCallsList]);
1652
- // Close the UI if no more calls
1653
- if (this.newIncomingCallsList.length === 0) {
1654
- this.closeIncomingCallDiv.emit({ show: 0, call: data });
1655
- }
1656
- }
1672
+ this.handleCallEnd(data, callSid);
1657
1673
  }
1658
1674
  catch (error) {
1659
1675
  console.error('Error rejecting call:', error);
1660
- // Even if there's an error, try to clean up the UI
1661
- if (this.newIncomingCallsList && data.parameters?.CallSid) {
1662
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters?.CallSid !== data.parameters.CallSid);
1663
- this.incomingCallsNewList.emit([...this.newIncomingCallsList]);
1664
- }
1665
- this.closeIncomingCallDiv.emit({ show: 0, call: data });
1676
+ // Make sure to clean up even if there's an error
1677
+ this.handleCallEnd(data, callSid);
1666
1678
  }
1667
1679
  }
1668
1680
  closeIncomingCallWrapper(val) {