@vgroup/dialbox 0.1.67 → 0.1.68
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.
- package/esm2020/lib/service/extension.service.mjs +2 -34
- package/esm2020/lib/service/twilio.service.mjs +9 -66
- package/fesm2015/vgroup-dialbox.mjs +9 -98
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +9 -98
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/service/extension.service.d.ts +0 -2
- package/lib/service/twilio.service.d.ts +0 -4
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, NgModule } from '@angular/core';
|
|
3
3
|
import swal from 'sweetalert2';
|
|
4
4
|
import { AsYouType } from 'libphonenumber-js';
|
|
5
|
-
import { throwError, BehaviorSubject,
|
|
5
|
+
import { throwError, BehaviorSubject, of, interval, Subscription } from 'rxjs';
|
|
6
6
|
import * as i1 from '@angular/common/http';
|
|
7
7
|
import { HttpHeaders, HttpParams, HttpClientModule } from '@angular/common/http';
|
|
8
8
|
import { catchError, switchMap, map, tap, shareReplay } from 'rxjs/operators';
|
|
@@ -588,38 +588,6 @@ class ExtensionService {
|
|
|
588
588
|
const params = new HttpParams().set('deviceId', deviceId);
|
|
589
589
|
return this.http.get(environment.apiUrl + '/utilities/twilio/incomingcall/token/web', { headers, params });
|
|
590
590
|
}
|
|
591
|
-
// Check if token needs refresh based on expires_at timestamp
|
|
592
|
-
isTokenExpired() {
|
|
593
|
-
const expiresAt = localStorage.getItem('token_expires_at');
|
|
594
|
-
if (!expiresAt) {
|
|
595
|
-
return true; // No expiration info, assume expired
|
|
596
|
-
}
|
|
597
|
-
const expirationTime = parseInt(expiresAt) * 1000; // Convert to milliseconds
|
|
598
|
-
const currentTime = Date.now();
|
|
599
|
-
const bufferTime = 5 * 60 * 1000; // 5 minutes buffer before actual expiration
|
|
600
|
-
return currentTime >= (expirationTime - bufferTime);
|
|
601
|
-
}
|
|
602
|
-
// Refresh token if needed
|
|
603
|
-
refreshTokenIfNeeded(deviceId) {
|
|
604
|
-
if (this.isTokenExpired()) {
|
|
605
|
-
console.log('Token expired or about to expire, refreshing...');
|
|
606
|
-
return this.getIncomingCallToken(deviceId);
|
|
607
|
-
}
|
|
608
|
-
// Return current token data
|
|
609
|
-
const currentToken = localStorage.getItem('in-token');
|
|
610
|
-
const expiresAt = localStorage.getItem('token_expires_at');
|
|
611
|
-
if (currentToken && expiresAt) {
|
|
612
|
-
return new Observable(observer => {
|
|
613
|
-
observer.next({
|
|
614
|
-
token: currentToken,
|
|
615
|
-
expires_at: parseInt(expiresAt)
|
|
616
|
-
});
|
|
617
|
-
observer.complete();
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
// If no current token, get a new one
|
|
621
|
-
return this.getIncomingCallToken(deviceId);
|
|
622
|
-
}
|
|
623
591
|
getOutgoingCallToken(payload) {
|
|
624
592
|
const params = {
|
|
625
593
|
'Content-Type': 'application/json',
|
|
@@ -1429,17 +1397,11 @@ class TwilioService {
|
|
|
1429
1397
|
if (this.tokenInitialized) {
|
|
1430
1398
|
return this.tokenInitialization$ || of(null);
|
|
1431
1399
|
}
|
|
1432
|
-
this.tokenInitialization$ = this.extensionService.
|
|
1400
|
+
this.tokenInitialization$ = this.extensionService.getIncomingCallToken(this.deviceId).pipe(tap((data) => {
|
|
1433
1401
|
this.incomingCallToken = data.token;
|
|
1434
1402
|
localStorage.setItem('in-token', data.token);
|
|
1435
|
-
// Store expiration timestamp for future refresh checks
|
|
1436
|
-
if (data.expires_at) {
|
|
1437
|
-
localStorage.setItem('token_expires_at', data.expires_at.toString());
|
|
1438
|
-
console.log('Token expires at:', new Date(data.expires_at * 1000).toLocaleString());
|
|
1439
|
-
}
|
|
1440
1403
|
this.tokenInitialized = true;
|
|
1441
|
-
console.log('
|
|
1442
|
-
this.startTokenRefreshScheduler();
|
|
1404
|
+
console.log('dfdfdsfdsfds');
|
|
1443
1405
|
this.initializeDevice();
|
|
1444
1406
|
}), catchError(error => {
|
|
1445
1407
|
console.error('Error initializing Twilio token:', error);
|
|
@@ -1450,24 +1412,12 @@ class TwilioService {
|
|
|
1450
1412
|
}
|
|
1451
1413
|
initializeTwilioDevice(deviceId) {
|
|
1452
1414
|
this.deviceId = deviceId;
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
if (data.expires_at) {
|
|
1460
|
-
localStorage.setItem('token_expires_at', data.expires_at.toString());
|
|
1461
|
-
console.log('Token refreshed, expires at:', new Date(data.expires_at * 1000).toLocaleString());
|
|
1462
|
-
}
|
|
1463
|
-
this.tokenInitialized = true;
|
|
1464
|
-
this.startTokenRefreshScheduler();
|
|
1465
|
-
this.initializeDevice();
|
|
1466
|
-
},
|
|
1467
|
-
error: (error) => {
|
|
1468
|
-
console.error('Error refreshing token during device initialization:', error);
|
|
1469
|
-
}
|
|
1470
|
-
});
|
|
1415
|
+
if (this.tokenInitialized && this.incomingCallToken) {
|
|
1416
|
+
this.initializeDevice();
|
|
1417
|
+
}
|
|
1418
|
+
else {
|
|
1419
|
+
this.initializeToken().subscribe();
|
|
1420
|
+
}
|
|
1471
1421
|
}
|
|
1472
1422
|
initializeDevice() {
|
|
1473
1423
|
if (this.device) {
|
|
@@ -1570,45 +1520,6 @@ class TwilioService {
|
|
|
1570
1520
|
};
|
|
1571
1521
|
return this.http.post(environment.apiUrl + '/utilities/phonebook/delete/photo/' + id, payload, httpOptions);
|
|
1572
1522
|
}
|
|
1573
|
-
// Start periodic token refresh scheduler
|
|
1574
|
-
startTokenRefreshScheduler() {
|
|
1575
|
-
// Clear existing interval if any
|
|
1576
|
-
if (this.tokenRefreshInterval) {
|
|
1577
|
-
clearInterval(this.tokenRefreshInterval);
|
|
1578
|
-
}
|
|
1579
|
-
// Check token every 10 minutes
|
|
1580
|
-
this.tokenRefreshInterval = setInterval(() => {
|
|
1581
|
-
if (this.deviceId && this.extensionService.isTokenExpired()) {
|
|
1582
|
-
console.log('Scheduled token refresh triggered');
|
|
1583
|
-
this.extensionService.refreshTokenIfNeeded(this.deviceId).subscribe({
|
|
1584
|
-
next: (data) => {
|
|
1585
|
-
this.incomingCallToken = data.token;
|
|
1586
|
-
localStorage.setItem('in-token', data.token);
|
|
1587
|
-
if (data.expires_at) {
|
|
1588
|
-
localStorage.setItem('token_expires_at', data.expires_at.toString());
|
|
1589
|
-
console.log('Token automatically refreshed, expires at:', new Date(data.expires_at * 1000).toLocaleString());
|
|
1590
|
-
}
|
|
1591
|
-
// Reinitialize device with new token
|
|
1592
|
-
this.initializeDevice();
|
|
1593
|
-
},
|
|
1594
|
-
error: (error) => {
|
|
1595
|
-
console.error('Error during scheduled token refresh:', error);
|
|
1596
|
-
}
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
}, 10 * 60 * 1000); // 10 minutes
|
|
1600
|
-
}
|
|
1601
|
-
// Stop token refresh scheduler
|
|
1602
|
-
stopTokenRefreshScheduler() {
|
|
1603
|
-
if (this.tokenRefreshInterval) {
|
|
1604
|
-
clearInterval(this.tokenRefreshInterval);
|
|
1605
|
-
this.tokenRefreshInterval = null;
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
// Cleanup method to be called when service is destroyed
|
|
1609
|
-
ngOnDestroy() {
|
|
1610
|
-
this.stopTokenRefreshScheduler();
|
|
1611
|
-
}
|
|
1612
1523
|
// toggleCallerIdAlertFn(val: any) {
|
|
1613
1524
|
// let httpOptions = {
|
|
1614
1525
|
// headers: new HttpHeaders({
|