@vgroup/dialbox 0.0.52 → 0.0.54
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/components/call-progress/incoming-call/incoming-call.component.mjs +1 -2
- package/esm2020/lib/dialbox.component.mjs +73 -18
- package/esm2020/lib/service/twilio.service.mjs +47 -18
- package/fesm2015/vgroup-dialbox.mjs +119 -35
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +118 -35
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/dialbox.component.d.ts +3 -0
- package/lib/service/twilio.service.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1317,25 +1317,54 @@ class TwilioService {
|
|
|
1317
1317
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
1318
1318
|
this.initializeTwilioDevice();
|
|
1319
1319
|
}
|
|
1320
|
+
setupDeviceListeners() {
|
|
1321
|
+
if (!this.device)
|
|
1322
|
+
return;
|
|
1323
|
+
// Remove any existing listeners first
|
|
1324
|
+
this.device.off('incoming');
|
|
1325
|
+
this.device.off('error');
|
|
1326
|
+
this.device.off('registered');
|
|
1327
|
+
this.device.off('unregistered');
|
|
1328
|
+
// Set up new listeners
|
|
1329
|
+
this.device.on('registered', () => {
|
|
1330
|
+
console.log('Twilio Device registered');
|
|
1331
|
+
});
|
|
1332
|
+
this.device.on('incoming', (call) => {
|
|
1333
|
+
console.log('Incoming call received');
|
|
1334
|
+
this.currentCall.next(call);
|
|
1335
|
+
this.callType.next('INCOMING');
|
|
1336
|
+
this.currentCallState.next('incoming');
|
|
1337
|
+
});
|
|
1338
|
+
this.device.on('error', (error) => {
|
|
1339
|
+
console.error('Twilio Device Error:', error);
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1320
1342
|
initializeTwilioDevice() {
|
|
1343
|
+
if (this.device) {
|
|
1344
|
+
// If device already exists, just re-register
|
|
1345
|
+
this.device.register();
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1321
1348
|
if (this.token) {
|
|
1322
|
-
this.extensionService.getIncomingCallToken().subscribe(
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1349
|
+
this.extensionService.getIncomingCallToken().subscribe({
|
|
1350
|
+
next: (data) => {
|
|
1351
|
+
this.incomingCallToken = data.token;
|
|
1352
|
+
localStorage.setItem('in-token', data.token);
|
|
1353
|
+
// Destroy existing device if any
|
|
1354
|
+
if (this.device) {
|
|
1355
|
+
this.device.destroy();
|
|
1356
|
+
}
|
|
1357
|
+
this.device = new Device(this.incomingCallToken, {
|
|
1358
|
+
allowIncomingWhileBusy: true,
|
|
1359
|
+
closeProtection: true
|
|
1360
|
+
});
|
|
1361
|
+
this.setupDeviceListeners();
|
|
1362
|
+
this.device.register();
|
|
1363
|
+
},
|
|
1364
|
+
error: (error) => {
|
|
1365
|
+
console.error('Error getting Twilio token:', error);
|
|
1366
|
+
// Add retry logic here if needed
|
|
1367
|
+
}
|
|
1339
1368
|
});
|
|
1340
1369
|
}
|
|
1341
1370
|
}
|
|
@@ -1545,7 +1574,6 @@ class IncomingCallComponent {
|
|
|
1545
1574
|
if (call) {
|
|
1546
1575
|
this.twilioCallData = call;
|
|
1547
1576
|
this.twilioAuthId = call.customParameters.get('twilioAuthId');
|
|
1548
|
-
this.newIncomingCallsList.push(call);
|
|
1549
1577
|
if (!call.parameters) {
|
|
1550
1578
|
call.parameters = {};
|
|
1551
1579
|
}
|
|
@@ -2137,7 +2165,7 @@ class DialboxComponent {
|
|
|
2137
2165
|
this.ipService = ipService;
|
|
2138
2166
|
this.extensionService = extensionService;
|
|
2139
2167
|
this.router = router;
|
|
2140
|
-
this.isDialpadHidden =
|
|
2168
|
+
this.isDialpadHidden = true;
|
|
2141
2169
|
this.closeDialpadEvent = new EventEmitter();
|
|
2142
2170
|
this.callInitiated = new EventEmitter();
|
|
2143
2171
|
this.endCallEvent = new EventEmitter();
|
|
@@ -2183,14 +2211,22 @@ class DialboxComponent {
|
|
|
2183
2211
|
this.subscriptions = new Subscription();
|
|
2184
2212
|
this.shakeDedicatedBtn = false;
|
|
2185
2213
|
this.isSmartDialCall = false;
|
|
2214
|
+
this.isTwilioInitialized = false;
|
|
2186
2215
|
this.isMinimised = false;
|
|
2216
|
+
// Subscribe to incoming calls
|
|
2217
|
+
this.subscriptions.add(this.twilioService.currentCall.subscribe(call => {
|
|
2218
|
+
if (call) {
|
|
2219
|
+
this.handleIncomingCall(call);
|
|
2220
|
+
}
|
|
2221
|
+
}));
|
|
2187
2222
|
}
|
|
2188
2223
|
ngOnInit() {
|
|
2189
2224
|
try {
|
|
2190
2225
|
this.token = localStorage.getItem('ext_token') || '';
|
|
2191
|
-
|
|
2226
|
+
this.initializeTwilio();
|
|
2192
2227
|
this.getContactList();
|
|
2193
2228
|
this.getUserCallSetting();
|
|
2229
|
+
// Subscribe to dial number events
|
|
2194
2230
|
const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
|
|
2195
2231
|
if (contact.number) {
|
|
2196
2232
|
this.isSmartDialCall = false;
|
|
@@ -2309,12 +2345,56 @@ class DialboxComponent {
|
|
|
2309
2345
|
this.registerDragElement();
|
|
2310
2346
|
}
|
|
2311
2347
|
ngOnChanges(changes) {
|
|
2312
|
-
if (changes['isDialpadHidden']
|
|
2313
|
-
this.
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2348
|
+
if (changes['isDialpadHidden']) {
|
|
2349
|
+
if (!changes['isDialpadHidden'].firstChange && !this.isDialpadHidden) {
|
|
2350
|
+
// Re-initialize Twilio when dialpad becomes visible
|
|
2351
|
+
this.initializeTwilio();
|
|
2352
|
+
}
|
|
2353
|
+
if (!this.isDialpadHidden) {
|
|
2354
|
+
this.getContactList();
|
|
2355
|
+
this.getUserCallSetting();
|
|
2356
|
+
setTimeout(() => {
|
|
2357
|
+
if (this.dialInputElement?.nativeElement) {
|
|
2358
|
+
this.dialInputElement.nativeElement.focus();
|
|
2359
|
+
}
|
|
2360
|
+
}, 0);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
initializeTwilio() {
|
|
2365
|
+
if (this.isTwilioInitialized || !this.token)
|
|
2366
|
+
return;
|
|
2367
|
+
this.isTwilioInitialized = true;
|
|
2368
|
+
// Clear any existing device first
|
|
2369
|
+
if (this.twilioService.device) {
|
|
2370
|
+
this.twilioService.device.destroy();
|
|
2371
|
+
this.twilioService.device = null;
|
|
2372
|
+
}
|
|
2373
|
+
// Initialize new device
|
|
2374
|
+
this.twilioService.initializeTwilioDevice();
|
|
2375
|
+
// Reset the current call state
|
|
2376
|
+
this.twilioService.currentCall.next(null);
|
|
2377
|
+
this.twilioService.currentCallState.next('none');
|
|
2378
|
+
}
|
|
2379
|
+
handleIncomingCall(call) {
|
|
2380
|
+
try {
|
|
2381
|
+
if (!call)
|
|
2382
|
+
return;
|
|
2383
|
+
this.incomingCallInitiated.emit();
|
|
2384
|
+
this.newIncomingCallData = call;
|
|
2385
|
+
// Add to incoming calls list if not already present
|
|
2386
|
+
const existingCall = this.incomingCallsList.find((c) => c.parameters.CallSid === call.parameters.CallSid);
|
|
2387
|
+
if (!existingCall) {
|
|
2388
|
+
this.incomingCallsList.unshift(call);
|
|
2389
|
+
this.incomingCallsNewInfoEvent.emit(this.incomingCallsList);
|
|
2390
|
+
}
|
|
2391
|
+
// Show the dialpad if it's hidden
|
|
2392
|
+
if (this.isDialpadHidden) {
|
|
2393
|
+
this.isDialpadHidden = false;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
catch (error) {
|
|
2397
|
+
console.error('Error handling incoming call:', error);
|
|
2318
2398
|
}
|
|
2319
2399
|
}
|
|
2320
2400
|
registerDragElement() {
|
|
@@ -3042,19 +3122,22 @@ class DialboxComponent {
|
|
|
3042
3122
|
}
|
|
3043
3123
|
ngOnDestroy() {
|
|
3044
3124
|
try {
|
|
3045
|
-
console.log('Cleaning up C2cDialpadComponent');
|
|
3046
|
-
// Unsubscribe from all subscriptions
|
|
3047
|
-
if (this.subscriptions) {
|
|
3048
|
-
this.subscriptions.unsubscribe();
|
|
3049
|
-
}
|
|
3050
|
-
// End any active call
|
|
3051
|
-
if (this.isCallInProgress) {
|
|
3052
|
-
this.endCall();
|
|
3053
|
-
}
|
|
3054
3125
|
// Clear any timeouts or intervals if they exist
|
|
3055
3126
|
if (this.toastTimeout) {
|
|
3056
3127
|
clearTimeout(this.toastTimeout);
|
|
3057
3128
|
}
|
|
3129
|
+
// Unsubscribe from all subscriptions
|
|
3130
|
+
this.subscriptions.unsubscribe();
|
|
3131
|
+
// Clean up Twilio device if it exists
|
|
3132
|
+
if (this.twilioService.device) {
|
|
3133
|
+
try {
|
|
3134
|
+
this.twilioService.device.destroy();
|
|
3135
|
+
this.twilioService.device = null;
|
|
3136
|
+
}
|
|
3137
|
+
catch (error) {
|
|
3138
|
+
console.error('Error cleaning up Twilio device:', error);
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3058
3141
|
console.log('C2cDialpadComponent cleanup complete');
|
|
3059
3142
|
}
|
|
3060
3143
|
catch (error) {
|