@vgroup/dialbox 0.2.62 → 0.2.65

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.
@@ -2124,12 +2124,11 @@ class CallProgressComponent {
2124
2124
  yield this.connectToDevice(tokenData.token, callData);
2125
2125
  yield this.pollCallStatus(callAuthId);
2126
2126
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
2127
- var _b;
2128
2127
  yield this.addParticipantToCall({
2129
2128
  from: callData === null || callData === void 0 ? void 0 : callData.from,
2130
2129
  route: "OUTGOING",
2131
2130
  participantNumber: callData === null || callData === void 0 ? void 0 : callData.phone,
2132
- conferenceId: (_b = response === null || response === void 0 ? void 0 : response.callauth) === null || _b === void 0 ? void 0 : _b.id
2131
+ conferenceId: this.conferenceId
2133
2132
  });
2134
2133
  }), 1000);
2135
2134
  // Poll the status for 30-45 seconds
@@ -2360,234 +2359,86 @@ class CallProgressComponent {
2360
2359
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2361
2360
  this.GetContactsList();
2362
2361
  }
2363
- // async callContact(contact: any) {
2364
- // console.log('Adding contact to call:', contact);
2365
- // // Check if there's an active call
2366
- // if (!this.call || this.call.status() !== 'open') {
2367
- // console.error('No active call to add participant to');
2368
- // return;
2369
- // }
2370
- // // Get the phone number from the contact
2371
- // const phoneNumber = contact.numbersList && contact.numbersList[0]?.number;
2372
- // if (!phoneNumber) {
2373
- // console.error('No phone number found for contact');
2374
- // return;
2375
- // }
2376
- // try {
2377
- // // Put current call on hold
2378
- // if (this.call) {
2379
- // this.heldCall = this.call;
2380
- // this.isCallOnHold = true;
2381
- // this.heldCall.mute(true);
2382
- // console.log('Current call put on hold');
2383
- // }
2384
- // // Close contacts panel
2385
- // this.showContactsPanel = false;
2386
- // // Prepare new call data
2387
- // const newCallData = {
2388
- // phone: phoneNumber,
2389
- // from: this.callData.from,
2390
- // extNum: this.callData.extNum,
2391
- // name: `${contact.firstName} ${contact.middleName || ''} ${contact.lastName || ''}`.trim(),
2392
- // img: contact.img || 'assets/images/user.jpg',
2393
- // displayNum: phoneNumber
2394
- // };
2395
- // // Initiate new call
2396
- // this.showRingAnimation = true;
2397
- // const payload = {
2398
- // channelId: environment.channelId,
2399
- // userId: localStorage.getItem('userId'),
2400
- // to: phoneNumber,
2401
- // scope: 'local',
2402
- // fromNumber: this.callData.from
2403
- // };
2404
- // const response = await this.initiateCall(payload);
2405
- // if (response.status == 200) {
2406
- // const { id: callAuthId, recordCall } = await this.getCallAuthId(response);
2407
- // this.getUserInformation(callAuthId);
2408
- // this.recordCall = recordCall;
2409
- // const tokenData: any = await this.getOutgoingCallToken(callAuthId);
2410
- // // Connect to new call
2411
- // const options: any = {
2412
- // codecPreferences: ['opus', 'pcmu'],
2413
- // closeProtection: true,
2414
- // };
2415
- // // Reuse existing Device if available; otherwise create and register once
2416
- // if (!this.device) {
2417
- // this.device = new Device(tokenData.token.value, options);
2418
- // await this.device.register();
2419
- // } else {
2420
- // // Update token if Device supports it and token changed/rotated
2421
- // try {
2422
- // if ((this.device as any).updateToken) {
2423
- // await (this.device as any).updateToken(tokenData.token.value);
2424
- // }
2425
- // } catch (e) {
2426
- // console.warn('Device updateToken failed, proceeding with existing token', e);
2427
- // }
2428
- // }
2429
- // const newCall = await this.device.connect({
2430
- // params: {
2431
- // From: this.callData.from,
2432
- // To: phoneNumber,
2433
- // Env: environment.abb,
2434
- // Token: tokenData.token.id,
2435
- // Ext: this.callData.extNum
2436
- // },
2437
- // rtcConstraints: { audio: { deviceId: 'default' } },
2438
- // });
2439
- // // Set new call as active
2440
- // this.call = newCall;
2441
- // this.callData = newCallData;
2442
- // // Setup event listeners for new call
2443
- // this.setupEventListeners();
2444
- // // Poll call status
2445
- // this.pollCallStatus(callAuthId);
2446
- // console.log('New call initiated to:', phoneNumber);
2447
- // this.cdr.detectChanges();
2448
- // } else if (response.status == 201) {
2449
- // swal("Error", response.message.join("<br/>"), "error");
2450
- // // Restore held call if new call fails
2451
- // if (this.heldCall) {
2452
- // this.call = this.heldCall;
2453
- // this.heldCall = undefined;
2454
- // this.isCallOnHold = false;
2455
- // this.call.mute(false);
2456
- // }
2457
- // }
2458
- // } catch (error) {
2459
- // console.error('Error adding participant:', error);
2460
- // this.showRingAnimation = false;
2461
- // // Restore held call on error
2462
- // if (this.heldCall) {
2463
- // this.call = this.heldCall;
2464
- // this.heldCall = undefined;
2465
- // this.isCallOnHold = false;
2466
- // this.call.mute(false);
2467
- // }
2468
- // this.handleError(error);
2469
- // }
2470
- // }
2471
- // acceptConcurrentCall(incomingCall: any) {
2472
- // if (!incomingCall) return;
2473
- // // Put current call on hold instead of disconnecting
2474
- // if (this.call) {
2475
- // this.heldCall = this.call;
2476
- // this.isCallOnHold = true;
2477
- // // Mute the held call
2478
- // this.heldCall.mute(true);
2479
- // }
2480
- // incomingCall.accept();
2481
- // this.call = incomingCall;
2482
- // this.callData.phone = incomingCall.parameters['From'];
2483
- // this.callData.name = incomingCall.customParameters?.get('name') || '-';
2484
- // this.callData.img = incomingCall.customParameters?.get('image') || 'assets/images/user.jpg';
2485
- // this.isConcurrentIncoming = false;
2486
- // this.incomingCallDiv = false;
2487
- // this.disbaleEndCallBtn = false;
2488
- // // Reset timer for new call
2489
- // this.stopTimer();
2490
- // this.startTimer();
2491
- // this.cdr.detectChanges();
2492
- // }
2493
2362
  callContact(contact) {
2494
- var _a, _b;
2363
+ var _a, _b, _c;
2495
2364
  return __awaiter(this, void 0, void 0, function* () {
2496
- console.log("Starting second call:", contact);
2497
- // Must have active Call A
2498
- if (!this.call || this.call.status() !== "open") {
2499
- console.error("No active call to start second call");
2365
+ console.log('Adding participant:', contact);
2366
+ // Check if there's an active call
2367
+ if (!this.call || this.call.status() !== 'open') {
2368
+ console.error('No active call');
2369
+ swal("Error", "No active call found", "error");
2500
2370
  return;
2501
2371
  }
2372
+ // Get the phone number from the contact
2502
2373
  const phoneNumber = (_b = (_a = contact === null || contact === void 0 ? void 0 : contact.numbersList) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.number;
2503
2374
  if (!phoneNumber) {
2504
- console.error("No phone number found");
2375
+ console.error('No phone number found for contact');
2505
2376
  return;
2506
2377
  }
2507
2378
  try {
2508
- // ---- HOLD CALL A ----
2379
+ // Put current call on hold
2509
2380
  this.heldCall = this.call;
2510
2381
  this.isCallOnHold = true;
2511
2382
  this.heldCall.mute(true);
2512
- console.log("Call A placed on hold");
2383
+ // Close contacts panel and show ring animation
2513
2384
  this.showContactsPanel = false;
2514
2385
  this.showRingAnimation = true;
2515
- // ---- START CALL B ----
2516
- yield this.startSecondOutboundCall(phoneNumber, contact);
2386
+ // Get the conference ID from the current call or use the stored one
2387
+ const conferenceId = this.conferenceId;
2388
+ if (!conferenceId) {
2389
+ console.error("No conferenceId found for active call");
2390
+ swal("Error", "Cannot add participant: conference not found", "error");
2391
+ this.showRingAnimation = false;
2392
+ return;
2393
+ }
2394
+ // Add participant to the conference
2395
+ yield this.addParticipantToCall({
2396
+ from: (_c = this.callData) === null || _c === void 0 ? void 0 : _c.from,
2397
+ route: "OUTGOING",
2398
+ participantNumber: phoneNumber,
2399
+ conferenceId: conferenceId
2400
+ });
2401
+ console.log("Participant added to conference:", phoneNumber);
2517
2402
  this.showRingAnimation = false;
2518
- console.log("Second call started successfully");
2403
+ // Show success message
2404
+ swal("Success", "Participant is being added to your call", "success");
2519
2405
  }
2520
- catch (err) {
2521
- console.error("Error starting second call:", err);
2522
- // Restore call A
2406
+ catch (error) {
2407
+ console.error('Error adding participant:', error);
2408
+ this.showRingAnimation = false;
2409
+ // Restore held call on error
2523
2410
  if (this.heldCall) {
2524
2411
  this.call = this.heldCall;
2525
2412
  this.heldCall = undefined;
2526
2413
  this.isCallOnHold = false;
2527
2414
  this.call.mute(false);
2528
2415
  }
2529
- this.showRingAnimation = false;
2530
- swal("Error", "Failed to start second call", "error");
2531
- }
2532
- });
2533
- }
2534
- startSecondOutboundCall(phoneNumber, contact) {
2535
- return __awaiter(this, void 0, void 0, function* () {
2536
- console.log("Dialing second call to", phoneNumber);
2537
- // 1️⃣ Prepare data for new call
2538
- const payload = {
2539
- channelId: environment.channelId,
2540
- userId: localStorage.getItem("userId"),
2541
- to: phoneNumber,
2542
- scope: "local",
2543
- fromNumber: this.callData.from
2544
- };
2545
- const response = yield this.initiateCall(payload);
2546
- if (response.status !== 200) {
2547
- throw new Error("Backend failed to initiate call");
2548
- }
2549
- const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2550
- this.recordCall = recordCall;
2551
- const tokenData = yield this.getOutgoingCallToken(callAuthId);
2552
- // 2️⃣ Setup Twilio Device (same as your current code)
2553
- const options = {
2554
- codecPreferences: ["opus", "pcmu"],
2555
- closeProtection: true,
2556
- };
2557
- if (!this.device) {
2558
- this.device = new Device(tokenData.token.value, options);
2559
- yield this.device.register();
2560
- }
2561
- else if (this.device.updateToken) {
2562
- yield this.device.updateToken(tokenData.token.value);
2416
+ this.handleError(error);
2563
2417
  }
2564
- // 3️⃣ Start NEW CALL B
2565
- const newCall = yield this.device.connect({
2566
- params: {
2567
- From: this.callData.from,
2568
- To: phoneNumber,
2569
- Env: environment.abb,
2570
- Token: tokenData.token.id,
2571
- Ext: this.callData.extNum
2572
- },
2573
- rtcConstraints: { audio: { deviceId: "default" } }
2574
- });
2575
- // 4️⃣ Set new call B as active call
2576
- this.call = newCall;
2577
- // Update call data UI
2578
- this.callData = {
2579
- phone: phoneNumber,
2580
- from: this.callData.from,
2581
- extNum: this.callData.extNum,
2582
- name: `${contact.firstName} ${contact.middleName || ""} ${contact.lastName || ""}`.trim(),
2583
- img: contact.img || "assets/images/user.jpg",
2584
- displayNum: phoneNumber
2585
- };
2586
- this.setupEventListeners();
2587
- this.pollCallStatus(callAuthId);
2588
- console.log("Call B is now active");
2589
2418
  });
2590
2419
  }
2420
+ // acceptConcurrentCall(incomingCall: any) {
2421
+ // if (!incomingCall) return;
2422
+ // // Put current call on hold instead of disconnecting
2423
+ // if (this.call) {
2424
+ // this.heldCall = this.call;
2425
+ // this.isCallOnHold = true;
2426
+ // // Mute the held call
2427
+ // this.heldCall.mute(true);
2428
+ // }
2429
+ // incomingCall.accept();
2430
+ // this.call = incomingCall;
2431
+ // this.callData.phone = incomingCall.parameters['From'];
2432
+ // this.callData.name = incomingCall.customParameters?.get('name') || '-';
2433
+ // this.callData.img = incomingCall.customParameters?.get('image') || 'assets/images/user.jpg';
2434
+ // this.isConcurrentIncoming = false;
2435
+ // this.incomingCallDiv = false;
2436
+ // this.disbaleEndCallBtn = false;
2437
+ // // Reset timer for new call
2438
+ // this.stopTimer();
2439
+ // this.startTimer();
2440
+ // this.cdr.detectChanges();
2441
+ // }
2591
2442
  acceptConcurrentCall(incomingCall) {
2592
2443
  var _a, _b;
2593
2444
  if (!incomingCall)
@@ -2641,47 +2492,15 @@ class CallProgressComponent {
2641
2492
  console.log('Updated callData:', this.callData);
2642
2493
  this.cdr.detectChanges();
2643
2494
  }
2644
- // mergeCalls() {
2645
- // // Merge functionality - unmute both calls for conference
2646
- // if (this.heldCall && this.call) {
2647
- // this.heldCall.mute(false);
2648
- // this.call.mute(false);
2649
- // this.isCallOnHold = false;
2650
- // this.isConference = true;
2651
- // this.cdr.detectChanges();
2652
- // }
2653
- // }
2654
2495
  mergeCalls() {
2655
- var _a;
2656
- return __awaiter(this, void 0, void 0, function* () {
2657
- if (!this.conferenceId) {
2658
- swal("Error", "Unable to merge: conference ID missing", "error");
2659
- return;
2660
- }
2661
- if (!((_a = this.callData) === null || _a === void 0 ? void 0 : _a.phone)) {
2662
- swal("Error", "Second call number is missing", "error");
2663
- return;
2664
- }
2665
- try {
2666
- this.showRingAnimation = true;
2667
- const payload = {
2668
- from: this.callData.from,
2669
- route: "OUTGOING",
2670
- participantNumber: this.callData.phone,
2671
- conferenceId: this.conferenceId
2672
- };
2673
- console.log("Calling addParticipant API:", payload);
2674
- yield this.addParticipantToCall(payload);
2675
- this.showRingAnimation = false;
2676
- this.isConference = true;
2677
- swal("Success", "Calls have been merged", "success");
2678
- }
2679
- catch (error) {
2680
- console.error("Merge failed:", error);
2681
- this.showRingAnimation = false;
2682
- swal("Error", "Failed to merge calls", "error");
2683
- }
2684
- });
2496
+ // Merge functionality - unmute both calls for conference
2497
+ if (this.heldCall && this.call) {
2498
+ this.heldCall.mute(false);
2499
+ this.call.mute(false);
2500
+ this.isCallOnHold = false;
2501
+ this.isConference = true;
2502
+ this.cdr.detectChanges();
2503
+ }
2685
2504
  }
2686
2505
  endHeldCall() {
2687
2506
  if (this.heldCall) {