@vgroup/dialbox 0.0.55 → 0.0.57

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.
@@ -1317,18 +1317,30 @@ class TwilioService {
1317
1317
  this.triggerSMSReload = new BehaviorSubject(false);
1318
1318
  this.isInitialized = false;
1319
1319
  this.initializationInProgress = false;
1320
- // Initialize when token is available
1321
1320
  this.initializeTwilioDevice();
1322
1321
  }
1323
1322
  initializeTwilioDevice() {
1324
- if (this.initializationInProgress || !this.token)
1323
+ if (this.initializationInProgress || this.isInitialized)
1325
1324
  return;
1326
1325
  this.initializationInProgress = true;
1327
1326
  this.extensionService.getIncomingCallToken().subscribe({
1328
1327
  next: (data) => {
1329
1328
  if (data?.token) {
1330
- this.setupDevice(data.token);
1329
+ this.incomingCallToken = data.token;
1330
+ localStorage.setItem('in-token', data.token);
1331
+ // Clean up existing device if any
1332
+ if (this.device) {
1333
+ this.device.destroy();
1334
+ }
1335
+ // Initialize new device
1336
+ this.device = new Device(data.token, {
1337
+ allowIncomingWhileBusy: true,
1338
+ closeProtection: true
1339
+ });
1340
+ this.setupDeviceEventListeners();
1341
+ this.device.register();
1331
1342
  this.isInitialized = true;
1343
+ this.initializationInProgress = false;
1332
1344
  }
1333
1345
  },
1334
1346
  error: (error) => {
@@ -1339,21 +1351,13 @@ class TwilioService {
1339
1351
  }
1340
1352
  });
1341
1353
  }
1342
- setupDevice(token) {
1343
- // Clean up existing device if any
1344
- if (this.device) {
1345
- this.device.destroy();
1346
- }
1347
- this.incomingCallToken = token;
1348
- localStorage.setItem('in-token', token);
1349
- this.device = new Device(token, {
1350
- allowIncomingWhileBusy: true,
1351
- closeProtection: true
1352
- });
1353
- // Set up event listeners
1354
+ setupDeviceEventListeners() {
1355
+ if (!this.device)
1356
+ return;
1357
+ // Clean up existing listeners
1358
+ this.device.removeAllListeners();
1354
1359
  this.device.on('registered', () => {
1355
1360
  console.log('Twilio Device registered successfully');
1356
- this.initializationInProgress = false;
1357
1361
  });
1358
1362
  this.device.on('incoming', (call) => {
1359
1363
  console.log('Incoming call received');
@@ -1364,7 +1368,6 @@ class TwilioService {
1364
1368
  this.device.on('error', (error) => {
1365
1369
  console.error('Twilio Device Error:', error);
1366
1370
  this.isInitialized = false;
1367
- this.initializationInProgress = false;
1368
1371
  // Attempt to reinitialize after error
1369
1372
  setTimeout(() => this.initializeTwilioDevice(), 5000);
1370
1373
  });
@@ -1374,11 +1377,15 @@ class TwilioService {
1374
1377
  // Attempt to re-register
1375
1378
  this.initializeTwilioDevice();
1376
1379
  });
1377
- this.device.register();
1378
1380
  }
1379
- // //call.accept();
1380
- // });
1381
- // }
1381
+ onIncomingCall() {
1382
+ if (this.device) {
1383
+ this.device.on('incoming', (call) => {
1384
+ console.log('Incoming call:', call);
1385
+ // call.accept();
1386
+ });
1387
+ }
1388
+ }
1382
1389
  saveContact(payload) {
1383
1390
  const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
1384
1391
  return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
@@ -2163,29 +2170,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
2163
2170
  }] } });
2164
2171
 
