@vgroup/dialbox 0.0.62 → 0.0.64
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/dialbox.module.mjs +29 -3
- package/esm2020/lib/service/Notification.service.mjs +14 -5
- package/esm2020/lib/service/app-initializer.service.mjs +88 -0
- package/esm2020/lib/service/twilio.service.mjs +74 -18
- package/fesm2015/vgroup-dialbox.mjs +205 -24
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +196 -24
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/service/app-initializer.service.d.ts +19 -0
- package/lib/service/twilio.service.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, NgModule } from '@angular/core';
|
|
2
|
+
import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, PLATFORM_ID, APP_INITIALIZER, Injector, NgModule } from '@angular/core';
|
|
3
3
|
import swal from 'sweetalert2';
|
|
4
4
|
import { AsYouType } from 'libphonenumber-js';
|
|
5
5
|
import { throwError, BehaviorSubject, interval, Subscription } from 'rxjs';
|
|
@@ -12,7 +12,7 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
12
12
|
import * as i5 from '@angular/router';
|
|
13
13
|
import { RouterLink, RouterModule } from '@angular/router';
|
|
14
14
|
import * as i4 from '@angular/common';
|
|
15
|
-
import { CommonModule } from '@angular/common';
|
|
15
|
+
import { isPlatformBrowser, CommonModule } from '@angular/common';
|
|
16
16
|
import * as i3 from '@angular/forms';
|
|
17
17
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
18
18
|
import { BrowserModule } from '@angular/platform-browser';
|
|
@@ -1301,13 +1301,22 @@ class NotificationService {
|
|
|
1301
1301
|
if ('serviceWorker' in navigator) {
|
|
1302
1302
|
navigator.serviceWorker.addEventListener('message', this.handleServiceWorkerMessage.bind(this));
|
|
1303
1303
|
}
|
|
1304
|
+
// Listen for incoming calls from Twilio service
|
|
1305
|
+
this.twilioService.currentCall.subscribe((call) => {
|
|
1306
|
+
if (call) {
|
|
1307
|
+
this.showNotification(call);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1304
1310
|
}
|
|
1305
1311
|
showNotification(callData) {
|
|
1306
|
-
|
|
1312
|
+
if (!callData)
|
|
1313
|
+
return;
|
|
1307
1314
|
this.twilioCallData = callData;
|
|
1308
|
-
const incomingNumber = callData.parameters
|
|
1309
|
-
const
|
|
1310
|
-
const
|
|
1315
|
+
const incomingNumber = callData.parameters?.From;
|
|
1316
|
+
const customParams = callData.customParameters || new Map();
|
|
1317
|
+
const callerName = customParams.get('name') || incomingNumber;
|
|
1318
|
+
const callerImage = customParams.get('image') || '';
|
|
1319
|
+
this.twilioAuthId = customParams.get('twilioAuthId');
|
|
1311
1320
|
if (('serviceWorker' in navigator)) {
|
|
1312
1321
|
navigator.serviceWorker.ready.then((registration) => {
|
|
1313
1322
|
const options = {
|
|
@@ -1392,26 +1401,82 @@ class TwilioService {
|
|
|
1392
1401
|
initializeTwilioDevice() {
|
|
1393
1402
|
if (this.token) {
|
|
1394
1403
|
this.extensionService.getIncomingCallToken().subscribe((data) => {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1404
|
+
try {
|
|
1405
|
+
this.incomingCallToken = data.token;
|
|
1406
|
+
localStorage.setItem('in-token', data.token);
|
|
1407
|
+
// Destroy existing device if any
|
|
1408
|
+
if (this.device) {
|
|
1409
|
+
this.device.destroy();
|
|
1410
|
+
}
|
|
1411
|
+
this.device = new Device(this.incomingCallToken, {
|
|
1412
|
+
allowIncomingWhileBusy: true,
|
|
1413
|
+
closeProtection: true
|
|
1414
|
+
});
|
|
1415
|
+
// Register the device
|
|
1416
|
+
this.device.register();
|
|
1417
|
+
// Set up device event listeners
|
|
1418
|
+
this.setupDeviceListeners();
|
|
1419
|
+
console.log('Twilio device initialized and registered');
|
|
1420
|
+
}
|
|
1421
|
+
catch (error) {
|
|
1422
|
+
console.error('Error initializing Twilio device:', error);
|
|
1423
|
+
}
|
|
1424
|
+
}, (error) => {
|
|
1425
|
+
console.error('Error getting Twilio token:', error);
|
|
1412
1426
|
});
|
|
1413
1427
|
}
|
|
1414
1428
|
}
|
|
1429
|
+
setupDeviceListeners() {
|
|
1430
|
+
if (!this.device)
|
|
1431
|
+
return;
|
|
1432
|
+
// Incoming call handler
|
|
1433
|
+
this.device.on('incoming', (call) => {
|
|
1434
|
+
console.log('Incoming call from:', call.parameters['From']);
|
|
1435
|
+
// Update call state
|
|
1436
|
+
this.currentCall.next(call);
|
|
1437
|
+
this.callType.next('INCOMING');
|
|
1438
|
+
this.currentCallState.next('incoming');
|
|
1439
|
+
// Show notification and open dialpad
|
|
1440
|
+
this.notificationSerivce.showNotification(call);
|
|
1441
|
+
this.openInProgressDialpad.next(true);
|
|
1442
|
+
// Set up call event listeners
|
|
1443
|
+
call.on('accept', () => {
|
|
1444
|
+
console.log('Call accepted');
|
|
1445
|
+
this.currentCallState.next('in-progress');
|
|
1446
|
+
this.isIncomingCallPicked.next(true);
|
|
1447
|
+
});
|
|
1448
|
+
call.on('disconnect', () => {
|
|
1449
|
+
console.log('Call disconnected');
|
|
1450
|
+
this.currentCallState.next('none');
|
|
1451
|
+
this.currentCall.next(null);
|
|
1452
|
+
this.isIncomingCallPicked.next(false);
|
|
1453
|
+
this.openInProgressDialpad.next(false);
|
|
1454
|
+
});
|
|
1455
|
+
call.on('cancel', () => {
|
|
1456
|
+
console.log('Call cancelled');
|
|
1457
|
+
this.currentCallState.next('none');
|
|
1458
|
+
this.currentCall.next(null);
|
|
1459
|
+
this.isIncomingCallPicked.next(false);
|
|
1460
|
+
this.openInProgressDialpad.next(false);
|
|
1461
|
+
});
|
|
1462
|
+
});
|
|
1463
|
+
// Error handling
|
|
1464
|
+
this.device.on('error', (error) => {
|
|
1465
|
+
console.error('Twilio Device Error:', error);
|
|
1466
|
+
// Attempt to reinitialize on error
|
|
1467
|
+
if (error.code === 31201) { // Invalid token error
|
|
1468
|
+
console.log('Attempting to refresh Twilio token...');
|
|
1469
|
+
this.initializeTwilioDevice();
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
// Device ready
|
|
1473
|
+
this.device.on('registered', () => {
|
|
1474
|
+
console.log('Twilio device registered and ready');
|
|
1475
|
+
});
|
|
1476
|
+
this.device.on('unregistered', () => {
|
|
1477
|
+
console.log('Twilio device unregistered');
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1415
1480
|
// onIncomingCall(){
|
|
1416
1481
|
// this.device.on('incoming', (call:any) => {
|
|
1417
1482
|
// console.log(call);
|
|
@@ -3176,6 +3241,88 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3176
3241
|
args: [MAT_DIALOG_DATA]
|
|
3177
3242
|
}] }]; } });
|
|
3178
3243
|
|
|
3244
|
+
class AppInitializerService {
|
|
3245
|
+
constructor(injector, extensionService, router, platformId) {
|
|
3246
|
+
this.injector = injector;
|
|
3247
|
+
this.extensionService = extensionService;
|
|
3248
|
+
this.router = router;
|
|
3249
|
+
this.platformId = platformId;
|
|
3250
|
+
}
|
|
3251
|
+
getTwilioService() {
|
|
3252
|
+
if (!this.twilioService) {
|
|
3253
|
+
this.twilioService = this.injector.get(TwilioService);
|
|
3254
|
+
}
|
|
3255
|
+
return this.twilioService;
|
|
3256
|
+
}
|
|
3257
|
+
initializeApp() {
|
|
3258
|
+
return new Promise((resolve) => {
|
|
3259
|
+
if (isPlatformBrowser(this.platformId)) {
|
|
3260
|
+
this.initializeServices().then(() => {
|
|
3261
|
+
resolve();
|
|
3262
|
+
});
|
|
3263
|
+
}
|
|
3264
|
+
else {
|
|
3265
|
+
resolve();
|
|
3266
|
+
}
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
async initializeServices() {
|
|
3270
|
+
try {
|
|
3271
|
+
// Initialize Twilio device
|
|
3272
|
+
await this.initializeTwilio();
|
|
3273
|
+
// Fetch initial data
|
|
3274
|
+
await this.fetchInitialData();
|
|
3275
|
+
console.log('App initialization complete');
|
|
3276
|
+
}
|
|
3277
|
+
catch (error) {
|
|
3278
|
+
console.error('Error during app initialization:', error);
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
async initializeTwilio() {
|
|
3282
|
+
const token = localStorage.getItem('ext_token');
|
|
3283
|
+
if (token) {
|
|
3284
|
+
try {
|
|
3285
|
+
const twilioService = this.getTwilioService();
|
|
3286
|
+
await twilioService.initializeTwilioDevice();
|
|
3287
|
+
}
|
|
3288
|
+
catch (error) {
|
|
3289
|
+
console.error('Error initializing Twilio:', error);
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
async fetchInitialData() {
|
|
3294
|
+
const token = localStorage.getItem('ext_token');
|
|
3295
|
+
if (token) {
|
|
3296
|
+
try {
|
|
3297
|
+
// Fetch caller ID
|
|
3298
|
+
const response = await this.extensionService.fetchCallerId(token).toPromise();
|
|
3299
|
+
if (response && typeof response === 'object' && 'status' in response) {
|
|
3300
|
+
const callerIdRes = response;
|
|
3301
|
+
if (callerIdRes.status === 200) {
|
|
3302
|
+
const callerId = callerIdRes.callerid || 'Not set';
|
|
3303
|
+
localStorage.setItem('callerID', callerId);
|
|
3304
|
+
this.extensionService.changeMessage(callerId);
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
catch (error) {
|
|
3309
|
+
console.error('Error fetching initial data:', error);
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
AppInitializerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AppInitializerService, deps: [{ token: i0.Injector }, { token: ExtensionService }, { token: i5.Router }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3315
|
+
AppInitializerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AppInitializerService, providedIn: 'root' });
|
|
3316
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: AppInitializerService, decorators: [{
|
|
3317
|
+
type: Injectable,
|
|
3318
|
+
args: [{
|
|
3319
|
+
providedIn: 'root'
|
|
3320
|
+
}]
|
|
3321
|
+
}], ctorParameters: function () { return [{ type: i0.Injector }, { type: ExtensionService }, { type: i5.Router }, { type: Object, decorators: [{
|
|
3322
|
+
type: Inject,
|
|
3323
|
+
args: [PLATFORM_ID]
|
|
3324
|
+
}] }]; } });
|
|
3325
|
+
|
|
3179
3326
|
class DialboxModule {
|
|
3180
3327
|
}
|
|
3181
3328
|
DialboxModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DialboxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
@@ -3192,7 +3339,19 @@ DialboxModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version:
|
|
|
3192
3339
|
IncomingCallComponent,
|
|
3193
3340
|
CallProgressComponent,
|
|
3194
3341
|
CallerIdDialogComponent] });
|
|
3195
|
-
DialboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DialboxModule,
|
|
3342
|
+
DialboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DialboxModule, providers: [
|
|
3343
|
+
{
|
|
3344
|
+
provide: APP_INITIALIZER,
|
|
3345
|
+
useFactory: (injector) => {
|
|
3346
|
+
return () => {
|
|
3347
|
+
const appInitializer = injector.get(AppInitializerService);
|
|
3348
|
+
return appInitializer.initializeApp();
|
|
3349
|
+
};
|
|
3350
|
+
},
|
|
3351
|
+
deps: [Injector],
|
|
3352
|
+
multi: true
|
|
3353
|
+
}
|
|
3354
|
+
], imports: [CommonModule,
|
|
3196
3355
|
FormsModule,
|
|
3197
3356
|
ReactiveFormsModule,
|
|
3198
3357
|
HttpClientModule,
|
|
@@ -3221,6 +3380,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3221
3380
|
IncomingCallComponent,
|
|
3222
3381
|
CallProgressComponent,
|
|
3223
3382
|
CallerIdDialogComponent,
|
|
3383
|
+
],
|
|
3384
|
+
providers: [
|
|
3385
|
+
{
|
|
3386
|
+
provide: APP_INITIALIZER,
|
|
3387
|
+
useFactory: (injector) => {
|
|
3388
|
+
return () => {
|
|
3389
|
+
const appInitializer = injector.get(AppInitializerService);
|
|
3390
|
+
return appInitializer.initializeApp();
|
|
3391
|
+
};
|
|
3392
|
+
},
|
|
3393
|
+
deps: [Injector],
|
|
3394
|
+
multi: true
|
|
3395
|
+
}
|
|
3224
3396
|
]
|
|
3225
3397
|
}]
|
|
3226
3398
|
}] });
|