@vgroup/dialbox 0.0.60 → 0.0.61

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.
@@ -1294,10 +1294,83 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1294
1294
  }]
1295
1295
  }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: IpAddressService }]; } });
1296
1296
 
1297
+ class NotificationService {
1298
+ constructor(twilioService) {
1299
+ this.twilioService = twilioService;
1300
+ this.redirectUrl = window.location.href;
1301
+ if ('serviceWorker' in navigator) {
1302
+ navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerMessage.bind(this));
1303
+ }
1304
+ }
1305
+ showNotification(callData) {
1306
+ this.twilioAuthId = callData.customParameters.get('twilioAuthId');
1307
+ this.twilioCallData = callData;
1308
+ const incomingNumber = callData.parameters.From;
1309
+ const callerName = callData.customParameters.get('name');
1310
+ const callerImage = callData.customParameters.get('image');
1311
+ if (('serviceWorker' in navigator)) {
1312
+ navigator.serviceWorker.ready.then((registration) => {
1313
+ const options = {
1314
+ body: `Incoming call from ${callerName || incomingNumber}`,
1315
+ icon: callerImage,
1316
+ actions: [
1317
+ {
1318
+ action: 'accept',
1319
+ title: 'Accept',
1320
+ icon: '../../../assets/images/notification-icons/call-accept-icon.png'
1321
+ },
1322
+ {
1323
+ action: 'reject',
1324
+ title: 'Reject',
1325
+ icon: '../../../assets/images/notification-icons/call-reject-icon.jpg'
1326
+ }
1327
+ ],
1328
+ data: {
1329
+ url: this.redirectUrl,
1330
+ },
1331
+ requireInteraction: true,
1332
+ };
1333
+ registration.showNotification('Icoming Call', options);
1334
+ });
1335
+ }
1336
+ }
1337
+ handleServiceWorkerMessage(event) {
1338
+ if (!event.data)
1339
+ return;
1340
+ switch (event.data.action) {
1341
+ case 'accept':
1342
+ this.onNotificationAccept();
1343
+ break;
1344
+ case 'reject':
1345
+ this.onNotificationReject();
1346
+ break;
1347
+ default:
1348
+ console.log('default action:');
1349
+ break;
1350
+ }
1351
+ }
1352
+ onNotificationAccept() {
1353
+ this.twilioService.callhandleFromNotification.next({ callStatus: 'accept' });
1354
+ }
1355
+ onNotificationReject() {
1356
+ this.twilioService.callhandleFromNotification.next({ callStatus: 'reject' });
1357
+ }
1358
+ }
1359
+ NotificationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, deps: [{ token: TwilioService }], target: i0.ɵɵFactoryTarget.Injectable });
1360
+ NotificationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, providedIn: 'root' });
1361
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, decorators: [{
1362
+ type: Injectable,
1363
+ args: [{
1364
+ providedIn: 'root'
1365
+ }]
1366
+ }], ctorParameters: function () { return [{ type: TwilioService }]; } });
1367
+
1297
1368
  class TwilioService {
1298
- constructor(http, extensionService) {
1369
+ constructor(http, extensionService, notificationSerivce, twilioService) {
1299
1370
  this.http = http;
1300
1371
  this.extensionService = extensionService;
1372
+ this.notificationSerivce = notificationSerivce;
1373
+ this.twilioService = twilioService;
1301
1374
  this.openInProgressDialpad = new BehaviorSubject(false);
1302
1375
  this.currentCall = new BehaviorSubject(null);
1303
1376
  this.currentCallState = new BehaviorSubject('none'); //in-progress, out-progress, none
@@ -1315,26 +1388,53 @@ class TwilioService {
1315
1388
  this.isAvailableNumber = new BehaviorSubject(false);
1316
1389
  this.callerIdList = new BehaviorSubject([]);
1317
1390
  this.triggerSMSReload = new BehaviorSubject(false);
1391
+ this.isTwilioConnected = false;
1392
+ this.doNotDisturb = true;
1318
1393
  this.initializeTwilioDevice();
1319
1394
  }
1320
1395
  initializeTwilioDevice() {
1321
- if (this.token) {
1396
+ // if (this.token) {
1397
+ // this.extensionService.getIncomingCallToken().subscribe((data: any) => {
1398
+ // this.incomingCallToken = data.token;
1399
+ // localStorage.setItem('in-token', data.token);
1400
+ // this.device = new Device(this.incomingCallToken!, {
1401
+ // allowIncomingWhileBusy: true,
1402
+ // // Add any other necessary options
1403
+ // });
1404
+ // this.device.register();
1405
+ // this.device.on('incoming', (call: Call) => {
1406
+ // this.currentCall.next(call);
1407
+ // this.callType.next('INCOMING');
1408
+ // this.currentCallState.next('incoming');
1409
+ // this.notificationSerivce.showNotification(call);
1410
+ // });
1411
+ // this.device.on('error', (error: any) => {
1412
+ // console.error('Twilio Device Error:', error);
1413
+ // // Add error handling and reconnection logic
1414
+ // });
1415
+ // });
1416
+ // }
1417
+ if (localStorage.getItem('in-token')) {
1418
+ this.isTwilioConnected = true;
1419
+ this.doNotDisturb = false;
1322
1420
  this.extensionService.getIncomingCallToken().subscribe((data) => {
1323
- this.incomingCallToken = data.token;
1421
+ this.twilioService.incomingCallToken = data.token;
1324
1422
  localStorage.setItem('in-token', data.token);
1325
- this.device = new Device(this.incomingCallToken, {
1326
- allowIncomingWhileBusy: true,
1327
- // Add any other necessary options
1328
- });
1329
- this.device.register();
1330
- this.device.on('incoming', (call) => {
1331
- this.currentCall.next(call);
1332
- this.callType.next('INCOMING');
1333
- this.currentCallState.next('incoming');
1423
+ this.isTwilioConnected = true;
1424
+ if (!this.twilioService.incomingCallToken) {
1425
+ console.error('Cannot initialize Twilio device: No incoming call token available');
1426
+ return;
1427
+ }
1428
+ this.twilioService.device = new Device(this.twilioService.incomingCallToken, { allowIncomingWhileBusy: true });
1429
+ this.twilioService.device.register();
1430
+ this.twilioService.device.on('incoming', (call) => {
1431
+ this.twilioService.currentCall.next(call);
1432
+ this.twilioService.callType.next('INCOMING');
1433
+ this.notificationSerivce.showNotification(call);
1434
+ //this.twilioService.openInProgressDialpad.next(true);
1334
1435
  });
1335
- this.device.on('error', (error) => {
1336
- console.error('Twilio Device Error:', error);
1337
- // Add error handling and reconnection logic
1436
+ this.twilioService.device.on('error', (err) => {
1437
+ console.log(err);
1338
1438
  });
1339
1439
  });
1340
1440
  }
@@ -1431,14 +1531,14 @@ class TwilioService {
1431
1531
  return this.http.get(environment.apiUrl + '/utilities/softphone/check/countryCode/' + dialledNo, httpOptions);
1432
1532
  }
1433
1533
  }
1434
- TwilioService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, deps: [{ token: i1.HttpClient }, { token: ExtensionService }], target: i0.ɵɵFactoryTarget.Injectable });
1534
+ TwilioService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, deps: [{ token: i1.HttpClient }, { token: ExtensionService }, { token: NotificationService }, { token: TwilioService }], target: i0.ɵɵFactoryTarget.Injectable });
1435
1535
  TwilioService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, providedIn: 'root' });
1436
1536
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, decorators: [{
1437
1537
  type: Injectable,
1438
1538
  args: [{
1439
1539
  providedIn: 'root'
1440
1540
  }]
1441
- }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: ExtensionService }]; } });
1541
+ }], ctorParameters: function () { return [{ type: i1.HttpClient }, { type: ExtensionService }, { type: NotificationService }, { type: TwilioService }]; } });
1442
1542
 