2165
2172
  class DialboxComponent {
2166
- set isDialpadHidden(value) {
2167
- this._isDialpadHidden = value;
2168
- if (!value && !this.isInitialized) {
2169
- this.initializeTwilio();
2170
- }
2171
- }
2172
- get isDialpadHidden() {
2173
- return this._isDialpadHidden;
2174
- }
2175
- initializeTwilio() {
2176
- if (this.isInitialized || !this.token)
2177
- return;
2178
- this.twilioService.initializeTwilioDevice();
2179
- this.isInitialized = true;
2180
- // Subscribe to incoming calls
2181
- const callSub = this.twilioService.currentCall.subscribe(call => {
2182
- if (call) {
2183
- this.isCallInProgress = true;
2184
- this.isDialpadHidden = false; // Show dialpad on incoming call
2185
- }
2186
- });
2187
- this.subscriptions.add(callSub);
2188
- }
2189
2173
  constructor(twilioService, extService, dialog, ipService, extensionService, router) {
2190
2174
  this.twilioService = twilioService;
2191
2175
  this.extService = extService;
@@ -2193,7 +2177,7 @@ class DialboxComponent {
2193
2177
  this.ipService = ipService;
2194
2178
  this.extensionService = extensionService;
2195
2179
  this.router = router;
2196
- this._isDialpadHidden = true;
2180
+ this.isDialpadHidden = true;
2197
2181
  this.closeDialpadEvent = new EventEmitter();
2198
2182
  this.callInitiated = new EventEmitter();
2199
2183
  this.endCallEvent = new EventEmitter();
@@ -2239,21 +2223,75 @@ class DialboxComponent {
2239
2223
  this.subscriptions = new Subscription();
2240
2224
  this.shakeDedicatedBtn = false;
2241
2225
  this.isSmartDialCall = false;
2242
- this.isInitialized = false;
2243
2226
  this.isMinimised = false;
2244
2227
  }
2228
+ initializeTwilio() {
2229
+ if (!this.twilioService || !this.token) {
2230
+ return;
2231
+ }
2232
+ this.twilioService.initializeTwilioDevice();
2233
+ this.setupIncomingCallSubscription();
2234
+ }
2235
+ setupIncomingCallSubscription() {
2236
+ this.subscriptions.add(this.twilioService.currentCall.subscribe(incomingCallData => {
2237
+ if (incomingCallData) {
2238
+ if (this.isCallInProgress) {
2239
+ this.newIncomingCalls.push(incomingCallData);
2240
+ this.getUserInformation(incomingCallData);
2241
+ }
2242
+ else {
2243
+ this.handleNewIncomingCall(incomingCallData);
2244
+ }
2245
+ }
2246
+ }));
2247
+ }
2248
+ handleNewIncomingCall(call) {
2249
+ this.isCallInProgress = true;
2250
+ this.isDialpadHidden = false; // Show the dialpad when there's an incoming call
2251
+ this.callData = {
2252
+ phone: call.parameters['From'],
2253
+ displayNum: call.parameters['From'],
2254
+ dial: true,
2255
+ name: call.customParameters?.get('name') || 'Unknown',
2256
+ img: call.customParameters?.get('image') || 'assets/images/user.jpg',
2257
+ isIncomingCall: true,
2258
+ extNum: ''
2259
+ };
2260
+ call.on('cancel', () => this.handleCallEnd(call));
2261
+ call.on('disconnect', () => this.handleCallEnd(call));
2262
+ this.incomingCallInitiated.emit();
2263
+ }
2264
+ handleCallEnd(call) {
2265
+ this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters.CallSid !== call.parameters['CallSid']);
2266
+ if (this.incomingCallsList.length === 0) {
2267
+ this.isCallInProgress = false;
2268
+ this.resetCallData();
2269
+ }
2270
+ }
2271
+ resetCallData() {
2272
+ this.callData = {
2273
+ phone: '',
2274
+ displayNum: '',
2275
+ dial: false,
2276
+ name: '',
2277
+ img: 'assets/images/user.jpg',
2278
+ isIncomingCall: false,
2279
+ extNum: ''
2280
+ };
2281
+ }
2245
2282
  ngOnInit() {
2246
2283
  try {
2247
2284
  this.token = localStorage.getItem('ext_token') || '';
2248
2285
  this.initializeTwilio();
2286
+ this.getUserCallSetting();
2287
+ this.getContactList();
2249
2288
  this.getContactList();
2250
2289
  this.getUserCallSetting();
2251
- // Subscribe to dial number events
2252
2290
  const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
2253
- if (contact?.number) {
2291
+ if (contact.number) {
2254
2292
  this.isSmartDialCall = false;
2255
2293
  if (contact.isDialFromHistory) {
2256
- // Handle dialing from history page
2294
+ //handle dialing from history page
2257
2295
  if (contact.callerId == 'smartDialing') {
2258
2296
  this.selectedCallerId = { number: contact.from };
2259
2297
  this.isSmartDialCall = true;
@@ -2367,12 +2405,15 @@ class DialboxComponent {
2367
2405
  this.registerDragElement();
2368
2406
  }
2369
2407
  ngOnChanges(changes) {
2370
- if (changes['isDialpadHidden'] && !this.isDialpadHidden) {
2371
- this.getContactList();
2372
- this.getUserCallSetting();
2373
- setTimeout(() => {
2374
- this.dialInputElement.nativeElement.focus();
2375
- }, 0);
2408
+ if (changes['isDialpadHidden']) {
2409
+ if (!this.isDialpadHidden) {
2410
+ // Focus the input when dialpad becomes visible
2411
+ setTimeout(() => {
2412
+ if (this.dialInputElement?.nativeElement) {
2413
+ this.dialInputElement.nativeElement.focus();
2414
+ }
2415
+ }, 0);
2416
+ }
2376
2417
  }
2377
2418
  }
2378
2419
  registerDragElement() {
@@ -2582,6 +2623,232 @@ class DialboxComponent {
2582
2623
  this.endCallEvent.emit();
2583
2624
  }
2584
2625
  }
2626
+ // async initiateCall() {
2627
+ // try {
2628
+ // console.log('Initiating call with number:', this.dialedNumber);
2629
+ // if (!this.dialedNumber && this.lastDialed) {
2630
+ // console.log('Using last dialed number:', this.lastDialed.number);
2631
+ // this.sanitizedNum = this.lastDialed.number;
2632
+ // }
2633
+ // const isInvalid = await this.isInvalidNumber();
2634
+ // if (isInvalid) {
2635
+ // console.error('Invalid number format');
2636
+ // return false;
2637
+ // }
2638
+ // this.saveLastDialed();
2639
+ // this.isSavedContactDialled();
2640
+ // // Check payment status
2641
+ // this.isPaymentDue = localStorage.getItem('paymentDue') === 'true';
2642
+ // if (this.isPaymentDue) {
2643
+ // console.warn('Payment is due');
2644
+ // swal('Warning', 'Please note that your payment is due. To continue using our services, kindly subscribe to avoid interruptions.');
2645
+ // return false;
2646
+ // }
2647
+ // // Check if dialing own number
2648
+ // if (this.sanitizedNum === localStorage.getItem('twilioNumber')) {
2649
+ // console.error('Attempted to dial own number');
2650
+ // swal('Error', 'You cannot dial your own number');
2651
+ // return false;
2652
+ // }
2653
+ // // Check microphone permissions
2654
+ // const hasPermission = await this.checkMicrophonePermission();
2655
+ // if (!hasPermission) {
2656
+ // console.warn('Microphone permission not granted');
2657
+ // await this.askForMicrophonePermission();
2658
+ // return false;
2659
+ // }
2660
+ // if (!this.selectedCallerId) {
2661
+ // console.error('No caller ID selected');
2662
+ // this.shakeDedicatedBtn = true;
2663
+ // this.showDialAlert('Please select a C2C number to call from');
2664
+ // setTimeout(() => {
2665
+ // this.shakeDedicatedBtn = false;
2666
+ // }, 3000);
2667
+ // return false;
2668
+ // }
2669
+ // console.log('Getting number with country code...');
2670
+ // this.callData.displayNum = '';
2671
+ // try {
2672
+ // await this.getToNumber(this.sanitizedNum);
2673
+ // } catch (error) {
2674
+ // console.error('Error getting number with country code:', error);
2675
+ // this.showDialAlert('Error processing number. Please try again.');
2676
+ // return false;
2677
+ // }
2678
+ // if (this.terminateCall) {
2679
+ // console.log('Call terminated by user');
2680
+ // this.terminateCall = false;
2681
+ // return false;
2682
+ // }
2683
+ // // Prepare call data
2684
+ // this.callData = {
2685
+ // ...this.callData,
2686
+ // phone: this.sanitizedNum,
2687
+ // isIncomingCall: false,
2688
+ // dial: true,
2689
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2690
+ // timestamp: new Date().toISOString()
2691
+ // };
2692
+ // console.log('Initiating call with data:', this.callData);
2693
+ // this.isCallInProgress = true;
2694
+ // this.callInitiated.emit({ ...this.callData });
2695
+ // return true;
2696
+ // } catch (error) {
2697
+ // console.error('Error in initiateCall:', error);
2698
+ // this.showDialAlert('Failed to initiate call. Please try again.');
2699
+ // this.isCallInProgress = false;
2700
+ // return false;
2701
+ // }
2702
+ // //this.clearAllDialed();
2703
+ // // } else {
2704
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2705
+ // // }
2706
+ // }
2707
+ // async initiateCall() {
2708
+ // if (!this.dialedNumber && this.lastDialed) {
2709
+ // this.sanitizedNum = this.lastDialed.number;
2710
+ // }
2711
+ // const isInvalid = await this.isInvalidNumber();
2712
+ // if (isInvalid) {
2713
+ // return false;
2714
+ // }
2715
+ // this.saveLastDialed();
2716
+ // this.isSavedContactDialled();
2717
+ // //let isCallerIdSet = await this.isCallerIdSet();
2718
+ // this.isPaymentDue = localStorage.getItem('paymentDue') == 'false' ? false : true;
2719
+ // if (this.isPaymentDue) {
2720
+ // swal('Warning', 'Please note that your payment is due, To continue on your services kindly subscribe to use uninterrupted services.');
2721
+ // return;
2722
+ // }
2723
+ // this.isTrialPeriodOver = localStorage.getItem('trialOver') == 'false' ? false : true;
2724
+ // // if (!this.isTrialPeriodOver) {
2725
+ // if (this.sanitizedNum == localStorage.getItem('twilioNumber')) {
2726
+ // swal('Error', 'You can not dial this number');
2727
+ // return;
2728
+ // }
2729
+ // const hasPermission = await this.checkMicrophonePermission();
2730
+ // if (hasPermission) {
2731
+ // if (this.selectedCallerId) {
2732
+ // //clear displayNum if value is binded from previous call
2733
+ // this.callData.displayNum = '';
2734
+ // // get number to be dialled from backend
2735
+ // await this.getToNumber(this.sanitizedNum);
2736
+ // if (this.terminateCall) {
2737
+ // this.terminateCall = false;
2738
+ // return;
2739
+ // }
2740
+ // this.callData.phone = this.sanitizedNum;
2741
+ // this.callData.isIncomingCall = false;
2742
+ // this.callData.dial = true;
2743
+ // if (!this.isSmartDialCall) {
2744
+ // this.callData.from = this.selectedCallerId.number;
2745
+ // }
2746
+ // this.isCallInProgress = true;
2747
+ // this.callData = {
2748
+ // ...this.callData,
2749
+ // phone: this.sanitizedNum,
2750
+ // isIncomingCall: false,
2751
+ // dial: true,
2752
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2753
+ // timestamp: new Date().toISOString()
2754
+ // };
2755
+ // console.log('Initiating call with data:', this.callData);
2756
+ // this.isCallInProgress = true;
2757
+ // this.callInitiated.emit({ ...this.callData });
2758
+ // return true;
2759
+ // } else {
2760
+ // this.shakeDedicatedBtn = true;
2761
+ // this.showDialAlert('Select a C2C number to call');
2762
+ // setTimeout(() => {
2763
+ // this.shakeDedicatedBtn = false;
2764
+ // }, 3000);
2765
+ // return false;
2766
+ // }
2767
+ // //this.callingOpenEvent.emit({ phone: this.dialedNumber });
2768
+ // } else {
2769
+ // await this.askForMicrophonePermission();
2770
+ // }
2771
+ // //this.clearAllDialed();
2772
+ // // } else {
2773
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2774
+ // // }
2775
+ // }
2776
+ // async initiateCall() {
2777
+ // try{
2778
+ // if (!this.dialedNumber && this.lastDialed) {
2779
+ // this.sanitizedNum = this.lastDialed.number;
2780
+ // }
2781
+ // const isInvalid = await this.isInvalidNumber();
2782
+ // if (isInvalid) {
2783
+ // return false;
2784
+ // }
2785
+ // this.saveLastDialed();
2786
+ // this.isSavedContactDialled();
2787
+ // //let isCallerIdSet = await this.isCallerIdSet();
2788
+ // this.isPaymentDue = localStorage.getItem('paymentDue') == 'false' ? false : true;
2789
+ // if (this.isPaymentDue) {
2790
+ // swal('Warning', 'Please note that your payment is due, To continue on your services kindly subscribe to use uninterrupted services.');
2791
+ // return false;
2792
+ // }
2793
+ // this.isTrialPeriodOver = localStorage.getItem('trialOver') == 'false' ? false : true;
2794
+ // // if (!this.isTrialPeriodOver) {
2795
+ // if (this.sanitizedNum == localStorage.getItem('twilioNumber')) {
2796
+ // swal('Error', 'You can not dial this number');
2797
+ // return false;
2798
+ // }
2799
+ // const hasPermission = await this.checkMicrophonePermission();
2800
+ // if (hasPermission) {
2801
+ // if (this.selectedCallerId) {
2802
+ // //clear displayNum if value is binded from previous call
2803
+ // this.callData.displayNum = '';
2804
+ // // get number to be dialled from backend
2805
+ // await this.getToNumber(this.sanitizedNum);
2806
+ // if (this.terminateCall) {
2807
+ // this.terminateCall = false;
2808
+ // return;
2809
+ // }
2810
+ // this.callData.phone = this.sanitizedNum;
2811
+ // this.callData.isIncomingCall = false;
2812
+ // this.callData.dial = true;
2813
+ // if (!this.isSmartDialCall) {
2814
+ // this.callData.from = this.selectedCallerId.number;
2815
+ // }
2816
+ // this.isCallInProgress = true;
2817
+ // this.callData = {
2818
+ // ...this.callData,
2819
+ // phone: this.sanitizedNum,
2820
+ // isIncomingCall: false,
2821
+ // dial: true,
2822
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2823
+ // timestamp: new Date().toISOString()
2824
+ // };
2825
+ // console.log('Initiating call with data:', this.callData);
2826
+ // this.isCallInProgress = true;
2827
+ // this.callInitiated.emit({ ...this.callData });
2828
+ // return true;
2829
+ // } else {
2830
+ // this.shakeDedicatedBtn = true;
2831
+ // this.showDialAlert('Select a C2C number to call');
2832
+ // setTimeout(() => {
2833
+ // this.shakeDedicatedBtn = false;
2834
+ // }, 3000);
2835
+ // return false;
2836
+ // }
2837
+ // //this.callingOpenEvent.emit({ phone: this.dialedNumber });
2838
+ // } else {
2839
+ // await this.askForMicrophonePermission();
2840
+ // }
2841
+ // //this.clearAllDialed();
2842
+ // // } else {
2843
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2844
+ // // }
2845
+ // }catch(e){
2846
+ // console.error('Error in initiateCall:', e);
2847
+ // this.showDialAlert('Failed to initiate call. Please try again.');
2848
+ // this.isCallInProgress = false;
2849
+ // return false;
2850
+ // }
2851
+ // }
2585
2852
  async initiateCall() {
2586
2853
  try {
2587
2854
  if (!this.dialedNumber && this.lastDialed) {