@vgroup/dialbox 0.0.57 → 0.0.58

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.
@@ -1315,77 +1315,36 @@ class TwilioService {
1315
1315
  this.isAvailableNumber = new BehaviorSubject(false);
1316
1316
  this.callerIdList = new BehaviorSubject([]);
1317
1317
  this.triggerSMSReload = new BehaviorSubject(false);
1318
- this.isInitialized = false;
1319
- this.initializationInProgress = false;
1320
1318
  this.initializeTwilioDevice();
1321
1319
  }
1322
1320
  initializeTwilioDevice() {
1323
- if (this.initializationInProgress || this.isInitialized)
1324
- return;
1325
- this.initializationInProgress = true;
1326
- this.extensionService.getIncomingCallToken().subscribe({
1327
- next: (data) => {
1328
- if (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();
1342
- this.isInitialized = true;
1343
- this.initializationInProgress = false;
1344
- }
1345
- },
1346
- error: (error) => {
1347
- console.error('Error initializing Twilio:', error);
1348
- this.initializationInProgress = false;
1349
- // Retry after delay
1350
- setTimeout(() => this.initializeTwilioDevice(), 5000);
1351
- }
1352
- });
1353
- }
1354
- setupDeviceEventListeners() {
1355
- if (!this.device)
1356
- return;
1357
- // Clean up existing listeners
1358
- this.device.removeAllListeners();
1359
- this.device.on('registered', () => {
1360
- console.log('Twilio Device registered successfully');
1361
- });
1362
- this.device.on('incoming', (call) => {
1363
- console.log('Incoming call received');
1364
- this.currentCall.next(call);
1365
- this.callType.next('INCOMING');
1366
- this.currentCallState.next('incoming');
1367
- });
1368
- this.device.on('error', (error) => {
1369
- console.error('Twilio Device Error:', error);
1370
- this.isInitialized = false;
1371
- // Attempt to reinitialize after error
1372
- setTimeout(() => this.initializeTwilioDevice(), 5000);
1373
- });
1374
- this.device.on('unregistered', () => {
1375
- console.log('Twilio Device unregistered');
1376
- this.isInitialized = false;
1377
- // Attempt to re-register
1378
- this.initializeTwilioDevice();
1379
- });
1380
- }
1381
- onIncomingCall() {
1382
- if (this.device) {
1383
- this.device.on('incoming', (call) => {
1384
- console.log('Incoming call:', call);
1385
- // call.accept();
1321
+ if (this.token) {
1322
+ this.extensionService.getIncomingCallToken().subscribe((data) => {
1323
+ this.incomingCallToken = data.token;
1324
+ localStorage.setItem('in-token', data.token);
1325
+ this.device = new Device(this.incomingCallToken, {
1326
+ allowIncomingWhileBusy: true,
1327
+ // Add any other necessary options
1328
+ });
1329
+ this.device.register();
1330
+ this.device.on('incoming', (call) => {
1331
+ this.currentCall.next(call);
1332
+ this.callType.next('INCOMING');
1333
+ this.currentCallState.next('incoming');
1334
+ });
1335
+ this.device.on('error', (error) => {
1336
+ console.error('Twilio Device Error:', error);
1337
+ // Add error handling and reconnection logic
1338
+ });
1386
1339
  });
1387
1340
  }
1388
1341
  }
1342
+ // onIncomingCall(){
1343
+ // this.device.on('incoming', (call:any) => {
1344
+ // console.log(call);
1345
+ // //call.accept();
1346
+ // });
1347
+ // }
1389
1348
  saveContact(payload) {
1390
1349
  const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
1391
1350
  return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
@@ -2170,6 +2129,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
2170
2129
  }] } });
2171
2130
 
