@vgroup/dialbox 0.2.61 → 0.2.62

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.
@@ -2469,9 +2469,10 @@ class CallProgressComponent {
2469
2469
  // this.cdr.detectChanges();
2470
2470
  // }
2471
2471
  async callContact(contact) {
2472
- console.log("Adding participant:", contact);
2473
- if (!this.call || this.call.status() !== 'open') {
2474
- console.error('No active call');
2472
+ console.log("Starting second call:", contact);
2473
+ // Must have active Call A
2474
+ if (!this.call || this.call.status() !== "open") {
2475
+ console.error("No active call to start second call");
2475
2476
  return;
2476
2477
  }
2477
2478
  const phoneNumber = contact?.numbersList?.[0]?.number;
@@ -2480,45 +2481,86 @@ class CallProgressComponent {
2480
2481
  return;
2481
2482
  }
2482
2483
  try {
2483
- // ---- HOLD CURRENT CALL ----
2484
+ // ---- HOLD CALL A ----
2484
2485
  this.heldCall = this.call;
2485
2486
  this.isCallOnHold = true;
2486
2487
  this.heldCall.mute(true);
2488
+ console.log("Call A placed on hold");
2487
2489
  this.showContactsPanel = false;
2488
2490
  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);
2491
+ // ---- START CALL B ----
2492
+ await this.startSecondOutboundCall(phoneNumber, contact);
2505
2493
  this.showRingAnimation = false;
2506
- swal("Success", "Participant is being added to your call", "success");
2507
- // UI enters conference mode
2508
- this.isConference = true;
2494
+ console.log("Second call started successfully");
2509
2495
  }
2510
2496
  catch (err) {
2511
- console.error("Error adding participant:", err);
2512
- swal("Error", "Failed to add participant", "error");
2513
- this.showRingAnimation = false;
2497
+ console.error("Error starting second call:", err);
2498
+ // Restore call A
2514
2499
  if (this.heldCall) {
2515
2500
  this.call = this.heldCall;
2516
2501
  this.heldCall = undefined;
2517
- this.call.mute(false);
2518
2502
  this.isCallOnHold = false;
2503
+ this.call.mute(false);
2519
2504
  }
2505
+ this.showRingAnimation = false;
2506
+ swal("Error", "Failed to start second call", "error");
2520
2507
  }
2521
2508
  }
2509
+ async startSecondOutboundCall(phoneNumber, contact) {
2510
+ console.log("Dialing second call to", phoneNumber);
2511
+ // 1️⃣ Prepare data for new call
2512
+ const payload = {
2513
+ channelId: environment.channelId,
2514
+ userId: localStorage.getItem("userId"),
2515
+ to: phoneNumber,
2516
+ scope: "local",
2517
+ fromNumber: this.callData.from
2518
+ };
2519
+ const response = await this.initiateCall(payload);
2520
+ if (response.status !== 200) {
2521
+ throw new Error("Backend failed to initiate call");
2522
+ }
2523
+ const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2524
+ this.recordCall = recordCall;
2525
+ const tokenData = await this.getOutgoingCallToken(callAuthId);
2526
+ // 2️⃣ Setup Twilio Device (same as your current code)
2527
+ const options = {
2528
+ codecPreferences: ["opus", "pcmu"],
2529
+ closeProtection: true,
2530
+ };
2531
+ if (!this.device) {
2532
+ this.device = new Device(tokenData.token.value, options);
2533
+ await this.device.register();
2534
+ }
2535
+ else if (this.device.updateToken) {
2536
+ await this.device.updateToken(tokenData.token.value);
2537
+ }
2538
+ // 3️⃣ Start NEW CALL B
2539
+ const newCall = await this.device.connect({
2540
+ params: {
2541
+ From: this.callData.from,
2542
+ To: phoneNumber,
2543
+ Env: environment.abb,
2544
+ Token: tokenData.token.id,
2545
+ Ext: this.callData.extNum
2546
+ },
2547
+ rtcConstraints: { audio: { deviceId: "default" } }
2548
+ });
2549
+ // 4️⃣ Set new call B as active call
2550
+ this.call = newCall;
2551
+ // Update call data UI
2552
+ this.callData = {
2553
+ phone: phoneNumber,
2554
+ from: this.callData.from,
2555
+ extNum: this.callData.extNum,
2556
+ name: `${contact.firstName} ${contact.middleName || ""} ${contact.lastName || ""}`.trim(),
2557
+ img: contact.img || "assets/images/user.jpg",
2558
+ displayNum: phoneNumber
2559
+ };
2560
+ this.setupEventListeners();
2561
+ this.pollCallStatus(callAuthId);
2562
+ console.log("Call B is now active");
2563
+ }
2522
2564
  acceptConcurrentCall(incomingCall) {
2523
2565
  if (!incomingCall)
2524
2566
  return;
@@ -2576,14 +2618,43 @@ class CallProgressComponent {
2576
2618
  console.log('Updated callData:', this.callData);
2577
2619
  this.cdr.detectChanges();
2578
2620
  }
2579
- mergeCalls() {
2580
- // Merge functionality - unmute both calls for conference
2581
- if (this.heldCall && this.call) {
2582
- this.heldCall.mute(false);
2583
- this.call.mute(false);
2584
- this.isCallOnHold = false;
2621
+ // mergeCalls() {
2622
+ // // Merge functionality - unmute both calls for conference
2623
+ // if (this.heldCall && this.call) {
2624
+ // this.heldCall.mute(false);
2625
+ // this.call.mute(false);
2626
+ // this.isCallOnHold = false;
2627
+ // this.isConference = true;
2628
+ // this.cdr.detectChanges();
2629
+ // }
2630
+ // }
2631
+ async mergeCalls() {
2632
+ if (!this.conferenceId) {
2633
+ swal("Error", "Unable to merge: conference ID missing", "error");
2634
+ return;
2635
+ }
2636
+ if (!this.callData?.phone) {
2637
+ swal("Error", "Second call number is missing", "error");
2638
+ return;
2639
+ }
2640
+ try {
2641
+ this.showRingAnimation = true;
2642
+ const payload = {
2643
+ from: this.callData.from,
2644
+ route: "OUTGOING",
2645
+ participantNumber: this.callData.phone,
2646
+ conferenceId: this.conferenceId
2647
+ };
2648
+ console.log("Calling addParticipant API:", payload);
2649
+ await this.addParticipantToCall(payload);
2650
+ this.showRingAnimation = false;
2585
2651
  this.isConference = true;
2586
- this.cdr.detectChanges();
2652
+ swal("Success", "Calls have been merged", "success");
2653
+ }
2654
+ catch (error) {
2655
+ console.error("Merge failed:", error);
2656
+ this.showRingAnimation = false;
2657
+ swal("Error", "Failed to merge calls", "error");
2587
2658
  }
2588
2659
  }
2589
2660
  endHeldCall() {