1443
1543
  const GlobalConstant = {
1444
1544
  ErrorMsg500: "Unable to process request. Please try again later.",
@@ -1446,77 +1546,6 @@ const GlobalConstant = {
1446
1546
  dedicatedNumText: 'C2C Number'
1447
1547
  };
1448
1548
 
1449
- class NotificationService {
1450
- constructor(twilioService) {
1451
- this.twilioService = twilioService;
1452
- this.redirectUrl = window.location.href;
1453
- if ('serviceWorker' in navigator) {
1454
- navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerMessage.bind(this));
1455
- }
1456
- }
1457
- showNotification(callData) {
1458
- this.twilioAuthId = callData.customParameters.get('twilioAuthId');
1459
- this.twilioCallData = callData;
1460
- const incomingNumber = callData.parameters.From;
1461
- const callerName = callData.customParameters.get('name');
1462
- const callerImage = callData.customParameters.get('image');
1463
- if (('serviceWorker' in navigator)) {
1464
- navigator.serviceWorker.ready.then((registration) => {
1465
- const options = {
1466
- body: `Incoming call from ${callerName || incomingNumber}`,
1467
- icon: callerImage,
1468
- actions: [
1469
- {
1470
- action: 'accept',
1471
- title: 'Accept',
1472
- icon: '../../../assets/images/notification-icons/call-accept-icon.png'
1473
- },
1474
- {
1475
- action: 'reject',
1476
- title: 'Reject',
1477
- icon: '../../../assets/images/notification-icons/call-reject-icon.jpg'
1478
- }
1479
- ],
1480
- data: {
1481
- url: this.redirectUrl,
1482
- },
1483
- requireInteraction: true,
1484
- };
1485
- registration.showNotification('Icoming Call', options);
1486
- });
1487
- }
1488
- }
1489
- handleServiceWorkerMessage(event) {
1490
- if (!event.data)
1491
- return;
1492
- switch (event.data.action) {
1493
- case 'accept':
1494
- this.onNotificationAccept();
1495
- break;
1496
- case 'reject':
1497
- this.onNotificationReject();
1498
- break;
1499
- default:
1500
- console.log('default action:');
1501
- break;
1502
- }
1503
- }
1504
- onNotificationAccept() {
1505
- this.twilioService.callhandleFromNotification.next({ callStatus: 'accept' });
1506
- }
1507
- onNotificationReject() {
1508
- this.twilioService.callhandleFromNotification.next({ callStatus: 'reject' });
1509
- }
1510
- }
1511
- NotificationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, deps: [{ token: TwilioService }], target: i0.ɵɵFactoryTarget.Injectable });
1512
- NotificationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, providedIn: 'root' });
1513
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NotificationService, decorators: [{
1514
- type: Injectable,
1515
- args: [{
1516
- providedIn: 'root'
1517
- }]
1518
- }], ctorParameters: function () { return [{ type: TwilioService }]; } });
1519
-
1520
1549
  class IncomingCallComponent {
1521
1550
  constructor(extensionService, twilioService, notificationSerivce) {
1522
1551
  this.extensionService = extensionService;
@@ -2223,14 +2252,6 @@ class DialboxComponent {
2223
2252
  try {
2224
2253
  this.getContactList();
2225
2254
  this.getUserCallSetting();
2226
- // Subscribe to incoming calls and show dialpad when a call comes in
2227
- this.subscriptions.add(this.twilioService.currentCall.subscribe((call) => {
2228
- if (call && call.parameters && call.parameters.Direction === 'incoming') {
2229
- // Show the dialpad when an incoming call is received
2230
- this._isDialpadHidden = false;
2231
- this.incomingCallInitiated.emit();
2232
- }
2233
- }));
2234
2255
  // Subscribe to dial number events
2235
2256
  const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
2236
2257
  if (contact.number) {