2172
2131
  class DialboxComponent {
2132
+ set isDialpadHidden(value) {
2133
+ this._isDialpadHidden = value;
2134
+ if (!value) {
2135
+ // When dialpad becomes visible, ensure Twilio is initialized
2136
+ this.initializeTwilio();
2137
+ }
2138
+ }
2139
+ get isDialpadHidden() {
2140
+ return this._isDialpadHidden;
2141
+ }
2173
2142
  constructor(twilioService, extService, dialog, ipService, extensionService, router) {
2174
2143
  this.twilioService = twilioService;
2175
2144
  this.extService = extService;
@@ -2177,7 +2146,7 @@ class DialboxComponent {
2177
2146
  this.ipService = ipService;
2178
2147
  this.extensionService = extensionService;
2179
2148
  this.router = router;
2180
- this.isDialpadHidden = true;
2149
+ this._isDialpadHidden = true;
2181
2150
  this.closeDialpadEvent = new EventEmitter();
2182
2151
  this.callInitiated = new EventEmitter();
2183
2152
  this.endCallEvent = new EventEmitter();
@@ -2223,70 +2192,38 @@ class DialboxComponent {
2223
2192
  this.subscriptions = new Subscription();
2224
2193
  this.shakeDedicatedBtn = false;
2225
2194
  this.isSmartDialCall = false;
2195
+ this.isInitialized = false;
2226
2196
  this.isMinimised = false;
2197
+ // Initialize if dialpad is visible by default
2198
+ if (!this.isDialpadHidden) {
2199
+ this.initializeTwilio();
2200
+ }
2227
2201
  }
2228
2202
  initializeTwilio() {
2229
- if (!this.twilioService || !this.token) {
2203
+ if (this.isInitialized)
2204
+ return;
2205
+ this.token = localStorage.getItem('ext_token') || '';
2206
+ if (!this.token) {
2207
+ console.error('No authentication token found');
2230
2208
  return;
2231
2209
  }
2210
+ this.isInitialized = true;
2211
+ // Initialize Twilio service
2232
2212
  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
- }
2213
+ // Subscribe to incoming calls to show dialpad when call comes in
2214
+ const callSub = this.twilioService.currentCall.subscribe(call => {
2215
+ if (call) {
2216
+ this.isCallInProgress = true;
2217
+ this._isDialpadHidden = false; // Show dialpad on incoming call
2245
2218
  }
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
- };
2219
+ });
2220
+ this.subscriptions.add(callSub);
2281
2221
  }
2282
2222
  ngOnInit() {
2283
2223
  try {
2284
- this.token = localStorage.getItem('ext_token') || '';
2285
- this.initializeTwilio();
2286
- this.getUserCallSetting();
2287
- this.getContactList();
2288
2224
  this.getContactList();
2289
2225
  this.getUserCallSetting();
2226
+ // Subscribe to dial number events
2290
2227
  const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
2291
2228
  if (contact.number) {
2292
2229
  this.isSmartDialCall = false;
@@ -2405,15 +2342,12 @@ class DialboxComponent {
2405
2342
  this.registerDragElement();
2406
2343
  }
2407
2344
  ngOnChanges(changes) {
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
- }
2345
+ if (changes['isDialpadHidden'] && !this.isDialpadHidden) {
2346
+ this.getContactList();
2347
+ this.getUserCallSetting();
2348
+ setTimeout(() => {
2349
+ this.dialInputElement.nativeElement.focus();
2350
+ }, 0);
2417
2351
  }
2418
2352
  }
2419
2353
  registerDragElement() {
@@ -3146,6 +3080,10 @@ class DialboxComponent {
3146
3080
  if (this.subscriptions) {
3147
3081
  this.subscriptions.unsubscribe();
3148
3082
  }
3083
+ // Clean up Twilio device when component is destroyed
3084
+ if (this.twilioService['device']) {
3085
+ this.twilioService['device'].destroy();
3086
+ }
3149
3087
  // End any active call
3150
3088
  if (this.isCallInProgress) {
3151
3089
  this.endCall();