@vgroup/dialbox 0.2.59 → 0.2.61

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.
@@ -2110,19 +2110,22 @@ class CallProgressComponent {
2110
2110
  scope: 'local',
2111
2111
  };
2112
2112
  const response = await this.initiateCall(payload);
2113
+ this.conferenceId = response?.callauth?.id;
2113
2114
  if (response.status == 200) {
2114
2115
  const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2115
2116
  this.getUserInformation(callAuthId);
2116
2117
  this.recordCall = recordCall; // Store the recordCall value
2117
2118
  const tokenData = await this.getOutgoingCallToken(callAuthId);
2118
2119
  await this.connectToDevice(tokenData.token, callData);
2119
- this.pollCallStatus(callAuthId);
2120
- await this.addParticipantToCall({
2121
- from: callData?.from,
2122
- route: "OUTGOING",
2123
- participantNumber: callData?.phone,
2124
- conferenceId: response?.callauth?.id
2125
- });
2120
+ await this.pollCallStatus(callAuthId);
2121
+ setTimeout(async () => {
2122
+ await this.addParticipantToCall({
2123
+ from: callData?.from,
2124
+ route: "OUTGOING",
2125
+ participantNumber: callData?.phone,
2126
+ conferenceId: response?.callauth?.id
2127
+ });
2128
+ }, 1000);
2126
2129
  // Poll the status for 30-45 seconds
2127
2130
  }
