@vgroup/dialbox 0.0.50 → 0.0.51

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.
@@ -3,11 +3,11 @@ import * as i0 from '@angular/core';
3
3
  import { Injectable, EventEmitter, Component, Input, Output, ViewChild, Inject, NgModule } from '@angular/core';
4
4
  import swal from 'sweetalert2';
5
5
  import { AsYouType } from 'libphonenumber-js';
6
- import { throwError, BehaviorSubject, interval, Subscription } from 'rxjs';
6
+ import { throwError, BehaviorSubject, timer, interval, Subscription } from 'rxjs';
7
7
  import * as i1 from '@angular/common/http';
8
8
  import { HttpHeaders, HttpParams, HttpClientModule } from '@angular/common/http';
9
9
  import { Device } from '@twilio/voice-sdk';
10
- import { catchError, switchMap, map } from 'rxjs/operators';
10
+ import { catchError, map, switchMap } from 'rxjs/operators';
11
11
  import * as i3$1 from '@angular/material/dialog';
12
12
  import { MAT_DIALOG_DATA } from '@angular/material/dialog';
13
13
  import * as i5 from '@angular/router';
@@ -155,6 +155,22 @@ class ExtensionService {
155
155
  this.isProfileUpdated = new BehaviorSubject(false);
156
156
  this.callerIdSubject = new BehaviorSubject(null);
157
157
  this.callerId$ = this.callerIdSubject.asObservable();
158
+ // initiateCall(payload: any): Observable<any> {
159
+ // return this.ipAddressService.getIpAddressInfo().pipe(
160
+ // switchMap(ipAddressInfo => {
161
+ // const params = {
162
+ // 'Content-Type': 'application/json',
163
+ // 'Auth-Key': 'Bearer ' + localStorage.getItem('ext_token'),
164
+ // 'ip-address': ipAddressInfo.ip,
165
+ // 'ip-country': ipAddressInfo.address.country
166
+ // };
167
+ // const httpOptions = { headers: new HttpHeaders(params) };
168
+ // return this.http.post<[]>(environment.apiUrl + '/utilities/ext/ur/initiate/call', payload, httpOptions);
169
+ // })
170
+ // );
171
+ // }
172
+ this.maxRetries = 3;
173
+ this.retryDelay = 2000; // 2 seconds
158
174
  }
