@vgroup/dialbox 0.0.27 → 0.0.29

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.
@@ -115,12 +115,28 @@ class TwilioService {
115
115
  this.callerIdList = new BehaviorSubject([]);
116
116
  this.triggerSMSReload = new BehaviorSubject(false);
117
117
  }
118
- // onIncomingCall(){
119
- // this.device.on('incoming', (call:any) => {
120
- // console.log(call);
121
- // //call.accept();
122
- // });
123
- // }
118
+ onIncomingCall() {
119
+ this.device.on('incoming', (call) => {
120
+ console.log('Incoming call from:', call.parameters['From']);
121
+ // Update the current call subject with the incoming call
122
+ this.currentCall.next(call);
123
+ // Update call state to ringing
124
+ this.currentCallState.next('ringing');
125
+ // Emit a custom event with the call data
126
+ this.dispatchIncomingCallEvent(call);
127
+ });
128
+ }
129
+ dispatchIncomingCallEvent(call) {
130
+ const event = new CustomEvent('incomingCall', {
131
+ detail: {
132
+ call,
133
+ isIncomingCall: true,
134
+ from: call.parameters['From'],
135
+ to: call.parameters['To']
136
+ }
137
+ });
138
+ window.dispatchEvent(event);
139
+ }
124
140
  saveContact(payload) {
125
141
  const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
126
142
  return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
@@ -1635,14 +1651,19 @@ class CallProgressComponent {
1635
1651
  }
1636
1652
  ngOnChanges(changes) {
1637
1653
  console.log('Call Progress Component ngOnChanges');
1638
- if (changes.callData) {
1639
- console.log('Call Progress Component ngOnChanges callData', changes.callData);
1640
- if (changes.callData.currentValue.isIncomingCall) {
1641
- changes.incomingCallDiv = true;
1654
+ console.log('Call Progress Component ngOnChanges changes', changes);
1655
+ if (changes['callData']) {
1656
+ console.log('Call Progress Component ngOnChanges callData', changes['callData'].currentValue);
1657
+ if (changes['callData'].currentValue?.isIncomingCall) {
1658
+ console.log('Incoming call detected, showing incoming call UI');
1659
+ this.incomingCallDiv = true;
1660
+ this.cdr.detectChanges(); // Trigger change detection
1642
1661
  }
1643
- else {
1644
- //for outgoing call
1645
- this.startCall(changes.callData.currentValue);
1662
+ else if (changes['callData'].currentValue) {
1663
+ // For outgoing call
1664
+ console.log('Outgoing call detected');
1665
+ this.incomingCallDiv = false;
1666
+ this.startCall(changes['callData'].currentValue);
1646
1667
  }
1647
1668
  }
1648
1669
  if (changes.newIncomingCallData) {
@@ -2154,18 +2175,35 @@ class DialboxComponent {
2154
2175
  // this.callData.isIncomingCall = true;
2155
2176
  // }
2156
2177
  if (incomingCallData) {
2178
+ // Create a new call data object to ensure change detection works
2179
+ const callSid = incomingCallData.parameters.CallSid;
2180
+ const fromNumber = incomingCallData.parameters.From;
2181
+ const newCallData = {
2182
+ phone: fromNumber,
2183
+ displayNum: fromNumber,
2184
+ dial: false,
2185
+ name: incomingCallData.customParameters.get('name') || fromNumber,
2186
+ img: incomingCallData.customParameters.get('image') || 'assets/images/user.jpg',
2187
+ isIncomingCall: true,
2188
+ callSid: callSid
2189
+ };
2157
2190
  if (this.isCallInProgress) {
2158
- this.newIncomingCalls.push(incomingCallData);
2191
+ // If there's already a call in progress, add to new incoming calls
2192
+ this.newIncomingCalls.push({
2193
+ ...newCallData,
2194
+ parameters: incomingCallData.parameters,
2195
+ customParameters: incomingCallData.customParameters
2196
+ });
2159
2197
  this.getUserInformation(incomingCallData);
2160
2198
  }
2161
2199
  else {
2200
+ // If no call in progress, handle as primary incoming call
2162
2201
  this.isCallInProgress = true;
2163
2202
  this.isDialpadHidden = false;
2164
- this.callData.phone = incomingCallData.parameters.From;
2203
+ // Update callData with a new object to trigger change detection
2204
+ this.callData = { ...newCallData };
2205
+ // Get additional user information
2165
2206
  this.getUserInformation(incomingCallData);
2166
- this.callData.name = incomingCallData.customParameters.get('name');
2167
- this.callData.img = incomingCallData.customParameters.get('image') || 'assets/images/user.jpg';
2168
- this.callData.isIncomingCall = true;
2169
2207
  }
2170
2208
  incomingCallData.on('cancel', () => {
2171
2209
  this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters.CallSid !== incomingCallData.parameters.CallSid);
@@ -2191,11 +2229,30 @@ class DialboxComponent {
2191
2229
  getUserInformation(incomingCallData) {
2192
2230
  console.log('getUserInformation', incomingCallData);
2193
2231
  let data = this.fromEntries(Array.from(incomingCallData.customParameters.entries()));
2194
- this.extensionService.getUserInformation(data.twilioAuthId).subscribe(response => {
2195
- incomingCallData['userInfo'] = response;
2196
- this.incomingCallsList.push(incomingCallData);
2232
+ this.extensionService.getUserInformation(data.twilioAuthId).subscribe((response) => {
2233
+ try {
2234
+ // Create a safe response object with default values
2235
+ const safeResponse = response || {};
2236
+ const c2cInfo = safeResponse.c2cInformation || {};
2237
+ // Update the call data with user information
2238
+ this.callData = {
2239
+ ...this.callData,
2240
+ name: c2cInfo.name || this.callData.name,
2241
+ displayNum: c2cInfo.number || this.callData.phone,
2242
+ userInfo: safeResponse
2243
+ };
2244
+ // Add to incoming calls list
2245
+ incomingCallData['userInfo'] = safeResponse;
2246
+ this.incomingCallsList = [...this.incomingCallsList, incomingCallData];
2247
+ }
2248
+ catch (error) {
2249
+ console.error('Error processing user information:', error);
2250
+ }
2197
2251
  }, error => {
2198
- console.error('Error starting recording', error);
2252
+ console.error('Error fetching user information:', error);
2253
+ // Even if there's an error, we should still add the call to the list
2254
+ incomingCallData['userInfo'] = { error: 'Failed to fetch user details' };
2255
+ this.incomingCallsList = [...this.incomingCallsList, incomingCallData];
2199
2256
  });
2200
2257
  }
2201
2258
  fromEntries(entries) {