2128
2131
  else if (response.status == 201) {
@@ -2335,118 +2338,114 @@ class CallProgressComponent {
2335
2338
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2336
2339
  this.GetContactsList();
2337
2340
  }
2338
- async callContact(contact) {
2339
- console.log('Adding contact to call:', contact);
2340
- // Check if there's an active call
2341
- if (!this.call || this.call.status() !== 'open') {
2342
- console.error('No active call to add participant to');
2343
- return;
2344
- }
2345
- // Get the phone number from the contact
2346
- const phoneNumber = contact.numbersList && contact.numbersList[0]?.number;
2347
- if (!phoneNumber) {
2348
- console.error('No phone number found for contact');
2349
- return;
2350
- }
2351
- try {
2352
- // Put current call on hold
2353
- if (this.call) {
2354
- this.heldCall = this.call;
2355
- this.isCallOnHold = true;
2356
- this.heldCall.mute(true);
2357
- console.log('Current call put on hold');
2358
- }
2359
- // Close contacts panel
2360
- this.showContactsPanel = false;
2361
- // Prepare new call data
2362
- const newCallData = {
2363
- phone: phoneNumber,
2364
- from: this.callData.from,
2365
- extNum: this.callData.extNum,
2366
- name: `${contact.firstName} ${contact.middleName || ''} ${contact.lastName || ''}`.trim(),
2367
- img: contact.img || 'assets/images/user.jpg',
2368
- displayNum: phoneNumber
2369
- };
2370
- // Initiate new call
2371
- this.showRingAnimation = true;
2372
- const payload = {
2373
- channelId: environment.channelId,
2374
- userId: localStorage.getItem('userId'),
2375
- to: phoneNumber,
2376
- scope: 'local',
2377
- fromNumber: this.callData.from
2378
- };
2379
- const response = await this.initiateCall(payload);
2380
- if (response.status == 200) {
2381
- const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2382
- this.getUserInformation(callAuthId);
2383
- this.recordCall = recordCall;
2384
- const tokenData = await this.getOutgoingCallToken(callAuthId);
2385
- // Connect to new call
2386
- const options = {
2387
- codecPreferences: ['opus', 'pcmu'],
2388
- closeProtection: true,
2389
- };
2390
- // Reuse existing Device if available; otherwise create and register once
2391
- if (!this.device) {
2392
- this.device = new Device(tokenData.token.value, options);
2393
- await this.device.register();
2394
- }
2395
- else {
2396
- // Update token if Device supports it and token changed/rotated
2397
- try {
2398
- if (this.device.updateToken) {
2399
- await this.device.updateToken(tokenData.token.value);
2400
- }
2401
- }
2402
- catch (e) {
2403
- console.warn('Device updateToken failed, proceeding with existing token', e);
2404
- }
2405
- }
2406
- const newCall = await this.device.connect({
2407
- params: {
2408
- From: this.callData.from,
2409
- To: phoneNumber,
2410
- Env: environment.abb,
2411
- Token: tokenData.token.id,
2412
- Ext: this.callData.extNum
2413
- },
2414
- rtcConstraints: { audio: { deviceId: 'default' } },
2415
- });
2416
- // Set new call as active
2417
- this.call = newCall;
2418
- this.callData = newCallData;
2419
- // Setup event listeners for new call
2420
- this.setupEventListeners();
2421
- // Poll call status
2422
- this.pollCallStatus(callAuthId);
2423
- console.log('New call initiated to:', phoneNumber);
2424
- this.cdr.detectChanges();
2425
- }
2426
- else if (response.status == 201) {
2427
- swal("Error", response.message.join("<br/>"), "error");
2428
- // Restore held call if new call fails
2429
- if (this.heldCall) {
2430
- this.call = this.heldCall;
2431
- this.heldCall = undefined;
2432
- this.isCallOnHold = false;
2433
- this.call.mute(false);
2434
- }
2435
- }
2436
- }
2437
- catch (error) {
2438
- console.error('Error adding participant:', error);
2439
- this.showRingAnimation = false;
2440
- // Restore held call on error
2441
- if (this.heldCall) {
2442
- this.call = this.heldCall;
2443
- this.heldCall = undefined;
2444
- this.isCallOnHold = false;
2445
- this.call.mute(false);
2446
- }
2447
- this.handleError(error);
2448
- }
2449
- }
2341
+ // async callContact(contact: any) {
2342
+ // console.log('Adding contact to call:', contact);
2343
+ // // Check if there's an active call
2344
+ // if (!this.call || this.call.status() !== 'open') {
2345
+ // console.error('No active call to add participant to');
2346
+ // return;
2347
+ // }
2348
+ // // Get the phone number from the contact
2349
+ // const phoneNumber = contact.numbersList && contact.numbersList[0]?.number;
2350
+ // if (!phoneNumber) {
2351
+ // console.error('No phone number found for contact');
2352
+ // return;
2353
+ // }
2354
+ // try {
2355
+ // // Put current call on hold
2356
+ // if (this.call) {
2357
+ // this.heldCall = this.call;
2358
+ // this.isCallOnHold = true;
2359
+ // this.heldCall.mute(true);
2360
+ // console.log('Current call put on hold');
2361
+ // }
2362
+ // // Close contacts panel
2363
+ // this.showContactsPanel = false;
2364
+ // // Prepare new call data
2365
+ // const newCallData = {
2366
+ // phone: phoneNumber,
2367
+ // from: this.callData.from,
2368
+ // extNum: this.callData.extNum,
2369
+ // name: `${contact.firstName} ${contact.middleName || ''} ${contact.lastName || ''}`.trim(),
2370
+ // img: contact.img || 'assets/images/user.jpg',
2371
+ // displayNum: phoneNumber
2372
+ // };
2373
+ // // Initiate new call
2374
+ // this.showRingAnimation = true;
2375
+ // const payload = {
2376
+ // channelId: environment.channelId,
2377
+ // userId: localStorage.getItem('userId'),
2378
+ // to: phoneNumber,
2379
+ // scope: 'local',
2380
+ // fromNumber: this.callData.from
2381
+ // };
2382
+ // const response = await this.initiateCall(payload);
2383
+ // if (response.status == 200) {
2384
+ // const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2385
+ // this.getUserInformation(callAuthId);
2386
+ // this.recordCall = recordCall;
2387
+ // const tokenData: any = await this.getOutgoingCallToken(callAuthId);
2388
+ // // Connect to new call
2389
+ // const options: any = {
2390
+ // codecPreferences: ['opus', 'pcmu'],
2391
+ // closeProtection: true,
2392
+ // };
2393
+ // // Reuse existing Device if available; otherwise create and register once
2394
+ // if (!this.device) {
2395
+ // this.device = new Device(tokenData.token.value, options);
2396
+ // await this.device.register();
2397
+ // } else {
2398
+ // // Update token if Device supports it and token changed/rotated
2399
+ // try {
2400
+ // if ((this.device as any).updateToken) {
2401
+ // await (this.device as any).updateToken(tokenData.token.value);
2402
+ // }
2403
+ // } catch (e) {
2404
+ // console.warn('Device updateToken failed, proceeding with existing token', e);
2405
+ // }
2406
+ // }
2407
+ // const newCall = await this.device.connect({
2408
+ // params: {
2409
+ // From: this.callData.from,
2410
+ // To: phoneNumber,
2411
+ // Env: environment.abb,
2412
+ // Token: tokenData.token.id,
2413
+ // Ext: this.callData.extNum
2414
+ // },
2415
+ // rtcConstraints: { audio: { deviceId: 'default' } },
2416
+ // });
2417
+ // // Set new call as active
2418
+ // this.call = newCall;
2419
+ // this.callData = newCallData;
2420
+ // // Setup event listeners for new call
2421
+ // this.setupEventListeners();
2422
+ // // Poll call status
2423
+ // this.pollCallStatus(callAuthId);
2424
+ // console.log('New call initiated to:', phoneNumber);
2425
+ // this.cdr.detectChanges();
2426
+ // } else if (response.status == 201) {
2427
+ // swal("Error", response.message.join("<br/>"), "error");
2428
+ // // Restore held call if new call fails
2429
+ // if (this.heldCall) {
2430
+ // this.call = this.heldCall;
2431
+ // this.heldCall = undefined;
2432
+ // this.isCallOnHold = false;
2433
+ // this.call.mute(false);
2434
+ // }
2435
+ // }
2436
+ // } catch (error) {
2437
+ // console.error('Error adding participant:', error);
2438
+ // this.showRingAnimation = false;
2439
+ // // Restore held call on error
2440
+ // if (this.heldCall) {
2441
+ // this.call = this.heldCall;
2442
+ // this.heldCall = undefined;
2443
+ // this.isCallOnHold = false;
2444
+ // this.call.mute(false);
2445
+ // }
2446
+ // this.handleError(error);
2447
+ // }
2448
+ // }
2450
2449
  // acceptConcurrentCall(incomingCall: any) {
2451
2450
  // if (!incomingCall) return;
2452
2451
  // // Put current call on hold instead of disconnecting
@@ -2469,6 +2468,57 @@ class CallProgressComponent {
2469
2468
  // this.startTimer();
2470
2469
  // this.cdr.detectChanges();
2471
2470
  // }
2471
+ async callContact(contact) {
2472
+ console.log("Adding participant:", contact);
2473
+ if (!this.call || this.call.status() !== 'open') {
2474
+ console.error('No active call');
2475
+ return;
2476
+ }
2477
+ const phoneNumber = contact?.numbersList?.[0]?.number;
2478
+ if (!phoneNumber) {
2479
+ console.error("No phone number found");
2480
+ return;
2481
+ }
2482
+ try {
2483
+ // ---- HOLD CURRENT CALL ----
2484
+ this.heldCall = this.call;
2485
+ this.isCallOnHold = true;
2486
+ this.heldCall.mute(true);
2487
+ this.showContactsPanel = false;
2488
+ this.showRingAnimation = true;
2489
+ if (!this.conferenceId) {
2490
+ console.error("No conferenceId found for active call");
2491
+ swal("Error", "Cannot add participant: conference not found", "error");
2492
+ this.showRingAnimation = false;
2493
+ return;
2494
+ }
2495
+ // ---- BUILD PAYLOAD ----
2496
+ setTimeout(async () => {
2497
+ await this.addParticipantToCall({
2498
+ from: this.callData?.from,
2499
+ route: "OUTGOING",
2500
+ participantNumber: this.callData?.phone,
2501
+ conferenceId: this.conferenceId
2502
+ });
2503
+ }, 1000);
2504
+ console.log("API Response:", this.conferenceId);
2505
+ this.showRingAnimation = false;
2506
+ swal("Success", "Participant is being added to your call", "success");
2507
+ // UI enters conference mode
2508
+ this.isConference = true;
2509
+ }
2510
+ catch (err) {
2511
+ console.error("Error adding participant:", err);
2512
+ swal("Error", "Failed to add participant", "error");
2513
+ this.showRingAnimation = false;
2514
+ if (this.heldCall) {
2515
+ this.call = this.heldCall;
2516
+ this.heldCall = undefined;
2517
+ this.call.mute(false);
2518
+ this.isCallOnHold = false;
2519
+ }
2520
+ }
2521
+ }
2472
2522
  acceptConcurrentCall(incomingCall) {
2473
2523
  if (!incomingCall)
2474
2524
  return;