@vgroup/dialbox 0.1.28 → 0.1.30

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.
@@ -1399,6 +1399,7 @@ class TwilioService {
1399
1399
  this.incomingCallToken = data.token;
1400
1400
  localStorage.setItem('in-token', data.token);
1401
1401
  this.tokenInitialized = true;
1402
+ console.log('dfdfdsfdsfds');
1402
1403
  this.initializeDevice();
1403
1404
  }), catchError(error => {
1404
1405
  console.error('Error initializing Twilio token:', error);
@@ -1415,50 +1416,9 @@ class TwilioService {
1415
1416
  this.initializeToken().subscribe();
1416
1417
  }
1417
1418
  }
1418
- // private initializeDevice() {
1419
- // if (this.device) {
1420
- // this.device.destroy();
1421
- // }
1422
- // if (!this.incomingCallToken) {
1423
- // console.error('No Twilio token available');
1424
- // return;
1425
- // }
1426
- // this.device = new Device(this.incomingCallToken, {
1427
- // allowIncomingWhileBusy: true,
1428
- // closeProtection: true
1429
- // });
1430
- // console.log("device created")
1431
- // this.device.register();
1432
- // this.device.on('incoming', (call: Call) => {
1433
- // console.log("incoming call",call)
1434
- // this.currentCall.next(call);
1435
- // this.callType.next('INCOMING');
1436
- // this.currentCallState.next('incoming');
1437
- // this.notificationSerivce.showNotification(call);
1438
- // });
1439
- // this.device.on('error', (error: any) => {
1440
- // console.error('Twilio Device Error:', error);
1441
- // // Reset initialization state on error to allow retry
1442
- // this.tokenInitialized = false;
1443
- // });
1444
- // this.device.on('registered', () => {
1445
- // console.log('Twilio Device registered successfully');
1446
- // });
1447
- // this.device.on('unregistered', () => {
1448
- // console.log('Twilio Device unregistered');
1449
- // this.tokenInitialized = false;
1450
- // });
1451
- // }
1452
- // onIncomingCall(){
1453
- // this.device.on('incoming', (call:any) => {
1454
- // console.log(call);
1455
- // //call.accept();
1456
- // });
1457
- // }
1458
1419
  initializeDevice() {
1459
1420
  if (this.device) {
1460
1421
  this.device.destroy();
1461
- this.device = null;
1462
1422
  }
1463
1423
  if (!this.incomingCallToken) {
1464
1424
  console.error('No Twilio token available');
@@ -1468,18 +1428,18 @@ class TwilioService {
1468
1428
  allowIncomingWhileBusy: true,
1469
1429
  closeProtection: true
1470
1430
  });
1431
+ console.log("device created");
1471
1432
  this.device.register();
1472
- // Remove previous handlers to avoid duplicates
1473
- this.device.removeAllListeners('incoming');
1474
1433
  this.device.on('incoming', (call) => {
1475
1434
  console.log("incoming call", call);
1476
- this.currentCall.next(call); // ✅ fires only once per real call
1435
+ this.currentCall.next(call);
1477
1436
  this.callType.next('INCOMING');
1478
1437
  this.currentCallState.next('incoming');
1479
1438
  this.notificationSerivce.showNotification(call);
1480
1439
  });
1481
1440
  this.device.on('error', (error) => {
1482
1441
  console.error('Twilio Device Error:', error);
1442
+ // Reset initialization state on error to allow retry
1483
1443
  this.tokenInitialized = false;
1484
1444
  });
1485
1445
  this.device.on('registered', () => {
@@ -1490,6 +1450,12 @@ class TwilioService {
1490
1450
  this.tokenInitialized = false;
1491
1451
  });
1492
1452
  }
1453
+ // onIncomingCall(){
1454
+ // this.device.on('incoming', (call:any) => {
1455
+ // console.log(call);
1456
+ // //call.accept();
1457
+ // });
1458
+ // }
1493
1459
  saveContact(payload) {
1494
1460
  const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
1495
1461
  return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
@@ -2512,7 +2478,7 @@ class DialboxComponent {
2512
2478
  console.log('366---', data);
2513
2479
  this.extensionService.getUserInformation(data['twilioAuthId']).subscribe(response => {
2514
2480
  incomingCallData['userInfo'] = response;
2515
- const alreadyExists = this.incomingCallsList.some((call) => call.parameters?.CallSid === incomingCallData.parameters?.CallSid);
2481
+ const alreadyExists = this.incomingCallsList.some((call) => call.parameters?.From === incomingCallData.parameters?.From || call.parameters?.CallSid === incomingCallData.parameters?.CallSid);
2516
2482
  if (!alreadyExists) {
2517
2483
  this.incomingCallsList.push(incomingCallData);
2518
2484
  }
@@ -2558,9 +2524,11 @@ class DialboxComponent {
2558
2524
  if (this.incomingCallsList.length == 0) {
2559
2525
  this.isCallInProgress = false;
2560
2526
  }
2527
+ this.incomingCallData.disconnect();
2561
2528
  });
2562
2529
  this.incomingCallData.on('disconnect', () => {
2563
2530
  this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters['CallSid'] !== this.incomingCallData.parameters['CallSid']);
2531
+ this.incomingCallData.disconnect();
2564
2532
  if (this.incomingCallsList.length == 0) {
2565
2533
  this.isCallInProgress = false;
2566
2534
  }