@vgroup/dialbox 0.2.29 → 0.2.31

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,7 +3,7 @@ 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, forkJoin, of, interval, Subscription } from 'rxjs';
6
+ import { throwError, BehaviorSubject, of, 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 { catchError, switchMap, map, tap, shareReplay } from 'rxjs/operators';
@@ -563,54 +563,74 @@ class ExtensionService {
563
563
  // })
564
564
  // );
565
565
  // }
566
- /**
567
- * Initiates a normal & a conference call in parallel.
568
- * The method performs three steps:
569
- * 1. Load black-listed countries & current IP info in parallel.
570
- * 2. Abort early if the caller is from a blocked country.
571
- * 3. Fire both call-initiation APIs together and return both responses.
572
- *
573
- * It guarantees that:
574
- * • Both HTTP requests are always attempted.
575
- * • Failure of one request does not cancel the other – the error is
576
- * returned alongside the success response so that the component can
577
- * decide what to do.
578
- */
579
566
  initiateCall(payload) {
580
- return forkJoin({
581
- blocked: this.fetchBlockedCountries(),
582
- ipInfo: this.ipAddressService.getIpAddressInfo()
583
- }).pipe(switchMap(({ blocked, ipInfo }) => {
584
- // Reject early if user’s country is in the blocked list.
585
- if (blocked.includes(ipInfo.address.countryCode)) {
586
- return throwError(() => ({ message: ['User from blocked country'] }));
587
- }
588
- // Prepare headers & body for both requests.
589
- const headers = new HttpHeaders({
590
- 'Content-Type': 'application/json',
591
- 'Auth-Key': 'Bearer ' + localStorage.getItem('ext_token'),
592
- 'ip-address': ipInfo.ip,
593
- 'ip-country': ipInfo.address.country
594
- });
595
- const body = Object.assign(Object.assign({}, payload), { proxy: ipInfo.proxy.toString() });
596
- const options = { headers };
597
- const api1$ = this.http
598
- .post(`${environment.apiUrl}/utilities/ext/ur/initiate/call`, body, options)
599
- .pipe(catchError(error => of({ error })));
600
- const api2$ = this.http
601
- .post(`${environment.apiUrl}/ur/initiate/conference/call`, body, options)
602
- .pipe(catchError(error => of({ error })));
603
- // Execute both requests and return their individual outcomes.
604
- return forkJoin([api1$, api2$]);
567
+ return this.fetchBlockedCountries().pipe(switchMap(blockedCountries => {
568
+ return this.ipAddressService.getIpAddressInfo().pipe(switchMap(ipAddressInfo => {
569
+ const params = {
570
+ 'Content-Type': 'application/json',
571
+ 'Auth-Key': 'Bearer ' + localStorage.getItem('ext_token'),
572
+ 'ip-address': ipAddressInfo.ip,
573
+ 'ip-country': ipAddressInfo.address.country,
574
+ };
575
+ payload = Object.assign(Object.assign({}, payload), { proxy: ipAddressInfo.proxy.toString() });
576
+ const httpOptions = { headers: new HttpHeaders(params) };
577
+ return this.http.post(environment.apiUrl + '/utilities/ext/ur/initiate/conference/call', payload, httpOptions).pipe(catchError(error => {
578
+ return throwError(error);
579
+ }));
580
+ }), catchError(error => {
581
+ // Catch error from getIpAddressInfo
582
+ return throwError(error);
583
+ }));
605
584
  }));
606
585
  }
586
+ // initiateCall(payload: any): Observable<any> {
587
+ // return this.fetchBlockedCountries().pipe(
588
+ // switchMap(blockedCountries => {
589
+ // return this.ipAddressService.getIpAddressInfo().pipe(
590
+ // switchMap(ipAddressInfo => {
591
+ // const params = {
592
+ // 'Content-Type': 'application/json',
593
+ // 'Auth-Key': 'Bearer ' + localStorage.getItem('ext_token'),
594
+ // 'ip-address': ipAddressInfo.ip,
595
+ // 'ip-country': ipAddressInfo.address.country,
596
+ // };
597
+ // payload = { ...payload, proxy: ipAddressInfo.proxy.toString() };
598
+ // const httpOptions = { headers: new HttpHeaders(params) };
599
+ // const api1$ = this.http.post(
600
+ // `${environment.apiUrl}/utilities/ext/ur/initiate/call`,
601
+ // payload,
602
+ // httpOptions
603
+ // );
604
+ // const api2$ = this.http.post(
605
+ // `${environment.apiUrl}/utilities/ext/ur/initiate/conference/call`,
606
+ // payload,
607
+ // httpOptions
608
+ // );
609
+ // return forkJoin([api1$, api2$]).pipe(
610
+ // catchError(error => throwError(() => error))
611
+ // );
612
+ // }),
613
+ // catchError(error => throwError(() => error))
614
+ // );
615
+ // })
616
+ // );
617
+ // }
618
+ // getConferenceCallToken(payload: any) {
619
+ // const params = {
620
+ // "conferenceId": payload.conferenceId,
621
+ // "userId": payload.userId
622
+ // }
623
+ // const httpOptions = { headers: new HttpHeaders(params) };
624
+ // return this.http.post<[]>(environment.apiUrl + '/utilities/ext/ur/generate/conference/token', params, httpOptions);
625
+ // }
607
626
  getConferenceCallToken(payload) {
608
627
  const params = {
609
- "conferenceId": payload.conferenceId,
610
- "userId": payload.userId
628
+ 'Content-Type': 'application/json',
629
+ 'Auth-Key': "Bearer " + localStorage.getItem('ext_token'),
630
+ 'c2c-request': window.location.hostname
611
631
  };
612
632
  const httpOptions = { headers: new HttpHeaders(params) };
613
- return this.http.post(environment.apiUrl + '/ur/generate/conference/token', params, httpOptions);
633
+ return this.http.post(environment.apiUrl + '/utilities/ext/ur/generate/token', payload, httpOptions);
614
634
  }
615
635
  addFirstParticipant(payload) {
616
636
  const params = {
@@ -2124,17 +2144,17 @@ class CallProgressComponent {
2124
2144
  scope: 'local',
2125
2145
  fromNumber: callData.from
2126
2146
  };
2127
- const [response] = yield this.initiateCall(payload);
2128
- if (response && response.status === 200) {
2147
+ const response = yield this.initiateCall(payload);
2148
+ if (response.status == 200) {
2129
2149
  const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2130
2150
  this.getUserInformation(callAuthId);
2131
2151
  this.recordCall = recordCall; // Store the recordCall value
2132
- const tokenData = yield this.getOutgoingCallToken(callAuthId);
2152
+ const tokenData = yield this.getConferenceCallToken(callAuthId);
2133
2153
  yield this.connectToDevice(tokenData.token, callData);
2134
2154
  // Poll the status for 30-45 seconds
2135
2155
  this.pollCallStatus(callAuthId);
2136
2156
  }
2137
- else if (response && response.status === 201) {
2157
+ else if (response.status == 201) {
2138
2158
  swal("Error", response.message.join("<br/>"), "error");
2139
2159
  console.log('test2');
2140
2160
  this.endCall();
@@ -2161,9 +2181,9 @@ class CallProgressComponent {
2161
2181
  };
2162
2182
  });
2163
2183
  }
2164
- getOutgoingCallToken(callAuthId) {
2184
+ getConferenceCallToken(callAuthId) {
2165
2185
  return __awaiter(this, void 0, void 0, function* () {
2166
- return yield this.extensionService.getOutgoingCallToken({ authId: callAuthId }).toPromise();
2186
+ return yield this.extensionService.getConferenceCallToken({ authId: callAuthId }).toPromise();
2167
2187
  });
2168
2188
  }
2169
2189
  connectToDevice(token, callData) {
@@ -2387,12 +2407,12 @@ class CallProgressComponent {
2387
2407
  scope: 'local',
2388
2408
  fromNumber: this.callData.from
2389
2409
  };
2390
- const [response] = yield this.initiateCall(payload);
2391
- if (response && response.status === 200) {
2410
+ const response = yield this.initiateCall(payload);
2411
+ if (response.status == 200) {
2392
2412
  const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2393
2413
  this.getUserInformation(callAuthId);
2394
2414
  this.recordCall = recordCall;
2395
- const tokenData = yield this.getOutgoingCallToken(callAuthId);
2415
+ const tokenData = yield this.getConferenceCallToken(callAuthId);
2396
2416
  // Connect to new call
2397
2417
  const options = {
2398
2418
  codecPreferences: ['opus', 'pcmu'],
@@ -2434,7 +2454,7 @@ class CallProgressComponent {
2434
2454
  console.log('New call initiated to:', phoneNumber);
2435
2455
  this.cdr.detectChanges();
2436
2456
  }
2437
- else if (response && response.status === 201) {
2457
+ else if (response.status == 201) {
2438
2458
  swal("Error", response.message.join("<br/>"), "error");
2439
2459
  // Restore held call if new call fails
2440
2460
  if (this.heldCall) {