159
175
  changeMessage(message) {
160
176
  this.messageSource.next(message);
@@ -405,13 +421,34 @@ class ExtensionService {
405
421
  const httpOptions = { headers: new HttpHeaders(params) };
406
422
  return this.http.post(environment.apiUrl + '/utilities/softphone/purchase/number', dtModel, httpOptions);
407
423
  }
408
- fetchCallerId(token) {
409
- const params = {
424
+ fetchCallerId(token, retryCount = 0) {
425
+ if (!token) {
426
+ return throwError(() => new Error('No authentication token provided'));
427
+ }
428
+ const headers = new HttpHeaders({
410
429
  'Content-Type': 'application/json',
411
- 'Auth-Key': "Bearer " + token
430
+ 'Auth-Key': `Bearer ${token}`,
431
+ 'Cache-Control': 'no-cache',
432
+ 'Pragma': 'no-cache'
433
+ });
434
+ const httpOptions = {
435
+ headers: headers,
436
+ withCredentials: true,
437
+ observe: 'response'
412
438
  };
413
- const httpOptions = { headers: new HttpHeaders(params) };
414
- return this.http.get(environment.apiUrl + '/utilities/softphone/fetch/callerid', httpOptions);
439
+ return this.http.get(`${environment.apiUrl}/utilities/softphone/fetch/callerid`, httpOptions).pipe(map(response => {
440
+ if (!response.body) {
441
+ throw new Error('Empty response from server');
442
+ }
443
+ return response.body;
444
+ }), catchError(error => {
445
+ console.error('Error fetching caller ID:', error);
446
+ if (retryCount < this.maxRetries) {
447
+ console.log(`Retrying... (${retryCount + 1}/${this.maxRetries})`);
448
+ return timer(this.retryDelay).pipe(switchMap(() => this.fetchCallerId(token, retryCount + 1)));
449
+ }
450
+ return throwError(() => new Error(`Failed to fetch caller ID after ${this.maxRetries} attempts`));
451
+ }));
415
452
  }
416
453
  updateNumberLabel(token, dtModel) {
417
454
  const params = {
@@ -566,36 +603,66 @@ class ExtensionService {
566
603
  }
567
604
  }));
568
605
  }
569
- // initiateCall(payload: any): Observable<any> {
570
- // return this.ipAddressService.getIpAddressInfo().pipe(
571
- // switchMap(ipAddressInfo => {
572
- // const params = {
573
- // 'Content-Type': 'application/json',
574
- // 'Auth-Key': 'Bearer ' + localStorage.getItem('ext_token'),
575
- // 'ip-address': ipAddressInfo.ip,
576
- // 'ip-country': ipAddressInfo.address.country
577
- // };
578
- // const httpOptions = { headers: new HttpHeaders(params) };
579
- // return this.http.post<[]>(environment.apiUrl + '/utilities/ext/ur/initiate/call', payload, httpOptions);
580
- // })
581
- // );
582
- // }
583
- getIncomingCallToken() {
584
- const params = {
606
+ getIncomingCallToken(retryCount = 0) {
607
+ const token = localStorage.getItem('ext_token');
608
+ if (!token) {
609
+ return throwError(() => new Error('No authentication token found'));
610
+ }
611
+ const params = new HttpHeaders({
585
612
  'Content-Type': 'application/json',
586
- 'Auth-Key': "Bearer " + localStorage.getItem('ext_token')
613
+ 'Auth-Key': `Bearer ${token}`,
614
+ 'Cache-Control': 'no-cache',
615
+ 'Pragma': 'no-cache'
616
+ });
617
+ const httpOptions = {
618
+ headers: params,
619
+ withCredentials: true,
620
+ observe: 'response'
587
621
  };
588
- const httpOptions = { headers: new HttpHeaders(params) };
589
- return this.http.get(environment.apiUrl + '/utilities/twilio/incomingcall/token/web', httpOptions);
622
+ return this.http.get(`${environment.apiUrl}/utilities/twilio/incomingcall/token/web`, httpOptions).pipe(map(response => {
623
+ if (!response.body) {
624
+ throw new Error('Empty response from server');
625
+ }
626
+ return response.body;
627
+ }), catchError(error => {
628
+ console.error('Error fetching Twilio token:', error);
629
+ if (retryCount < this.maxRetries) {
630
+ console.log(`Retrying... (${retryCount + 1}/${this.maxRetries})`);
631
+ return timer(this.retryDelay).pipe(switchMap(() => this.getIncomingCallToken(retryCount + 1)));
632
+ }
633
+ return throwError(() => new Error(`Failed to get Twilio token after ${this.maxRetries} attempts`));
634
+ }));
590
635
  }
591
- getOutgoingCallToken(payload) {
592
- const params = {
636
+ getOutgoingCallToken(payload, retryCount = 0) {
637
+ const token = localStorage.getItem('ext_token');
638
+ if (!token) {
639
+ return throwError(() => new Error('No authentication token found'));
640
+ }
641
+ const headers = new HttpHeaders({
593
642
  'Content-Type': 'application/json',
594
- 'Auth-Key': "Bearer " + localStorage.getItem('ext_token'),
595
- 'c2c-request': window.location.hostname
643
+ 'Auth-Key': `Bearer ${token}`,
644
+ 'c2c-request': window.location.hostname,
645
+ 'Cache-Control': 'no-cache',
646
+ 'Pragma': 'no-cache'
647
+ });
648
+ const httpOptions = {
649
+ headers: headers,
650
+ withCredentials: true,
651
+ observe: 'response'
596
652
  };
597
- const httpOptions = { headers: new HttpHeaders(params) };
598
- return this.http.post(environment.apiUrl + '/utilities/ext/ur/generate/token', payload, httpOptions);
653
+ return this.http.post(`${environment.apiUrl}/utilities/ext/ur/generate/token`, payload, httpOptions).pipe(map(response => {
654
+ if (!response.body) {
655
+ throw new Error('Empty response from server');
656
+ }
657
+ return response.body;
658
+ }), catchError(error => {
659
+ console.error('Error fetching outgoing call token:', error);
660
+ if (retryCount < this.maxRetries) {
661
+ console.log(`Retrying... (${retryCount + 1}/${this.maxRetries})`);
662
+ return timer(this.retryDelay).pipe(switchMap(() => this.getOutgoingCallToken(payload, retryCount + 1)));
663
+ }
664
+ return throwError(() => new Error(`Failed to get outgoing call token after ${this.maxRetries} attempts`));
665
+ }));
599
666
  }
600
667
  getCallRecording(callSid) {
601
668
  const headers = new HttpHeaders({