@vgroup/dialbox 0.0.55 → 0.0.56

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.
@@ -1318,7 +1318,17 @@ class TwilioService {
1318
1318
  this.isInitialized = false;
1319
1319
  this.initializationInProgress = false;
1320
1320
  // Initialize when token is available
1321
- this.initializeTwilioDevice();
1321
+ if (this.token) {
1322
+ this.initializeTwilioDevice();
1323
+ }
1324
+ else {
1325
+ // If token is not available, try to get it from localStorage
1326
+ const token = localStorage.getItem('ext_token');
1327
+ if (token) {
1328
+ this.token = token;
1329
+ this.initializeTwilioDevice();
1330
+ }
1331
+ }
1322
1332
  }
1323
1333
  initializeTwilioDevice() {
1324
1334
  if (this.initializationInProgress || !this.token)
@@ -2165,27 +2175,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
2165
2175
  class DialboxComponent {
2166
2176
  set isDialpadHidden(value) {
2167
2177
  this._isDialpadHidden = value;
2168
- if (!value && !this.isInitialized) {
2178
+ if (!value) {
2179
+ // When dialpad becomes visible, ensure Twilio is initialized
2169
2180
  this.initializeTwilio();
2170
2181
  }
2171
2182
  }
2172
2183
  get isDialpadHidden() {
2173
2184
  return this._isDialpadHidden;
2174
2185
  }
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
2186
  constructor(twilioService, extService, dialog, ipService, extensionService, router) {
2190
2187
  this.twilioService = twilioService;
2191
2188
  this.extService = extService;
@@ -2241,19 +2238,41 @@ class DialboxComponent {
2241
2238
  this.isSmartDialCall = false;
2242
2239
  this.isInitialized = false;
2243
2240
  this.isMinimised = false;
2241
+ // Initialize if dialpad is visible by default
2242
+ if (!this.isDialpadHidden) {
2243
+ this.initializeTwilio();
2244
+ }
2245
+ }
2246
+ initializeTwilio() {
2247
+ if (this.isInitialized)
2248
+ return;
2249
+ this.token = localStorage.getItem('ext_token') || '';
2250
+ if (!this.token) {
2251
+ console.error('No authentication token found');
2252
+ return;
2253
+ }
2254
+ this.isInitialized = true;
2255
+ // Initialize Twilio service
2256
+ this.twilioService.initializeTwilioDevice();
2257
+ // Subscribe to incoming calls to show dialpad when call comes in
2258
+ const callSub = this.twilioService.currentCall.subscribe(call => {
2259
+ if (call) {
2260
+ this.isCallInProgress = true;
2261
+ this._isDialpadHidden = false; // Show dialpad on incoming call
2262
+ }
2263
+ });
2264
+ this.subscriptions.add(callSub);
2244
2265
  }
2245
2266
  ngOnInit() {
2246
2267
  try {
2247
- this.token = localStorage.getItem('ext_token') || '';
2248
- this.initializeTwilio();
2249
2268
  this.getContactList();
2250
2269
  this.getUserCallSetting();
2251
2270
  // Subscribe to dial number events
2252
2271
  const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
2253
- if (contact?.number) {
2272
+ if (contact.number) {
2254
2273
  this.isSmartDialCall = false;
2255
2274
  if (contact.isDialFromHistory) {
2256
- // Handle dialing from history page
2275
+ //handle dialing from history page
2257
2276
  if (contact.callerId == 'smartDialing') {
2258
2277
  this.selectedCallerId = { number: contact.from };
2259
2278
  this.isSmartDialCall = true;
@@ -2582,6 +2601,232 @@ class DialboxComponent {
2582
2601
  this.endCallEvent.emit();
2583
2602
  }
2584
2603
  }
2604
+ // async initiateCall() {
2605
+ // try {
2606
+ // console.log('Initiating call with number:', this.dialedNumber);
2607
+ // if (!this.dialedNumber && this.lastDialed) {
2608
+ // console.log('Using last dialed number:', this.lastDialed.number);
2609
+ // this.sanitizedNum = this.lastDialed.number;
2610
+ // }
2611
+ // const isInvalid = await this.isInvalidNumber();
2612
+ // if (isInvalid) {
2613
+ // console.error('Invalid number format');
2614
+ // return false;
2615
+ // }
2616
+ // this.saveLastDialed();
2617
+ // this.isSavedContactDialled();
2618
+ // // Check payment status
2619
+ // this.isPaymentDue = localStorage.getItem('paymentDue') === 'true';
2620
+ // if (this.isPaymentDue) {
2621
+ // console.warn('Payment is due');
2622
+ // swal('Warning', 'Please note that your payment is due. To continue using our services, kindly subscribe to avoid interruptions.');
2623
+ // return false;
2624
+ // }
2625
+ // // Check if dialing own number
2626
+ // if (this.sanitizedNum === localStorage.getItem('twilioNumber')) {
2627
+ // console.error('Attempted to dial own number');
2628
+ // swal('Error', 'You cannot dial your own number');
2629
+ // return false;
2630
+ // }
2631
+ // // Check microphone permissions
2632
+ // const hasPermission = await this.checkMicrophonePermission();
2633
+ // if (!hasPermission) {
2634
+ // console.warn('Microphone permission not granted');
2635
+ // await this.askForMicrophonePermission();
2636
+ // return false;
2637
+ // }
2638
+ // if (!this.selectedCallerId) {
2639
+ // console.error('No caller ID selected');
2640
+ // this.shakeDedicatedBtn = true;
2641
+ // this.showDialAlert('Please select a C2C number to call from');
2642
+ // setTimeout(() => {
2643
+ // this.shakeDedicatedBtn = false;
2644
+ // }, 3000);
2645
+ // return false;
2646
+ // }
2647
+ // console.log('Getting number with country code...');
2648
+ // this.callData.displayNum = '';
2649
+ // try {
2650
+ // await this.getToNumber(this.sanitizedNum);
2651
+ // } catch (error) {
2652
+ // console.error('Error getting number with country code:', error);
2653
+ // this.showDialAlert('Error processing number. Please try again.');
2654
+ // return false;
2655
+ // }
2656
+ // if (this.terminateCall) {
2657
+ // console.log('Call terminated by user');
2658
+ // this.terminateCall = false;
2659
+ // return false;
2660
+ // }
2661
+ // // Prepare call data
2662
+ // this.callData = {
2663
+ // ...this.callData,
2664
+ // phone: this.sanitizedNum,
2665
+ // isIncomingCall: false,
2666
+ // dial: true,
2667
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2668
+ // timestamp: new Date().toISOString()
2669
+ // };
2670
+ // console.log('Initiating call with data:', this.callData);
2671
+ // this.isCallInProgress = true;
2672
+ // this.callInitiated.emit({ ...this.callData });
2673
+ // return true;
2674
+ // } catch (error) {
2675
+ // console.error('Error in initiateCall:', error);
2676
+ // this.showDialAlert('Failed to initiate call. Please try again.');
2677
+ // this.isCallInProgress = false;
2678
+ // return false;
2679
+ // }
2680
+ // //this.clearAllDialed();
2681
+ // // } else {
2682
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2683
+ // // }
2684
+ // }
2685
+ // async initiateCall() {
2686
+ // if (!this.dialedNumber && this.lastDialed) {
2687
+ // this.sanitizedNum = this.lastDialed.number;
2688
+ // }
2689
+ // const isInvalid = await this.isInvalidNumber();
2690
+ // if (isInvalid) {
2691
+ // return false;
2692
+ // }
2693
+ // this.saveLastDialed();
2694
+ // this.isSavedContactDialled();
2695
+ // //let isCallerIdSet = await this.isCallerIdSet();
2696
+ // this.isPaymentDue = localStorage.getItem('paymentDue') == 'false' ? false : true;
2697
+ // if (this.isPaymentDue) {
2698
+ // swal('Warning', 'Please note that your payment is due, To continue on your services kindly subscribe to use uninterrupted services.');
2699
+ // return;
2700
+ // }
2701
+ // this.isTrialPeriodOver = localStorage.getItem('trialOver') == 'false' ? false : true;
2702
+ // // if (!this.isTrialPeriodOver) {
2703
+ // if (this.sanitizedNum == localStorage.getItem('twilioNumber')) {
2704
+ // swal('Error', 'You can not dial this number');
2705
+ // return;
2706
+ // }
2707
+ // const hasPermission = await this.checkMicrophonePermission();
2708
+ // if (hasPermission) {
2709
+ // if (this.selectedCallerId) {
2710
+ // //clear displayNum if value is binded from previous call
2711
+ // this.callData.displayNum = '';
2712
+ // // get number to be dialled from backend
2713
+ // await this.getToNumber(this.sanitizedNum);
2714
+ // if (this.terminateCall) {
2715
+ // this.terminateCall = false;
2716
+ // return;
2717
+ // }
2718
+ // this.callData.phone = this.sanitizedNum;
2719
+ // this.callData.isIncomingCall = false;
2720
+ // this.callData.dial = true;
2721
+ // if (!this.isSmartDialCall) {
2722
+ // this.callData.from = this.selectedCallerId.number;
2723
+ // }
2724
+ // this.isCallInProgress = true;
2725
+ // this.callData = {
2726
+ // ...this.callData,
2727
+ // phone: this.sanitizedNum,
2728
+ // isIncomingCall: false,
2729
+ // dial: true,
2730
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2731
+ // timestamp: new Date().toISOString()
2732
+ // };
2733
+ // console.log('Initiating call with data:', this.callData);
2734
+ // this.isCallInProgress = true;
2735
+ // this.callInitiated.emit({ ...this.callData });
2736
+ // return true;
2737
+ // } else {
2738
+ // this.shakeDedicatedBtn = true;
2739
+ // this.showDialAlert('Select a C2C number to call');
2740
+ // setTimeout(() => {
2741
+ // this.shakeDedicatedBtn = false;
2742
+ // }, 3000);
2743
+ // return false;
2744
+ // }
2745
+ // //this.callingOpenEvent.emit({ phone: this.dialedNumber });
2746
+ // } else {
2747
+ // await this.askForMicrophonePermission();
2748
+ // }
2749
+ // //this.clearAllDialed();
2750
+ // // } else {
2751
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2752
+ // // }
2753
+ // }
2754
+ // async initiateCall() {
2755
+ // try{
2756
+ // if (!this.dialedNumber && this.lastDialed) {
2757
+ // this.sanitizedNum = this.lastDialed.number;
2758
+ // }
2759
+ // const isInvalid = await this.isInvalidNumber();
2760
+ // if (isInvalid) {
2761
+ // return false;
2762
+ // }
2763
+ // this.saveLastDialed();
2764
+ // this.isSavedContactDialled();
2765
+ // //let isCallerIdSet = await this.isCallerIdSet();
2766
+ // this.isPaymentDue = localStorage.getItem('paymentDue') == 'false' ? false : true;
2767
+ // if (this.isPaymentDue) {
2768
+ // swal('Warning', 'Please note that your payment is due, To continue on your services kindly subscribe to use uninterrupted services.');
2769
+ // return false;
2770
+ // }
2771
+ // this.isTrialPeriodOver = localStorage.getItem('trialOver') == 'false' ? false : true;
2772
+ // // if (!this.isTrialPeriodOver) {
2773
+ // if (this.sanitizedNum == localStorage.getItem('twilioNumber')) {
2774
+ // swal('Error', 'You can not dial this number');
2775
+ // return false;
2776
+ // }
2777
+ // const hasPermission = await this.checkMicrophonePermission();
2778
+ // if (hasPermission) {
2779
+ // if (this.selectedCallerId) {
2780
+ // //clear displayNum if value is binded from previous call
2781
+ // this.callData.displayNum = '';
2782
+ // // get number to be dialled from backend
2783
+ // await this.getToNumber(this.sanitizedNum);
2784
+ // if (this.terminateCall) {
2785
+ // this.terminateCall = false;
2786
+ // return;
2787
+ // }
2788
+ // this.callData.phone = this.sanitizedNum;
2789
+ // this.callData.isIncomingCall = false;
2790
+ // this.callData.dial = true;
2791
+ // if (!this.isSmartDialCall) {
2792
+ // this.callData.from = this.selectedCallerId.number;
2793
+ // }
2794
+ // this.isCallInProgress = true;
2795
+ // this.callData = {
2796
+ // ...this.callData,
2797
+ // phone: this.sanitizedNum,
2798
+ // isIncomingCall: false,
2799
+ // dial: true,
2800
+ // from: this.isSmartDialCall ? this.callData.from : this.selectedCallerId.number,
2801
+ // timestamp: new Date().toISOString()
2802
+ // };
2803
+ // console.log('Initiating call with data:', this.callData);
2804
+ // this.isCallInProgress = true;
2805
+ // this.callInitiated.emit({ ...this.callData });
2806
+ // return true;
2807
+ // } else {
2808
+ // this.shakeDedicatedBtn = true;
2809
+ // this.showDialAlert('Select a C2C number to call');
2810
+ // setTimeout(() => {
2811
+ // this.shakeDedicatedBtn = false;
2812
+ // }, 3000);
2813
+ // return false;
2814
+ // }
2815
+ // //this.callingOpenEvent.emit({ phone: this.dialedNumber });
2816
+ // } else {
2817
+ // await this.askForMicrophonePermission();
2818
+ // }
2819
+ // //this.clearAllDialed();
2820
+ // // } else {
2821
+ // // swal('Error', 'Trial period is over. Please setup payment method to continue services')
2822
+ // // }
2823
+ // }catch(e){
2824
+ // console.error('Error in initiateCall:', e);
2825
+ // this.showDialAlert('Failed to initiate call. Please try again.');
2826
+ // this.isCallInProgress = false;
2827
+ // return false;
2828
+ // }
2829
+ // }
2585
2830
  async initiateCall() {
2586
2831
  try {
2587
2832
  if (!this.dialedNumber && this.lastDialed) {
@@ -2879,6 +3124,10 @@ class DialboxComponent {
2879
3124
  if (this.subscriptions) {
2880
3125
  this.subscriptions.unsubscribe();
2881
3126
  }
3127
+ // Clean up Twilio device when component is destroyed
3128
+ if (this.twilioService['device']) {
3129
+ this.twilioService['device'].destroy();
3130
+ }
2882
3131
  // End any active call
2883
3132
  if (this.isCallInProgress) {
2884
3133
  this.endCall();