@vgroup/dialbox 0.0.56 → 0.0.57
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 +63 -42
- package/esm2020/lib/service/twilio.service.mjs +30 -33
- package/fesm2015/vgroup-dialbox.mjs +93 -73
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +91 -73
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/dialbox.component.d.ts +5 -4
- package/lib/service/twilio.service.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1317,28 +1317,30 @@ class TwilioService {
|
|
|
1317
1317
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
1318
1318
|
this.isInitialized = false;
|
|
1319
1319
|
this.initializationInProgress = false;
|
|
1320
|
-
|
|
1321
|
-
if (this.token) {
|
|
1322
|
-
this.initializeTwilioDevice();
|
|
1323
|
-
}
|
|
1324
|
-
else {
|
|
1325
|
-
// If token is not available, try to get it from localStorage
|
|
1326
|
-
const token = localStorage.getItem('ext_token');
|
|
1327
|
-
if (token) {
|
|
1328
|
-
this.token = token;
|
|
1329
|
-
this.initializeTwilioDevice();
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1320
|
+
this.initializeTwilioDevice();
|
|
1332
1321
|
}
|
|
1333
1322
|
initializeTwilioDevice() {
|
|
1334
|
-
if (this.initializationInProgress ||
|
|
1323
|
+
if (this.initializationInProgress || this.isInitialized)
|
|
1335
1324
|
return;
|
|
1336
1325
|
this.initializationInProgress = true;
|
|
1337
1326
|
this.extensionService.getIncomingCallToken().subscribe({
|
|
1338
1327
|
next: (data) => {
|
|
1339
1328
|
if (data?.token) {
|
|
1340
|
-
this.
|
|
1329
|
+
this.incomingCallToken = data.token;
|
|
1330
|
+
localStorage.setItem('in-token', data.token);
|
|
1331
|
+
// Clean up existing device if any
|
|
1332
|
+
if (this.device) {
|
|
1333
|
+
this.device.destroy();
|
|
1334
|
+
}
|
|
1335
|
+
// Initialize new device
|
|
1336
|
+
this.device = new Device(data.token, {
|
|
1337
|
+
allowIncomingWhileBusy: true,
|
|
1338
|
+
closeProtection: true
|
|
1339
|
+
});
|
|
1340
|
+
this.setupDeviceEventListeners();
|
|
1341
|
+
this.device.register();
|
|
1341
1342
|
this.isInitialized = true;
|
|
1343
|
+
this.initializationInProgress = false;
|
|
1342
1344
|
}
|
|
1343
1345
|
},
|
|
1344
1346
|
error: (error) => {
|
|
@@ -1349,21 +1351,13 @@ class TwilioService {
|
|
|
1349
1351
|
}
|
|
1350
1352
|
});
|
|
1351
1353
|
}
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
this.incomingCallToken = token;
|
|
1358
|
-
localStorage.setItem('in-token', token);
|
|
1359
|
-
this.device = new Device(token, {
|
|
1360
|
-
allowIncomingWhileBusy: true,
|
|
1361
|
-
closeProtection: true
|
|
1362
|
-
});
|
|
1363
|
-
// Set up event listeners
|
|
1354
|
+
setupDeviceEventListeners() {
|
|
1355
|
+
if (!this.device)
|
|
1356
|
+
return;
|
|
1357
|
+
// Clean up existing listeners
|
|
1358
|
+
this.device.removeAllListeners();
|
|
1364
1359
|
this.device.on('registered', () => {
|
|
1365
1360
|
console.log('Twilio Device registered successfully');
|
|
1366
|
-
this.initializationInProgress = false;
|
|
1367
1361
|
});
|
|
1368
1362
|
this.device.on('incoming', (call) => {
|
|
1369
1363
|
console.log('Incoming call received');
|
|
@@ -1374,7 +1368,6 @@ class TwilioService {
|
|
|
1374
1368
|
this.device.on('error', (error) => {
|
|
1375
1369
|
console.error('Twilio Device Error:', error);
|
|
1376
1370
|
this.isInitialized = false;
|
|
1377
|
-
this.initializationInProgress = false;
|
|
1378
1371
|
// Attempt to reinitialize after error
|
|
1379
1372
|
setTimeout(() => this.initializeTwilioDevice(), 5000);
|
|
1380
1373
|
});
|
|
@@ -1384,11 +1377,15 @@ class TwilioService {
|
|
|
1384
1377
|
// Attempt to re-register
|
|
1385
1378
|
this.initializeTwilioDevice();
|
|
1386
1379
|
});
|
|
1387
|
-
this.device.register();
|
|
1388
1380
|
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1381
|
+
onIncomingCall() {
|
|
1382
|
+
if (this.device) {
|
|
1383
|
+
this.device.on('incoming', (call) => {
|
|
1384
|
+
console.log('Incoming call:', call);
|
|
1385
|
+
// call.accept();
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1392
1389
|
saveContact(payload) {
|
|
1393
1390
|
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
|
|
1394
1391
|
return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
|
|
@@ -2173,16 +2170,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
2173
2170
|
}] } });
|
|
2174
2171
|
|
|
2175
2172
|
class DialboxComponent {
|
|
2176
|
-
set isDialpadHidden(value) {
|
|
2177
|
-
this._isDialpadHidden = value;
|
|
2178
|
-
if (!value) {
|
|
2179
|
-
// When dialpad becomes visible, ensure Twilio is initialized
|
|
2180
|
-
this.initializeTwilio();
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
get isDialpadHidden() {
|
|
2184
|
-
return this._isDialpadHidden;
|
|
2185
|
-
}
|
|
2186
2173
|
constructor(twilioService, extService, dialog, ipService, extensionService, router) {
|
|
2187
2174
|
this.twilioService = twilioService;
|
|
2188
2175
|
this.extService = extService;
|
|
@@ -2190,7 +2177,7 @@ class DialboxComponent {
|
|
|
2190
2177
|
this.ipService = ipService;
|
|
2191
2178
|
this.extensionService = extensionService;
|
|
2192
2179
|
this.router = router;
|
|
2193
|
-
this.
|
|
2180
|
+
this.isDialpadHidden = true;
|
|
2194
2181
|
this.closeDialpadEvent = new EventEmitter();
|
|
2195
2182
|
this.callInitiated = new EventEmitter();
|
|
2196
2183
|
this.endCallEvent = new EventEmitter();
|
|
@@ -2236,38 +2223,70 @@ class DialboxComponent {
|
|
|
2236
2223
|
this.subscriptions = new Subscription();
|
|
2237
2224
|
this.shakeDedicatedBtn = false;
|
|
2238
2225
|
this.isSmartDialCall = false;
|
|
2239
|
-
this.isInitialized = false;
|
|
2240
2226
|
this.isMinimised = false;
|
|
2241
|
-
// Initialize if dialpad is visible by default
|
|
2242
|
-
if (!this.isDialpadHidden) {
|
|
2243
|
-
this.initializeTwilio();
|
|
2244
|
-
}
|
|
2245
2227
|
}
|
|
2246
2228
|
initializeTwilio() {
|
|
2247
|
-
if (this.
|
|
2248
|
-
return;
|
|
2249
|
-
this.token = localStorage.getItem('ext_token') || '';
|
|
2250
|
-
if (!this.token) {
|
|
2251
|
-
console.error('No authentication token found');
|
|
2229
|
+
if (!this.twilioService || !this.token) {
|
|
2252
2230
|
return;
|
|
2253
2231
|
}
|
|
2254
|
-
this.isInitialized = true;
|
|
2255
|
-
// Initialize Twilio service
|
|
2256
2232
|
this.twilioService.initializeTwilioDevice();
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2233
|
+
this.setupIncomingCallSubscription();
|
|
2234
|
+
}
|
|
2235
|
+
setupIncomingCallSubscription() {
|
|
2236
|
+
this.subscriptions.add(this.twilioService.currentCall.subscribe(incomingCallData => {
|
|
2237
|
+
if (incomingCallData) {
|
|
2238
|
+
if (this.isCallInProgress) {
|
|
2239
|
+
this.newIncomingCalls.push(incomingCallData);
|
|
2240
|
+
this.getUserInformation(incomingCallData);
|
|
2241
|
+
}
|
|
2242
|
+
else {
|
|
2243
|
+
this.handleNewIncomingCall(incomingCallData);
|
|
2244
|
+
}
|
|
2262
2245
|
}
|
|
2263
|
-
});
|
|
2264
|
-
|
|
2246
|
+
}));
|
|
2247
|
+
}
|
|
2248
|
+
handleNewIncomingCall(call) {
|
|
2249
|
+
this.isCallInProgress = true;
|
|
2250
|
+
this.isDialpadHidden = false; // Show the dialpad when there's an incoming call
|
|
2251
|
+
this.callData = {
|
|
2252
|
+
phone: call.parameters['From'],
|
|
2253
|
+
displayNum: call.parameters['From'],
|
|
2254
|
+
dial: true,
|
|
2255
|
+
name: call.customParameters?.get('name') || 'Unknown',
|
|
2256
|
+
img: call.customParameters?.get('image') || 'assets/images/user.jpg',
|
|
2257
|
+
isIncomingCall: true,
|
|
2258
|
+
extNum: ''
|
|
2259
|
+
};
|
|
2260
|
+
call.on('cancel', () => this.handleCallEnd(call));
|
|
2261
|
+
call.on('disconnect', () => this.handleCallEnd(call));
|
|
2262
|
+
this.incomingCallInitiated.emit();
|
|
2263
|
+
}
|
|
2264
|
+
handleCallEnd(call) {
|
|
2265
|
+
this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters.CallSid !== call.parameters['CallSid']);
|
|
2266
|
+
if (this.incomingCallsList.length === 0) {
|
|
2267
|
+
this.isCallInProgress = false;
|
|
2268
|
+
this.resetCallData();
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
resetCallData() {
|
|
2272
|
+
this.callData = {
|
|
2273
|
+
phone: '',
|
|
2274
|
+
displayNum: '',
|
|
2275
|
+
dial: false,
|
|
2276
|
+
name: '',
|
|
2277
|
+
img: 'assets/images/user.jpg',
|
|
2278
|
+
isIncomingCall: false,
|
|
2279
|
+
extNum: ''
|
|
2280
|
+
};
|
|
2265
2281
|
}
|
|
2266
2282
|
ngOnInit() {
|
|
2267
2283
|
try {
|
|
2284
|
+
this.token = localStorage.getItem('ext_token') || '';
|
|
2285
|
+
this.initializeTwilio();
|
|
2286
|
+
this.getUserCallSetting();
|
|
2287
|
+
this.getContactList();
|
|
2268
2288
|
this.getContactList();
|
|
2269
2289
|
this.getUserCallSetting();
|
|
2270
|
-
// Subscribe to dial number events
|
|
2271
2290
|
const sub1 = this.twilioService.dialNumberFromOtherModule.subscribe((contact) => {
|
|
2272
2291
|
if (contact.number) {
|
|
2273
2292
|
this.isSmartDialCall = false;
|
|
@@ -2386,12 +2405,15 @@ class DialboxComponent {
|
|
|
2386
2405
|
this.registerDragElement();
|
|
2387
2406
|
}
|
|
2388
2407
|
ngOnChanges(changes) {
|
|
2389
|
-
if (changes['isDialpadHidden']
|
|
2390
|
-
this.
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2408
|
+
if (changes['isDialpadHidden']) {
|
|
2409
|
+
if (!this.isDialpadHidden) {
|
|
2410
|
+
// Focus the input when dialpad becomes visible
|
|
2411
|
+
setTimeout(() => {
|
|
2412
|
+
if (this.dialInputElement?.nativeElement) {
|
|
2413
|
+
this.dialInputElement.nativeElement.focus();
|
|
2414
|
+
}
|
|
2415
|
+
}, 0);
|
|
2416
|
+
}
|
|
2395
2417
|
}
|
|
2396
2418
|
}
|
|
2397
2419
|
registerDragElement() {
|
|
@@ -3124,10 +3146,6 @@ class DialboxComponent {
|
|
|
3124
3146
|
if (this.subscriptions) {
|
|
3125
3147
|
this.subscriptions.unsubscribe();
|
|
3126
3148
|
}
|
|
3127
|
-
// Clean up Twilio device when component is destroyed
|
|
3128
|
-
if (this.twilioService['device']) {
|
|
3129
|
-
this.twilioService['device'].destroy();
|
|
3130
|
-
}
|
|
3131
3149
|
// End any active call
|
|
3132
3150
|
if (this.isCallInProgress) {
|
|
3133
3151
|
this.endCall();
|