@vgroup/dialbox 0.0.24 → 0.0.25

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.
@@ -14,7 +14,7 @@ import * as i3 from '@angular/common';
14
14
  import { CommonModule } from '@angular/common';
15
15
  import * as i3$1 from '@angular/forms';
16
16
  import { FormsModule, ReactiveFormsModule } from '@angular/forms';
17
- import { Device } from '@twilio/voice-sdk';
17
+ import { Device as Device$1 } from '@twilio/voice-sdk';
18
18
 
19
19
  const keypad = [
20
20
  {
@@ -114,13 +114,61 @@ class TwilioService {
114
114
  this.isAvailableNumber = new BehaviorSubject(false);
115
115
  this.callerIdList = new BehaviorSubject([]);
116
116
  this.triggerSMSReload = new BehaviorSubject(false);
117
+ this.initializeTwilioDevice();
118
+ }
119
+ // Initialize Twilio device and set up event listeners
120
+ initializeTwilioDevice() {
121
+ // Get the Twilio token from localStorage
122
+ const token = localStorage.getItem('twilio_token');
123
+ if (!token) {
124
+ console.error('Twilio token not found in localStorage');
125
+ return;
126
+ }
127
+ // Initialize the Twilio Device
128
+ // @ts-ignore - We'll handle the device setup
129
+ this.device = new Device(token, {
130
+ codecPreferences: ['opus', 'pcmu'],
131
+ debug: true
132
+ });
133
+ // Set up device event listeners
134
+ this.device.on('ready', (device) => {
135
+ console.log('Twilio Device Ready');
136
+ });
137
+ this.device.on('error', (error) => {
138
+ console.error('Twilio Device Error:', error);
139
+ this.currentCallState.next('error');
140
+ });
141
+ // Handle incoming calls
142
+ this.device.on('incoming', (call) => {
143
+ console.log('Incoming call:', call);
144
+ this.currentCall.next(call);
145
+ this.currentCallState.next('incoming');
146
+ this.callType.next('INCOMING');
147
+ // Set up call event handlers
148
+ call.on('accept', () => {
149
+ console.log('Call accepted');
150
+ this.currentCallState.next('in-progress');
151
+ this.isIncomingCallPicked.next(true);
152
+ });
153
+ call.on('disconnect', () => {
154
+ console.log('Call disconnected');
155
+ this.currentCall.next(null);
156
+ this.currentCallState.next('none');
157
+ this.isIncomingCallPicked.next(false);
158
+ });
159
+ call.on('reject', () => {
160
+ console.log('Call rejected');
161
+ this.currentCall.next(null);
162
+ this.currentCallState.next('none');
163
+ });
164
+ });
165
+ }
166
+ // Update Twilio token when needed
167
+ updateToken(token) {
168
+ if (this.device) {
169
+ this.device.updateToken(token);
170
+ }
117
171
  }
118
- // onIncomingCall(){
119
- // this.device.on('incoming', (call:any) => {
120
- // console.log(call);
121
- // //call.accept();
122
- // });
123
- // }
124
172
  saveContact(payload) {
125
173
  const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
126
174
  return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
@@ -1445,6 +1493,25 @@ class IncomingCallComponent {
1445
1493
  if (!call.parameters) {
1446
1494
  call.parameters = {};
1447
1495
  }
1496
+ // Fetch user information when call is received
1497
+ if (this.twilioAuthId) {
1498
+ this.extensionService.getUserInformation(this.twilioAuthId).subscribe({
1499
+ next: (userInfo) => {
1500
+ console.log('User information:', userInfo);
1501
+ // Update the call data with user information
1502
+ if (userInfo && userInfo.data) {
1503
+ this.incomingCallData = {
1504
+ ...this.incomingCallData,
1505
+ callerInfo: userInfo.data
1506
+ };
1507
+ this.selectedIncomingCallInfo.emit(this.incomingCallData);
1508
+ }
1509
+ },
1510
+ error: (error) => {
1511
+ console.error('Error fetching user information:', error);
1512
+ }
1513
+ });
1514
+ }
1448
1515
  this.sendIPforIncomingCall(this.twilioAuthId, '');
1449
1516
  call.on('cancel', () => {
1450
1517
  if (this.incomingCallData && this.incomingCallData.parameters && this.incomingCallData.parameters.CallSid) {
@@ -1714,7 +1781,7 @@ class CallProgressComponent {
1714
1781
  codecPreferences: ['opus', 'pcmu'],
1715
1782
  closeProtection: true,
1716
1783
  };
1717
- this.device = new Device(token.value, options);
1784
+ this.device = new Device$1(token.value, options);
1718
1785
  this.call = await this.device.connect({
1719
1786
  params: {
1720
1787
  From: callData.from,