@vgroup/dialbox 0.0.64 → 0.0.65

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, PLATFORM_ID, APP_INITIALIZER, Injector, NgModule } from '@angular/core';
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
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 { isPlatformBrowser, CommonModule } from '@angular/common';
15
+ import { 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,22 +1301,13 @@ 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
- });
1310
1304
  }
1311
1305
  showNotification(callData) {
1312
- if (!callData)
1313
- return;
1306
+ this.twilioAuthId = callData.customParameters.get('twilioAuthId');
1314
1307
  this.twilioCallData = callData;
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');
1308
+ const incomingNumber = callData.parameters.From;
1309
+ const callerName = callData.customParameters.get('name');
1310
+ const callerImage = callData.customParameters.get('image');
1320
1311
  if (('serviceWorker' in navigator)) {
1321
1312
  navigator.serviceWorker.ready.then((registration) => {
1322
1313
  const options = {
@@ -1401,82 +1392,26 @@ class TwilioService {
1401
1392
  initializeTwilioDevice() {
1402
1393
  if (this.token) {
1403
1394
  this.extensionService.getIncomingCallToken().subscribe((data) => {
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);
1395
+ this.incomingCallToken = data.token;
1396
+ localStorage.setItem('in-token', data.token);
1397
+ this.device = new Device(this.incomingCallToken, {
1398
+ allowIncomingWhileBusy: true,
1399
+ // Add any other necessary options
1400
+ });
1401
+ this.device.register();
1402
+ this.device.on('incoming', (call) => {
1403
+ this.currentCall.next(call);
1404
+ this.callType.next('INCOMING');
1405
+ this.currentCallState.next('incoming');
1406
+ this.notificationSerivce.showNotification(call);
1407
+ });
1408
+ this.device.on('error', (error) => {
1409
+ console.error('Twilio Device Error:', error);
1410
+ // Add error handling and reconnection logic
1411
+ });
1426
1412
  });
1427
1413
  }
1428
1414
  }
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
- }
1480
1415
  // onIncomingCall(){
1481
1416
  // this.device.on('incoming', (call:any) => {
1482
1417
  // console.log(call);
@@ -3241,88 +3176,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
3241
3176
  args: [MAT_DIALOG_DATA]
3242
3177
  }] }]; } });
3243
3178
 
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
-
3326
3179
  class DialboxModule {
3327
3180
  }
3328
3181
  DialboxModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DialboxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
@@ -3339,19 +3192,7 @@ DialboxModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version:
3339
3192
  IncomingCallComponent,
3340
3193
  CallProgressComponent,
3341
3194
  CallerIdDialogComponent] });
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,
3195
+ DialboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DialboxModule, imports: [CommonModule,
3355
3196
  FormsModule,
3356
3197
  ReactiveFormsModule,
3357
3198
  HttpClientModule,
@@ -3380,19 +3221,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
3380
3221
  IncomingCallComponent,
3381
3222
  CallProgressComponent,
3382
3223
  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
- }
3396
3224
  ]
3397
3225
  }]
3398
3226
  }] });