@vgroup/dialbox 0.2.60 → 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,6 +2110,7 @@ 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);
@@ -2337,118 +2338,114 @@ class CallProgressComponent {
2337
2338
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2338
2339
  this.GetContactsList();
2339
2340
  }
2340
- async callContact(contact) {
2341
- console.log('Adding contact to call:', contact);
2342
- // Check if there's an active call
2343
- if (!this.call || this.call.status() !== 'open') {
2344
- console.error('No active call to add participant to');
2345
- return;
2346
- }
2347
- // Get the phone number from the contact
2348
- const phoneNumber = contact.numbersList && contact.numbersList[0]?.number;
2349
- if (!phoneNumber) {
2350
- console.error('No phone number found for contact');
2351
- return;
2352
- }
2353
- try {
2354
- // Put current call on hold
2355
- if (this.call) {
2356
- this.heldCall = this.call;
2357
- this.isCallOnHold = true;
2358
- this.heldCall.mute(true);
2359
- console.log('Current call put on hold');
2360
- }
2361
- // Close contacts panel
2362
- this.showContactsPanel = false;
2363
- // Prepare new call data
2364
- const newCallData = {
2365
- phone: phoneNumber,
2366
- from: this.callData.from,
2367
- extNum: this.callData.extNum,
2368
- name: `${contact.firstName} ${contact.middleName || ''} ${contact.lastName || ''}`.trim(),
2369
- img: contact.img || 'assets/images/user.jpg',
2370
- displayNum: phoneNumber
2371
- };
2372
- // Initiate new call
2373
- this.showRingAnimation = true;
2374
- const payload = {
2375
- channelId: environment.channelId,
2376
- userId: localStorage.getItem('userId'),
2377
- to: phoneNumber,
2378
- scope: 'local',
2379
- fromNumber: this.callData.from
2380
- };
2381
- const response = await this.initiateCall(payload);
2382
- if (response.status == 200) {
2383
- const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2384
- this.getUserInformation(callAuthId);
2385
- this.recordCall = recordCall;
2386
- const tokenData = await this.getOutgoingCallToken(callAuthId);
2387
- // Connect to new call
2388
- const options = {
2389
- codecPreferences: ['opus', 'pcmu'],
2390
- closeProtection: true,
2391
- };
2392
- // Reuse existing Device if available; otherwise create and register once
2393
- if (!this.device) {
2394
- this.device = new Device(tokenData.token.value, options);
2395
- await this.device.register();
2396
- }
2397
- else {
2398
- // Update token if Device supports it and token changed/rotated
2399
- try {
2400
- if (this.device.updateToken) {
2401
- await this.device.updateToken(tokenData.token.value);
2402
- }
2403
- }
2404
- catch (e) {
2405
- console.warn('Device updateToken failed, proceeding with existing token', e);
2406
- }
2407
- }
2408
- const newCall = await this.device.connect({
2409
- params: {
2410
- From: this.callData.from,
2411
- To: phoneNumber,
2412
- Env: environment.abb,
2413
- Token: tokenData.token.id,
2414
- Ext: this.callData.extNum
2415
- },
2416
- rtcConstraints: { audio: { deviceId: 'default' } },
2417
- });
2418
- // Set new call as active
2419
- this.call = newCall;
2420
- this.callData = newCallData;
2421
- // Setup event listeners for new call
2422
- this.setupEventListeners();
2423
- // Poll call status
2424
- this.pollCallStatus(callAuthId);
2425
- console.log('New call initiated to:', phoneNumber);
2426
- this.cdr.detectChanges();
2427
- }
2428
- else if (response.status == 201) {
2429
- swal("Error", response.message.join("<br/>"), "error");
2430
- // Restore held call if new call fails
2431
- if (this.heldCall) {
2432
- this.call = this.heldCall;
2433
- this.heldCall = undefined;
2434
- this.isCallOnHold = false;
2435
- this.call.mute(false);
2436
- }
2437
- }
2438
- }
2439
- catch (error) {
2440
- console.error('Error adding participant:', error);
2441
- this.showRingAnimation = false;
2442
- // Restore held call on error
2443
- if (this.heldCall) {
2444
- this.call = this.heldCall;
2445
- this.heldCall = undefined;
2446
- this.isCallOnHold = false;
2447
- this.call.mute(false);
2448
- }
2449
- this.handleError(error);
2450
- }
2451
- }
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
+ // }
2452
2449
  // acceptConcurrentCall(incomingCall: any) {
2453
2450
  // if (!incomingCall) return;
2454
2451
  // // Put current call on hold instead of disconnecting
@@ -2471,6 +2468,57 @@ class CallProgressComponent {
2471
2468
  // this.startTimer();
2472
2469
  // this.cdr.detectChanges();
2473
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
+ }
2474
2522
  acceptConcurrentCall(incomingCall) {
2475
2523
  if (!incomingCall)
2476
2524
  return;