@vgroup/dialbox 0.0.80 → 0.0.81
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.
- package/esm2020/lib/dialbox.component.mjs +13 -88
- package/esm2020/lib/service/twilio.service.mjs +41 -112
- package/fesm2015/vgroup-dialbox.mjs +51 -190
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +51 -197
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/dialbox.component.d.ts +0 -1
- package/lib/service/twilio.service.d.ts +4 -26
- package/package.json +1 -1
|
@@ -1366,14 +1366,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
1366
1366
|
}], ctorParameters: function () { return [{ type: TwilioService }]; } });
|
|
1367
1367
|
|
|
1368
1368
|
class TwilioService {
|
|
1369
|
-
constructor(http, extensionService,
|
|
1369
|
+
constructor(http, extensionService, notificationSerivce) {
|
|
1370
1370
|
this.http = http;
|
|
1371
1371
|
this.extensionService = extensionService;
|
|
1372
|
-
this.
|
|
1372
|
+
this.notificationSerivce = notificationSerivce;
|
|
1373
1373
|
this.openInProgressDialpad = new BehaviorSubject(false);
|
|
1374
1374
|
this.currentCall = new BehaviorSubject(null);
|
|
1375
|
-
this.currentCallState = new BehaviorSubject('none'); //
|
|
1376
|
-
this._currentCall = null;
|
|
1375
|
+
this.currentCallState = new BehaviorSubject('none'); //in-progress, out-progress, none
|
|
1377
1376
|
this.callType = new BehaviorSubject('NIL');
|
|
1378
1377
|
this.isIncomingCallPicked = new BehaviorSubject(false); // for both incoming and outgoing
|
|
1379
1378
|
this.token = localStorage.getItem('ext_token');
|
|
@@ -1388,92 +1387,37 @@ class TwilioService {
|
|
|
1388
1387
|
this.isAvailableNumber = new BehaviorSubject(false);
|
|
1389
1388
|
this.callerIdList = new BehaviorSubject([]);
|
|
1390
1389
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
1391
|
-
this.
|
|
1392
|
-
this.autoAnswer = false; // Default to manual answer
|
|
1393
|
-
// Don't initialize here - let the component handle it
|
|
1390
|
+
this.initializeTwilioDevice();
|
|
1394
1391
|
}
|
|
1395
1392
|
initializeTwilioDevice() {
|
|
1396
|
-
|
|
1397
|
-
if (this.device) {
|
|
1398
|
-
console.log('Twilio device already initialized');
|
|
1399
|
-
resolve();
|
|
1400
|
-
return;
|
|
1401
|
-
}
|
|
1402
|
-
const token = localStorage.getItem('ext_token');
|
|
1403
|
-
if (!token) {
|
|
1404
|
-
const error = new Error('No authentication token found in localStorage');
|
|
1405
|
-
console.error(error);
|
|
1406
|
-
reject(error);
|
|
1407
|
-
return;
|
|
1408
|
-
}
|
|
1409
|
-
// Store token in a const to ensure TypeScript knows it's not null
|
|
1410
|
-
const authToken = token;
|
|
1393
|
+
if (this.token) {
|
|
1411
1394
|
this.extensionService.getIncomingCallToken().subscribe((data) => {
|
|
1412
|
-
if (!data || !data.token) {
|
|
1413
|
-
const error = 'No token received from getIncomingCallToken';
|
|
1414
|
-
console.error(error);
|
|
1415
|
-
reject(new Error(error));
|
|
1416
|
-
return;
|
|
1417
|
-
}
|
|
1418
1395
|
this.incomingCallToken = data.token;
|
|
1419
1396
|
localStorage.setItem('in-token', data.token);
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
this.
|
|
1427
|
-
this.
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
console.error('
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
});
|
|
1436
|
-
});
|
|
1437
|
-
}
|
|
1438
|
-
setupDevice(device) {
|
|
1439
|
-
device.on('incoming', (call) => {
|
|
1440
|
-
console.log('Incoming call from:', call.parameters['From']);
|
|
1441
|
-
this._currentCall = call;
|
|
1442
|
-
this.currentCall.next(call);
|
|
1443
|
-
this.currentCallState.next('incoming');
|
|
1444
|
-
// Auto-answer if configured
|
|
1445
|
-
if (this.autoAnswer) {
|
|
1446
|
-
console.log('Auto-answering incoming call');
|
|
1447
|
-
// Call accept() without promise chaining since it returns void
|
|
1448
|
-
call.accept();
|
|
1449
|
-
this.currentCallState.next('in-progress');
|
|
1450
|
-
}
|
|
1451
|
-
// Handle call end
|
|
1452
|
-
call.on('disconnect', () => {
|
|
1453
|
-
if (this._currentCall && this._currentCall.parameters['CallSid'] === call.parameters['CallSid']) {
|
|
1454
|
-
this._currentCall = null;
|
|
1455
|
-
this.currentCall.next(null);
|
|
1456
|
-
this.currentCallState.next('none');
|
|
1457
|
-
}
|
|
1458
|
-
});
|
|
1459
|
-
// Handle call cancel
|
|
1460
|
-
call.on('cancel', () => {
|
|
1461
|
-
if (this._currentCall && this._currentCall.parameters['CallSid'] === call.parameters['CallSid']) {
|
|
1462
|
-
this._currentCall = null;
|
|
1463
|
-
this.currentCall.next(null);
|
|
1464
|
-
this.currentCallState.next('none');
|
|
1465
|
-
}
|
|
1397
|
+
this.device = new Device(this.incomingCallToken, {
|
|
1398
|
+
allowIncomingWhileBusy: true,
|
|
1399
|
+
// Add any other necessary options
|
|
1400
|
+
});
|
|
1401
|
+
this.device.register();
|
|
1402
|
+
this.device.on('incoming', (call) => {
|
|
1403
|
+
this.currentCall.next(call);
|
|
1404
|
+
this.callType.next('INCOMING');
|
|
1405
|
+
this.currentCallState.next('incoming');
|
|
1406
|
+
this.notificationSerivce.showNotification(call);
|
|
1407
|
+
});
|
|
1408
|
+
this.device.on('error', (error) => {
|
|
1409
|
+
console.error('Twilio Device Error:', error);
|
|
1410
|
+
// Add error handling and reconnection logic
|
|
1411
|
+
});
|
|
1466
1412
|
});
|
|
1467
|
-
}
|
|
1468
|
-
device.on('error', (error) => {
|
|
1469
|
-
console.error('Twilio Device Error:', error);
|
|
1470
|
-
// Handle specific error codes if needed
|
|
1471
|
-
if (error.code === 31201) { // Token expired
|
|
1472
|
-
console.log('Token expired, attempting to refresh...');
|
|
1473
|
-
this.initializeTwilioDevice();
|
|
1474
|
-
}
|
|
1475
|
-
});
|
|
1413
|
+
}
|
|
1476
1414
|
}
|
|
1415
|
+
// onIncomingCall(){
|
|
1416
|
+
// this.device.on('incoming', (call:any) => {
|
|
1417
|
+
// console.log(call);
|
|
1418
|
+
// //call.accept();
|
|
1419
|
+
// });
|
|
1420
|
+
// }
|
|
1477
1421
|
saveContact(payload) {
|
|
1478
1422
|
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
|
|
1479
1423
|
return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
|
|
@@ -1502,6 +1446,9 @@ class TwilioService {
|
|
|
1502
1446
|
return this.http.get(environment.apiUrl + '/utilities/phonebook/favourite/contacts', httpOptions);
|
|
1503
1447
|
}
|
|
1504
1448
|
getRecentCalls(pageIndex, pageSize) {
|
|
1449
|
+
// let params = new HttpParams();
|
|
1450
|
+
// params = params.set('size', pageSize);
|
|
1451
|
+
// params = params.set('page', pageIndex);
|
|
1505
1452
|
const headers = { 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') };
|
|
1506
1453
|
const httpOptions = { headers };
|
|
1507
1454
|
return this.http.get(environment.apiUrl + '/utilities/phonebook/recent/calls', httpOptions);
|
|
@@ -1532,6 +1479,14 @@ class TwilioService {
|
|
|
1532
1479
|
};
|
|
1533
1480
|
return this.http.post(environment.apiUrl + '/utilities/phonebook/delete/photo/' + id, payload, httpOptions);
|
|
1534
1481
|
}
|
|
1482
|
+
// toggleCallerIdAlertFn(val: any) {
|
|
1483
|
+
// let httpOptions = {
|
|
1484
|
+
// headers: new HttpHeaders({
|
|
1485
|
+
// 'Auth-Key': "Bearer " + localStorage.getItem('ext_token')
|
|
1486
|
+
// })
|
|
1487
|
+
// };
|
|
1488
|
+
// return this.http.put<[]>(environment.apiUrl + '/utilities/softphone/callerid/alert/' + val, {}, httpOptions);
|
|
1489
|
+
// }
|
|
1535
1490
|
toggleCoutryCodeToast(val) {
|
|
1536
1491
|
let httpOptions = {
|
|
1537
1492
|
headers: new HttpHeaders({
|
|
@@ -1545,35 +1500,9 @@ class TwilioService {
|
|
|
1545
1500
|
headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }),
|
|
1546
1501
|
params: new HttpParams().set('isoCode', isoCode)
|
|
1547
1502
|
};
|
|
1503
|
+
const params = new HttpParams().set('isoCode', isoCode);
|
|
1548
1504
|
return this.http.get(environment.apiUrl + '/utilities/softphone/check/countryCode/' + dialledNo, httpOptions);
|
|
1549
1505
|
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Get the current active call
|
|
1552
|
-
*/
|
|
1553
|
-
getCurrentCall() {
|
|
1554
|
-
return this._currentCall;
|
|
1555
|
-
}
|
|
1556
|
-
/**
|
|
1557
|
-
* Check if there's an active call
|
|
1558
|
-
*/
|
|
1559
|
-
hasActiveCall() {
|
|
1560
|
-
return this._currentCall !== null;
|
|
1561
|
-
}
|
|
1562
|
-
/**
|
|
1563
|
-
* Set whether to automatically answer incoming calls
|
|
1564
|
-
* @param autoAnswer - Whether to automatically answer calls
|
|
1565
|
-
*/
|
|
1566
|
-
setAutoAnswer(autoAnswer) {
|
|
1567
|
-
this.autoAnswer = autoAnswer;
|
|
1568
|
-
}
|
|
1569
|
-
/**
|
|
1570
|
-
* Toggle auto-answer for incoming calls
|
|
1571
|
-
* @returns The new auto-answer state
|
|
1572
|
-
*/
|
|
1573
|
-
toggleAutoAnswer() {
|
|
1574
|
-
this.autoAnswer = !this.autoAnswer;
|
|
1575
|
-
return this.autoAnswer;
|
|
1576
|
-
}
|
|
1577
1506
|
}
|
|
1578
1507
|
TwilioService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, deps: [{ token: i1.HttpClient }, { token: ExtensionService }, { token: NotificationService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1579
1508
|
TwilioService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, providedIn: 'root' });
|
|
@@ -2204,8 +2133,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
2204
2133
|
class DialboxComponent {
|
|
2205
2134
|
set isDialpadHidden(value) {
|
|
2206
2135
|
this._isDialpadHidden = value;
|
|
2207
|
-
if (!value
|
|
2208
|
-
// When dialpad becomes visible, ensure Twilio is initialized
|
|
2136
|
+
if (!value) {
|
|
2137
|
+
// When dialpad becomes visible, ensure Twilio is initialized
|
|
2209
2138
|
this.initializeTwilio();
|
|
2210
2139
|
}
|
|
2211
2140
|
}
|
|
@@ -2267,106 +2196,31 @@ class DialboxComponent {
|
|
|
2267
2196
|
this.isSmartDialCall = false;
|
|
2268
2197
|
this.isInitialized = false;
|
|
2269
2198
|
this.isMinimised = false;
|
|
2270
|
-
// Initialize
|
|
2271
|
-
this.
|
|
2272
|
-
if (this.token) {
|
|
2199
|
+
// Initialize if dialpad is visible by default
|
|
2200
|
+
if (!this.isDialpadHidden) {
|
|
2273
2201
|
this.initializeTwilio();
|
|
2274
2202
|
}
|
|
2275
|
-
else {
|
|
2276
|
-
console.warn('No auth token found, Twilio not initialized');
|
|
2277
|
-
}
|
|
2278
2203
|
}
|
|
2279
2204
|
initializeTwilio() {
|
|
2280
2205
|
if (this.isInitialized)
|
|
2281
2206
|
return;
|
|
2282
|
-
|
|
2207
|
+
this.token = localStorage.getItem('ext_token') || '';
|
|
2208
|
+
if (!this.token) {
|
|
2209
|
+
console.error('No authentication token found');
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
this.isInitialized = true;
|
|
2283
2213
|
// Initialize Twilio service
|
|
2284
2214
|
this.twilioService.initializeTwilioDevice();
|
|
2285
|
-
this.isInitialized = true;
|
|
2286
|
-
// Check for any existing call first
|
|
2287
|
-
const currentCall = this.twilioService.getCurrentCall();
|
|
2288
|
-
if (currentCall) {
|
|
2289
|
-
this.handleIncomingCall(currentCall);
|
|
2290
|
-
}
|
|
2291
2215
|
// Subscribe to incoming calls to show dialpad when call comes in
|
|
2292
2216
|
const callSub = this.twilioService.currentCall.subscribe(call => {
|
|
2293
2217
|
if (call) {
|
|
2294
|
-
console.log('Incoming call received
|
|
2295
|
-
this.handleIncomingCall(call);
|
|
2296
|
-
}
|
|
2297
|
-
});
|
|
2298
|
-
// Subscribe to call state changes
|
|
2299
|
-
const callStateSub = this.twilioService.currentCallState.subscribe(state => {
|
|
2300
|
-
console.log('Call state changed to:', state);
|
|
2301
|
-
if (state === 'incoming' || state === 'in-progress') {
|
|
2218
|
+
console.log('Incoming call received:', call);
|
|
2302
2219
|
this.isCallInProgress = true;
|
|
2303
|
-
this.
|
|
2304
|
-
}
|
|
2305
|
-
else if (state === 'none') {
|
|
2306
|
-
this.isCallInProgress = false;
|
|
2220
|
+
this.isDialpadHidden = false; // Show dialpad on incoming call
|
|
2307
2221
|
}
|
|
2308
2222
|
});
|
|
2309
2223
|
this.subscriptions.add(callSub);
|
|
2310
|
-
this.subscriptions.add(callStateSub);
|
|
2311
|
-
}
|
|
2312
|
-
handleIncomingCall(call) {
|
|
2313
|
-
console.log('Handling incoming call:', call);
|
|
2314
|
-
// Update call state
|
|
2315
|
-
this.isCallInProgress = true;
|
|
2316
|
-
// Force show the dialpad by directly setting the private field
|
|
2317
|
-
// to bypass any setter logic that might prevent showing it
|
|
2318
|
-
this._isDialpadHidden = false;
|
|
2319
|
-
// Update call data
|
|
2320
|
-
const callerNumber = call.parameters['From'] || 'Unknown';
|
|
2321
|
-
const callerName = call.parameters['CallerName'] || 'Unknown Caller';
|
|
2322
|
-
this.callData = {
|
|
2323
|
-
...this.callData,
|
|
2324
|
-
phone: callerNumber,
|
|
2325
|
-
name: callerName,
|
|
2326
|
-
img: 'assets/images/user.jpg',
|
|
2327
|
-
isIncomingCall: true,
|
|
2328
|
-
dial: true
|
|
2329
|
-
};
|
|
2330
|
-
// Add to incoming calls list if not already present
|
|
2331
|
-
const callExists = this.newIncomingCalls.some((c) => c.parameters['CallSid'] === call.parameters['CallSid']);
|
|
2332
|
-
if (!callExists) {
|
|
2333
|
-
this.newIncomingCalls = [...this.newIncomingCalls, call];
|
|
2334
|
-
this.incomingCallsList = [...this.newIncomingCalls];
|
|
2335
|
-
}
|
|
2336
|
-
// Emit event to notify parent components
|
|
2337
|
-
this.incomingCallInitiated.emit();
|
|
2338
|
-
// Set up call event handlers if not already set
|
|
2339
|
-
if (!call.listenerCount('accept')) {
|
|
2340
|
-
call.on('accept', () => {
|
|
2341
|
-
console.log('Call accepted:', call.parameters['CallSid']);
|
|
2342
|
-
this.isCallInProgress = true;
|
|
2343
|
-
this._isDialpadHidden = false; // Ensure dialpad stays open
|
|
2344
|
-
});
|
|
2345
|
-
}
|
|
2346
|
-
if (!call.listenerCount('disconnect')) {
|
|
2347
|
-
call.on('disconnect', () => {
|
|
2348
|
-
console.log('Call disconnected:', call.parameters['CallSid']);
|
|
2349
|
-
this.isCallInProgress = false;
|
|
2350
|
-
// Remove from incoming calls list
|
|
2351
|
-
this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2352
|
-
this.newIncomingCalls = this.newIncomingCalls.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2353
|
-
// If no more calls, reset the state
|
|
2354
|
-
if (this.incomingCallsList.length === 0) {
|
|
2355
|
-
this.isCallInProgress = false;
|
|
2356
|
-
// Don't hide the dialpad if there are no more calls
|
|
2357
|
-
// Let the user decide when to close it
|
|
2358
|
-
}
|
|
2359
|
-
});
|
|
2360
|
-
}
|
|
2361
|
-
if (!call.listenerCount('cancel')) {
|
|
2362
|
-
call.on('cancel', () => {
|
|
2363
|
-
console.log('Call cancelled by caller:', call.parameters['CallSid']);
|
|
2364
|
-
this.isCallInProgress = false;
|
|
2365
|
-
// Remove from incoming calls list
|
|
2366
|
-
this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2367
|
-
this.newIncomingCalls = this.newIncomingCalls.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
2224
|
}
|
|
2371
2225
|
// ngOnChange() {
|
|
2372
2226
|
// this.initializeTwilio();
|