@vgroup/dialbox 0.2.59 → 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.
@@ -2115,19 +2115,23 @@ class CallProgressComponent {
2115
2115
  scope: 'local',
2116
2116
  };
2117
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;
2118
2119
  if (response.status == 200) {
2119
2120
  const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2120
2121
  this.getUserInformation(callAuthId);
2121
2122
  this.recordCall = recordCall; // Store the recordCall value
2122
2123
  const tokenData = yield this.getOutgoingCallToken(callAuthId);
2123
2124
  yield this.connectToDevice(tokenData.token, callData);
2124
- this.pollCallStatus(callAuthId);
2125
- yield this.addParticipantToCall({
2126
- from: callData === null || callData === void 0 ? void 0 : callData.from,
2127
- route: "OUTGOING",
2128
- participantNumber: callData === null || callData === void 0 ? void 0 : callData.phone,
2129
- conferenceId: (_a = response === null || response === void 0 ? void 0 : response.callauth) === null || _a === void 0 ? void 0 : _a.id
2130
- });
2125
+ yield this.pollCallStatus(callAuthId);
2126
+ setTimeout(() => __awaiter(this, void 0, void 0, function* () {
2127
+ var _b;
2128
+ yield this.addParticipantToCall({
2129
+ from: callData === null || callData === void 0 ? void 0 : callData.from,
2130
+ route: "OUTGOING",
2131
+ 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
2133
+ });
2134
+ }), 1000);
2131
2135
  // Poll the status for 30-45 seconds
2132
2136
  }
2133
2137
  else if (response.status == 201) {
@@ -2356,121 +2360,114 @@ class CallProgressComponent {
2356
2360
  this.isAddRemoveParticipant = !this.isAddRemoveParticipant;
2357
2361
  this.GetContactsList();
2358
2362
  }
2359
- callContact(contact) {
2360
- var _a;
2361
- return __awaiter(this, void 0, void 0, function* () {
2362
- console.log('Adding contact to call:', contact);
2363
- // Check if there's an active call
2364
- if (!this.call || this.call.status() !== 'open') {
2365
- console.error('No active call to add participant to');
2366
- return;
2367
- }
2368
- // Get the phone number from the contact
2369
- const phoneNumber = contact.numbersList && ((_a = contact.numbersList[0]) === null || _a === void 0 ? void 0 : _a.number);
2370
- if (!phoneNumber) {
2371
- console.error('No phone number found for contact');
2372
- return;
2373
- }
2374
- try {
2375
- // Put current call on hold
2376
- if (this.call) {
2377
- this.heldCall = this.call;
2378
- this.isCallOnHold = true;
2379
- this.heldCall.mute(true);
2380
- console.log('Current call put on hold');
2381
- }
2382
- // Close contacts panel
2383
- this.showContactsPanel = false;
2384
- // Prepare new call data
2385
- const newCallData = {
2386
- phone: phoneNumber,
2387
- from: this.callData.from,
2388
- extNum: this.callData.extNum,
2389
- name: `${contact.firstName} ${contact.middleName || ''} ${contact.lastName || ''}`.trim(),
2390
- img: contact.img || 'assets/images/user.jpg',
2391
- displayNum: phoneNumber
2392
- };
2393
- // Initiate new call
2394
- this.showRingAnimation = true;
2395
- const payload = {
2396
- channelId: environment.channelId,
2397
- userId: localStorage.getItem('userId'),
2398
- to: phoneNumber,
2399
- scope: 'local',
2400
- fromNumber: this.callData.from
2401
- };
2402
- const response = yield this.initiateCall(payload);
2403
- if (response.status == 200) {
2404
- const { id: callAuthId, recordCall } = yield this.getCallAuthId(response);
2405
- this.getUserInformation(callAuthId);
2406
- this.recordCall = recordCall;
2407
- const tokenData = yield this.getOutgoingCallToken(callAuthId);
2408
- // Connect to new call
2409
- const options = {
2410
- codecPreferences: ['opus', 'pcmu'],
2411
- closeProtection: true,
2412
- };
2413
- // Reuse existing Device if available; otherwise create and register once
2414
- if (!this.device) {
2415
- this.device = new Device(tokenData.token.value, options);
2416
- yield this.device.register();
2417
- }
2418
- else {
2419
- // Update token if Device supports it and token changed/rotated
2420
- try {
2421
- if (this.device.updateToken) {
2422
- yield this.device.updateToken(tokenData.token.value);
2423
- }
2424
- }
2425
- catch (e) {
2426
- console.warn('Device updateToken failed, proceeding with existing token', e);
2427
- }
2428
- }
2429
- const newCall = yield 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
- }
2449
- else if (response.status == 201) {
2450
- swal("Error", response.message.join("<br/>"), "error");
2451
- // Restore held call if new call fails
2452
- if (this.heldCall) {
2453
- this.call = this.heldCall;
2454
- this.heldCall = undefined;
2455
- this.isCallOnHold = false;
2456
- this.call.mute(false);
2457
- }
2458
- }
2459
- }
2460
- catch (error) {
2461
- console.error('Error adding participant:', error);
2462
- this.showRingAnimation = false;
2463
- // Restore held call on error
2464
- if (this.heldCall) {
2465
- this.call = this.heldCall;
2466
- this.heldCall = undefined;
2467
- this.isCallOnHold = false;
2468
- this.call.mute(false);
2469
- }
2470
- this.handleError(error);
2471
- }
2472
- });
2473
- }
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
+ // }
2474
2471
  // acceptConcurrentCall(incomingCall: any) {
2475
2472
  // if (!incomingCall) return;
2476
2473
  // // Put current call on hold instead of disconnecting
@@ -2493,6 +2490,61 @@ class CallProgressComponent {
2493
2490
  // this.startTimer();
2494
2491
  // this.cdr.detectChanges();
2495
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
+ }
2496
2548
  acceptConcurrentCall(incomingCall) {
2497
2549
  var _a, _b;
2498
2550
  if (!incomingCall)