@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.
@@ -2102,6 +2102,7 @@ class CallProgressComponent {
2102
2102
  });
2103
2103
  }
2104
2104
  startCall(callData) {
2105
+ var _a;
2105
2106
  return __awaiter(this, void 0, void 0, function* () {
2106
2107
  console.log(callData, 'callData');
2107
2108
  try {
@@ -2114,6 +2115,7 @@ class CallProgressComponent {
2114
2115
  scope: 'local',
2115
2116
  };
2116
2117
  const response = yield this.initiateCall(payload);
2118
+ this.conferenceId = (_a = response === null || response === void 0 ? void 0 : response.callauth) === null || _a === void 0 ? void 0 : _a.id;
2117
2119
  if (response.status == 200) {
2118
2120
  const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2119
2121
  this.getUserInformation(callAuthId);
@@ -2122,12 +2124,12 @@ class CallProgressComponent {
2122
2124
  yield this.connectToDevice(tokenData.token, callData);
2123
2125
  yield this.pollCallStatus(callAuthId);
2124
2126
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
2125
- var _a;
2127
+ var _b;
2126
2128
  yield this.addParticipantToCall({
2127
2129
  from: callData === null || callData === void 0 ? void 0 : callData.from,
2128
2130
  route: "OUTGOING",
2129
2131
  participantNumber: callData === null || callData === void 0 ? void 0 : callData.phone,
2130
- conferenceId: (_a = response === null || response === void 0 ? void 0 : response.callauth) === null || _a === void 0 ? void 0 : _a.id
2132
+ conferenceId: (_b = response === null || response === void 0 ? void 0 : response.callauth) === null || _b === void 0 ? void 0 : _b.id
2131
2133
  });
2132
2134
  }), 1000);
2133
2135
  // Poll the status for 30-45 seconds
@@ -2358,121 +2360,114 @@ class CallProgressComponent {
2358
2360
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2359
2361
  this.GetContactsList();
2360
2362
  }
2361
- callContact(contact) {
2362
- var _a;
2363
- return __awaiter(this, void 0, void 0, function* () {
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 && ((_a = contact.numbersList[0]) === null || _a === void 0 ? void 0 : _a.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 = yield this.initiateCall(payload);
2405
- if (response.status == 200) {
2406
- const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2407
- this.getUserInformation(callAuthId);
2408
- this.recordCall = recordCall;
2409
- const tokenData = yield this.getOutgoingCallToken(callAuthId);
2410
- // Connect to new call
2411
- const options = {
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
- yield this.device.register();
2419
- }
2420
- else {
2421
- // Update token if Device supports it and token changed/rotated
2422
- try {
2423
- if (this.device.updateToken) {
2424
- yield this.device.updateToken(tokenData.token.value);
2425
- }
2426
- }
2427
- catch (e) {
2428
- console.warn('Device updateToken failed, proceeding with existing token', e);
2429
- }
2430
- }
2431
- const newCall = yield this.device.connect({
2432
- params: {
2433
- From: this.callData.from,
2434
- To: phoneNumber,
2435
- Env: environment.abb,
2436
- Token: tokenData.token.id,
2437
- Ext: this.callData.extNum
2438
- },
2439
- rtcConstraints: { audio: { deviceId: 'default' } },
2440
- });
2441
- // Set new call as active
2442
- this.call = newCall;
2443
- this.callData = newCallData;
2444
- // Setup event listeners for new call
2445
- this.setupEventListeners();
2446
- // Poll call status
2447
- this.pollCallStatus(callAuthId);
2448
- console.log('New call initiated to:', phoneNumber);
2449
- this.cdr.detectChanges();
2450
- }
2451
- else if (response.status == 201) {
2452
- swal("Error", response.message.join("<br/>"), "error");
2453
- // Restore held call if new call fails
2454
- if (this.heldCall) {
2455
- this.call = this.heldCall;
2456
- this.heldCall = undefined;
2457
- this.isCallOnHold = false;
2458
- this.call.mute(false);
2459
- }
2460
- }
2461
- }
2462
- catch (error) {
2463
- console.error('Error adding participant:', error);
2464
- this.showRingAnimation = false;
2465
- // Restore held call on error
2466
- if (this.heldCall) {
2467
- this.call = this.heldCall;
2468
- this.heldCall = undefined;
2469
- this.isCallOnHold = false;
2470
- this.call.mute(false);
2471
- }
2472
- this.handleError(error);
2473
- }
2474
- });
2475
- }
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
+ // }
2476
2471
  // acceptConcurrentCall(incomingCall: any) {
2477
2472
  // if (!incomingCall) return;
2478
2473
  // // Put current call on hold instead of disconnecting
@@ -2495,6 +2490,61 @@ class CallProgressComponent {
2495
2490
  // this.startTimer();
2496
2491
  // this.cdr.detectChanges();
2497
2492
  // }
2493
+ callContact(contact) {
2494
+ var _a, _b;
2495
+ return __awaiter(this, void 0, void 0, function* () {
2496
+ console.log("Adding participant:", contact);
2497
+ if (!this.call || this.call.status() !== 'open') {
2498
+ console.error('No active call');
2499
+ return;
2500
+ }
2501
+ 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;
2502
+ if (!phoneNumber) {
2503
+ console.error("No phone number found");
2504
+ return;
2505
+ }
2506
+ try {
2507
+ // ---- HOLD CURRENT CALL ----
2508
+ this.heldCall = this.call;
2509
+ this.isCallOnHold = true;
2510
+ this.heldCall.mute(true);
2511
+ this.showContactsPanel = false;
2512
+ this.showRingAnimation = true;
2513
+ if (!this.conferenceId) {
2514
+ console.error("No conferenceId found for active call");
2515
+ swal("Error", "Cannot add participant: conference not found", "error");
2516
+ this.showRingAnimation = false;
2517
+ return;
2518
+ }
2519
+ // ---- BUILD PAYLOAD ----
2520
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
2521
+ var _c, _d;
2522
+ yield this.addParticipantToCall({
2523
+ from: (_c = this.callData) === null || _c === void 0 ? void 0 : _c.from,
2524
+ route: "OUTGOING",
2525
+ participantNumber: (_d = this.callData) === null || _d === void 0 ? void 0 : _d.phone,
2526
+ conferenceId: this.conferenceId
2527
+ });
2528
+ }), 1000);
2529
+ console.log("API Response:", this.conferenceId);
2530
+ this.showRingAnimation = false;
2531
+ swal("Success", "Participant is being added to your call", "success");
2532
+ // UI enters conference mode
2533
+ this.isConference = true;
2534
+ }
2535
+ catch (err) {
2536
+ console.error("Error adding participant:", err);
2537
+ swal("Error", "Failed to add participant", "error");
2538
+ this.showRingAnimation = false;
2539
+ if (this.heldCall) {
2540
+ this.call = this.heldCall;
2541
+ this.heldCall = undefined;
2542
+ this.call.mute(false);
2543
+ this.isCallOnHold = false;
2544
+ }
2545
+ }
2546
+ });
2547
+ }
2498
2548
  acceptConcurrentCall(incomingCall) {
2499
2549
  var _a, _b;
2500
2550
  if (!incomingCall)