@vgroup/dialbox 0.2.62 → 0.2.63

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.
@@ -2123,7 +2123,7 @@ class CallProgressComponent {
2123
2123
  from: callData?.from,
2124
2124
  route: "OUTGOING",
2125
2125
  participantNumber: callData?.phone,
2126
- conferenceId: response?.callauth?.id
2126
+ conferenceId: this.conferenceId
2127
2127
  });
2128
2128
  }, 1000);
2129
2129
  // Poll the status for 30-45 seconds
@@ -2338,229 +2338,85 @@ class CallProgressComponent {
2338
2338
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2339
2339
  this.GetContactsList();
2340
2340
  }
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
- // }
2449
- // acceptConcurrentCall(incomingCall: any) {
2450
- // if (!incomingCall) return;
2451
- // // Put current call on hold instead of disconnecting
2452
- // if (this.call) {
2453
- // this.heldCall = this.call;
2454
- // this.isCallOnHold = true;
2455
- // // Mute the held call
2456
- // this.heldCall.mute(true);
2457
- // }
2458
- // incomingCall.accept();
2459
- // this.call = incomingCall;
2460
- // this.callData.phone = incomingCall.parameters['From'];
2461
- // this.callData.name = incomingCall.customParameters?.get('name') || '-';
2462
- // this.callData.img = incomingCall.customParameters?.get('image') || 'assets/images/user.jpg';
2463
- // this.isConcurrentIncoming = false;
2464
- // this.incomingCallDiv = false;
2465
- // this.disbaleEndCallBtn = false;
2466
- // // Reset timer for new call
2467
- // this.stopTimer();
2468
- // this.startTimer();
2469
- // this.cdr.detectChanges();
2470
- // }
2471
2341
  async callContact(contact) {
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");
2342
+ console.log('Adding participant:', contact);
2343
+ // Check if there's an active call
2344
+ if (!this.call || this.call.status() !== 'open') {
2345
+ console.error('No active call');
2346
+ swal("Error", "No active call found", "error");
2476
2347
  return;
2477
2348
  }
2349
+ // Get the phone number from the contact
2478
2350
  const phoneNumber = contact?.numbersList?.[0]?.number;
2479
2351
  if (!phoneNumber) {
2480
- console.error("No phone number found");
2352
+ console.error('No phone number found for contact');
2481
2353
  return;
2482
2354
  }
2483
2355
  try {
2484
- // ---- HOLD CALL A ----
2356
+ // Put current call on hold
2485
2357
  this.heldCall = this.call;
2486
2358
  this.isCallOnHold = true;
2487
2359
  this.heldCall.mute(true);
2488
- console.log("Call A placed on hold");
2360
+ // Close contacts panel and show ring animation
2489
2361
  this.showContactsPanel = false;
2490
2362
  this.showRingAnimation = true;
2491
- // ---- START CALL B ----
2492
- await this.startSecondOutboundCall(phoneNumber, contact);
2363
+ // Get the conference ID from the current call or use the stored one
2364
+ const conferenceId = this.conferenceId;
2365
+ if (!conferenceId) {
2366
+ console.error("No conferenceId found for active call");
2367
+ swal("Error", "Cannot add participant: conference not found", "error");
2368
+ this.showRingAnimation = false;
2369
+ return;
2370
+ }
2371
+ // Add participant to the conference
2372
+ await this.addParticipantToCall({
2373
+ from: this.callData?.from,
2374
+ route: "OUTGOING",
2375
+ participantNumber: phoneNumber,
2376
+ conferenceId: conferenceId
2377
+ });
2378
+ console.log("Participant added to conference:", phoneNumber);
2493
2379
  this.showRingAnimation = false;
2494
- console.log("Second call started successfully");
2380
+ // Update UI to show conference mode
2381
+ this.isConference = true;
2382
+ // Show success message
2383
+ swal("Success", "Participant is being added to your call", "success");
2495
2384
  }
2496
- catch (err) {
2497
- console.error("Error starting second call:", err);
2498
- // Restore call A
2385
+ catch (error) {
2386
+ console.error('Error adding participant:', error);
2387
+ this.showRingAnimation = false;
2388
+ // Restore held call on error
2499
2389
  if (this.heldCall) {
2500
2390
  this.call = this.heldCall;
2501
2391
  this.heldCall = undefined;
2502
2392
  this.isCallOnHold = false;
2503
2393
  this.call.mute(false);
2504
2394
  }
2505
- this.showRingAnimation = false;
2506
- swal("Error", "Failed to start second call", "error");
2507
- }
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);
2395
+ this.handleError(error);
2537
2396
  }
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
2397
  }
2398
+ // acceptConcurrentCall(incomingCall: any) {
2399
+ // if (!incomingCall) return;
2400
+ // // Put current call on hold instead of disconnecting
2401
+ // if (this.call) {
2402
+ // this.heldCall = this.call;
2403
+ // this.isCallOnHold = true;
2404
+ // // Mute the held call
2405
+ // this.heldCall.mute(true);
2406
+ // }
2407
+ // incomingCall.accept();
2408
+ // this.call = incomingCall;
2409
+ // this.callData.phone = incomingCall.parameters['From'];
2410
+ // this.callData.name = incomingCall.customParameters?.get('name') || '-';
2411
+ // this.callData.img = incomingCall.customParameters?.get('image') || 'assets/images/user.jpg';
2412
+ // this.isConcurrentIncoming = false;
2413
+ // this.incomingCallDiv = false;
2414
+ // this.disbaleEndCallBtn = false;
2415
+ // // Reset timer for new call
2416
+ // this.stopTimer();
2417
+ // this.startTimer();
2418
+ // this.cdr.detectChanges();
2419
+ // }
2564
2420
  acceptConcurrentCall(incomingCall) {
2565
2421
  if (!incomingCall)
2566
2422
  return;
@@ -2618,43 +2474,14 @@ class CallProgressComponent {
2618
2474
  console.log('Updated callData:', this.callData);
2619
2475
  this.cdr.detectChanges();
2620
2476
  }
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;
2477
+ mergeCalls() {
2478
+ // Merge functionality - unmute both calls for conference
2479
+ if (this.heldCall && this.call) {
2480
+ this.heldCall.mute(false);
2481
+ this.call.mute(false);
2482
+ this.isCallOnHold = false;
2651
2483
  this.isConference = true;
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");
2484
+ this.cdr.detectChanges();
2658
2485
  }
2659
2486
  }
2660
2487
  endHeldCall() {