@vgroup/dialbox 0.1.17 → 0.1.20

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.
@@ -1430,6 +1430,7 @@ class TwilioService {
1430
1430
  console.log("device created");
1431
1431
  this.device.register();
1432
1432
  this.device.on('incoming', (call) => {
1433
+ console.log("incoming call", call);
1433
1434
  this.currentCall.next(call);
1434
1435
  this.callType.next('INCOMING');
1435
1436
  this.currentCallState.next('incoming');
@@ -1621,26 +1622,48 @@ class IncomingCallComponent {
1621
1622
  }
1622
1623
  });
1623
1624
  }
1624
- rejectCallFromList(data) {
1625
+ async rejectCallFromList(data) {
1625
1626
  if (!data)
1626
1627
  return;
1627
- if (data.reject)
1628
- data.reject();
1629
- if (data.disconnect)
1630
- data.disconnect();
1631
- if (data.parameters) {
1632
- data.parameters['isCallConnected'] = false; // Should be false when rejecting
1633
- }
1634
- if (data.customParameters) {
1635
- this.sendIPforIncomingCall(data.customParameters.get('twilioAuthId'), 'answered');
1636
- }
1637
- if (this.newIncomingCallsList && data && data.parameters && data.parameters.CallSid) {
1638
- this.newIncomingCallsList = this.newIncomingCallsList.filter((item) => item.parameters && item.parameters.CallSid !== data.parameters.CallSid);
1639
- this.incomingCallsNewList.emit(this.newIncomingCallsList);
1640
- if (this.newIncomingCallsList.length == 0) {
1641
- this.closeIncomingCallDiv.emit({ show: 0, call: data });
1628
+ try {
1629
+ // First try to reject the call if it's incoming
1630
+ if (typeof data.reject === 'function') {
1631
+ data.reject();
1632
+ }
1633
+ // If reject doesn't work (e.g., for connected calls), try disconnect
1634
+ else if (typeof data.disconnect === 'function') {
1635
+ data.disconnect();
1636
+ }
1637
+ // Update call parameters
1638
+ if (data.parameters) {
1639
+ data.parameters['isCallConnected'] = false;
1640
+ }
1641
+ // Send call status update if we have auth ID
1642
+ if (data.customParameters) {
1643
+ const twilioAuthId = data.customParameters.get('twilioAuthId');
1644
+ if (twilioAuthId) {
1645
+ await this.sendIPforIncomingCall(twilioAuthId, 'completed');
1646
+ }
1647
+ }
1648
+ // 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
+ }
1642
1656
  }
1643
1657
  }
1658
+ catch (error) {
1659
+ 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 });
1666
+ }
1644
1667
  }
1645
1668
  closeIncomingCallWrapper(val) {
1646
1669
  this.closeIncomingCallDiv.emit({ show: val, call: this.twilioCallData });
@@ -2234,9 +2257,9 @@ class DialboxComponent {
2234
2257
  this.isInitialized = false;
2235
2258
  this.isMinimised = false;
2236
2259
  // Initialize if dialpad is visible by default
2237
- this.initializeTwilio();
2238
2260
  if (!this.isDialpadHidden) {
2239
2261
  console.log('sfsdfdsf');
2262
+ this.initializeTwilio();
2240
2263
  }
2241
2264
  }
2242
2265
  initializeTwilio() {
@@ -2248,7 +2271,6 @@ class DialboxComponent {
2248
2271
  }
2249
2272
  this.isInitialized = true;
2250
2273
  // Initialize Twilio service
2251
- console.log('Initializing Twilio service');
2252
2274
  this.twilioService.initializeTwilioDevice();
2253
2275
  // Subscribe to incoming calls to show dialpad when call comes in
2254
2276
  const callSub = this.twilioService.currentCall.subscribe(call => {
@@ -2260,9 +2282,6 @@ class DialboxComponent {
2260
2282
  });
2261
2283
  this.subscriptions.add(callSub);
2262
2284
  }
2263
- setTimeout(() => {
2264
- this.isInitialized = false;
2265
- }, 1000);
2266
2285
  }
2267
2286
  // ngOnChange() {
2268
2287
  // this.initializeTwilio();
@@ -2366,8 +2385,8 @@ class DialboxComponent {
2366
2385
  // }
2367
2386
  // }
2368
2387
  ngOnInit() {
2388
+ console.log('ngOnInit');
2369
2389
  try {
2370
- console.log('ngOnInit');
2371
2390
  this.token = localStorage.getItem('ext_token') || '';
2372
2391
  //this.isCallInProgress = true;
2373
2392
  this.getContactList();
@@ -2484,7 +2503,7 @@ class DialboxComponent {
2484
2503
  if (!alreadyExists) {
2485
2504
  this.incomingCallsList.push(incomingCallData);
2486
2505
  }
2487
- this.cdk.markForCheck();
2506
+ this.cdk.detectChanges();
2488
2507
  }, error => {
2489
2508
  console.error('Error starting recording', error);
2490
2509
  });