@vgroup/dialbox 0.0.71 → 0.0.72
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 +13 -2
- package/esm2020/lib/service/twilio.service.mjs +41 -4
- package/fesm2015/vgroup-dialbox.mjs +52 -4
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +52 -4
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/service/extension.service.d.ts +5 -1
- package/lib/service/twilio.service.d.ts +3 -2
- package/package.json +1 -1
|
@@ -129,6 +129,15 @@ class ExtensionService {
|
|
|
129
129
|
recordCall: this.recordCall
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
get token() {
|
|
133
|
+
return this._token;
|
|
134
|
+
}
|
|
135
|
+
set token(value) {
|
|
136
|
+
if (this._token !== value) {
|
|
137
|
+
this._token = value;
|
|
138
|
+
this.tokenChangeSubject.next(value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
132
141
|
setCallerId(callerId) {
|
|
133
142
|
this.callerIdSubject.next(callerId);
|
|
134
143
|
}
|
|
@@ -149,7 +158,9 @@ class ExtensionService {
|
|
|
149
158
|
this.draftSmsSource = new BehaviorSubject('');
|
|
150
159
|
this.draftMessage = this.draftSmsSource.asObservable();
|
|
151
160
|
this.isInputFocus$ = new BehaviorSubject(false);
|
|
152
|
-
this.
|
|
161
|
+
this._token = localStorage.getItem('ext_token') || '';
|
|
162
|
+
this.tokenChangeSubject = new BehaviorSubject(this._token);
|
|
163
|
+
this.tokenChange$ = this.tokenChangeSubject.asObservable();
|
|
153
164
|
this.isNewContactAdded = new BehaviorSubject(false);
|
|
154
165
|
this.isProfileUpdated = new BehaviorSubject(false);
|
|
155
166
|
this.callerIdSubject = new BehaviorSubject(null);
|
|
@@ -1366,10 +1377,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
1366
1377
|
}], ctorParameters: function () { return [{ type: TwilioService }]; } });
|
|
1367
1378
|
|
|
1368
1379
|
class TwilioService {
|
|
1369
|
-
constructor(http, extensionService,
|
|
1380
|
+
constructor(http, extensionService, notificationService) {
|
|
1370
1381
|
this.http = http;
|
|
1371
1382
|
this.extensionService = extensionService;
|
|
1372
|
-
this.
|
|
1383
|
+
this.notificationService = notificationService;
|
|
1373
1384
|
this.openInProgressDialpad = new BehaviorSubject(false);
|
|
1374
1385
|
this.currentCall = new BehaviorSubject(null);
|
|
1375
1386
|
this.currentCallState = new BehaviorSubject('none'); //in-progress, out-progress, none
|
|
@@ -1387,11 +1398,34 @@ class TwilioService {
|
|
|
1387
1398
|
this.isAvailableNumber = new BehaviorSubject(false);
|
|
1388
1399
|
this.callerIdList = new BehaviorSubject([]);
|
|
1389
1400
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
1401
|
+
this.isInitialized = false;
|
|
1402
|
+
// Initialize with current token if available
|
|
1390
1403
|
this.initializeTwilioDevice();
|
|
1404
|
+
// Listen for token changes
|
|
1405
|
+
this.extensionService.tokenChange$.subscribe(token => {
|
|
1406
|
+
if (token && (!this.token || token !== this.token)) {
|
|
1407
|
+
this.token = token;
|
|
1408
|
+
this.initializeTwilioDevice();
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1391
1411
|
}
|
|
1392
1412
|
initializeTwilioDevice() {
|
|
1413
|
+
// Don't initialize if already initialized with the same token
|
|
1414
|
+
if (this.device && this.token === this.extensionService.token) {
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
// Clean up existing device if any
|
|
1418
|
+
if (this.device) {
|
|
1419
|
+
this.device.destroy();
|
|
1420
|
+
this.device = null;
|
|
1421
|
+
}
|
|
1422
|
+
this.token = this.extensionService.token;
|
|
1393
1423
|
if (this.token) {
|
|
1394
1424
|
this.extensionService.getIncomingCallToken().subscribe((data) => {
|
|
1425
|
+
if (!data || !data.token) {
|
|
1426
|
+
console.error('No token received from getIncomingCallToken');
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1395
1429
|
this.incomingCallToken = data.token;
|
|
1396
1430
|
localStorage.setItem('in-token', data.token);
|
|
1397
1431
|
this.device = new Device(this.incomingCallToken, {
|
|
@@ -1400,10 +1434,24 @@ class TwilioService {
|
|
|
1400
1434
|
});
|
|
1401
1435
|
this.device.register();
|
|
1402
1436
|
this.device.on('incoming', (call) => {
|
|
1437
|
+
console.log('Incoming call received:', call);
|
|
1403
1438
|
this.currentCall.next(call);
|
|
1404
1439
|
this.callType.next('INCOMING');
|
|
1405
1440
|
this.currentCallState.next('incoming');
|
|
1406
|
-
this.
|
|
1441
|
+
this.notificationService.showNotification(call);
|
|
1442
|
+
// Auto-answer if needed (optional)
|
|
1443
|
+
// call.accept();
|
|
1444
|
+
call.on('accept', () => {
|
|
1445
|
+
const callSid = call.parameters['CallSid'];
|
|
1446
|
+
console.log('Call accepted:', callSid);
|
|
1447
|
+
this.currentCallState.next('in-progress');
|
|
1448
|
+
});
|
|
1449
|
+
call.on('disconnect', () => {
|
|
1450
|
+
const callSid = call.parameters['CallSid'];
|
|
1451
|
+
console.log('Call disconnected:', callSid);
|
|
1452
|
+
this.currentCall.next(null);
|
|
1453
|
+
this.currentCallState.next('disconnected');
|
|
1454
|
+
});
|
|
1407
1455
|
});
|
|
1408
1456
|
this.device.on('error', (error) => {
|
|
1409
1457
|
console.error('Twilio Device Error:', error);
|