@vgroup/dialbox 0.0.77 → 0.0.79
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 +81 -7
- package/esm2020/lib/service/twilio.service.mjs +32 -2
- package/fesm2015/vgroup-dialbox.mjs +104 -7
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +111 -7
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/dialbox.component.d.ts +1 -0
- package/lib/service/twilio.service.d.ts +10 -1
- package/package.json +1 -1
|
@@ -1372,7 +1372,8 @@ class TwilioService {
|
|
|
1372
1372
|
this.notificationSerivce = notificationSerivce;
|
|
1373
1373
|
this.openInProgressDialpad = new BehaviorSubject(false);
|
|
1374
1374
|
this.currentCall = new BehaviorSubject(null);
|
|
1375
|
-
this.currentCallState = new BehaviorSubject('none'); //in-progress, out-progress, none
|
|
1375
|
+
this.currentCallState = new BehaviorSubject('none'); // 'incoming', 'in-progress', 'out-progress', 'none'
|
|
1376
|
+
this._currentCall = null;
|
|
1376
1377
|
this.callType = new BehaviorSubject('NIL');
|
|
1377
1378
|
this.isIncomingCallPicked = new BehaviorSubject(false); // for both incoming and outgoing
|
|
1378
1379
|
this.token = localStorage.getItem('ext_token');
|
|
@@ -1400,10 +1401,27 @@ class TwilioService {
|
|
|
1400
1401
|
});
|
|
1401
1402
|
this.device.register();
|
|
1402
1403
|
this.device.on('incoming', (call) => {
|
|
1404
|
+
this._currentCall = call;
|
|
1403
1405
|
this.currentCall.next(call);
|
|
1404
1406
|
this.callType.next('INCOMING');
|
|
1405
1407
|
this.currentCallState.next('incoming');
|
|
1406
1408
|
this.notificationSerivce.showNotification(call);
|
|
1409
|
+
// Set up call event handlers
|
|
1410
|
+
call.on('accept', () => {
|
|
1411
|
+
this.currentCallState.next('in-progress');
|
|
1412
|
+
});
|
|
1413
|
+
call.on('disconnect', () => {
|
|
1414
|
+
this._currentCall = null;
|
|
1415
|
+
this.currentCall.next(null);
|
|
1416
|
+
this.currentCallState.next('none');
|
|
1417
|
+
this.callType.next('NIL');
|
|
1418
|
+
});
|
|
1419
|
+
call.on('cancel', () => {
|
|
1420
|
+
this._currentCall = null;
|
|
1421
|
+
this.currentCall.next(null);
|
|
1422
|
+
this.currentCallState.next('none');
|
|
1423
|
+
this.callType.next('NIL');
|
|
1424
|
+
});
|
|
1407
1425
|
});
|
|
1408
1426
|
this.device.on('error', (error) => {
|
|
1409
1427
|
console.error('Twilio Device Error:', error);
|
|
@@ -1503,6 +1521,18 @@ class TwilioService {
|
|
|
1503
1521
|
const params = new HttpParams().set('isoCode', isoCode);
|
|
1504
1522
|
return this.http.get(environment.apiUrl + '/utilities/softphone/check/countryCode/' + dialledNo, httpOptions);
|
|
1505
1523
|
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Get the current active call
|
|
1526
|
+
*/
|
|
1527
|
+
getCurrentCall() {
|
|
1528
|
+
return this._currentCall;
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Check if there's an active call
|
|
1532
|
+
*/
|
|
1533
|
+
hasActiveCall() {
|
|
1534
|
+
return this._currentCall !== null;
|
|
1535
|
+
}
|
|
1506
1536
|
}
|
|
1507
1537
|
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 });
|
|
1508
1538
|
TwilioService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioService, providedIn: 'root' });
|
|
@@ -2196,10 +2226,8 @@ class DialboxComponent {
|
|
|
2196
2226
|
this.isSmartDialCall = false;
|
|
2197
2227
|
this.isInitialized = false;
|
|
2198
2228
|
this.isMinimised = false;
|
|
2199
|
-
//
|
|
2200
|
-
|
|
2201
|
-
this.initializeTwilio();
|
|
2202
|
-
}
|
|
2229
|
+
// Always initialize Twilio when component loads to receive calls immediately
|
|
2230
|
+
this.initializeTwilio();
|
|
2203
2231
|
}
|
|
2204
2232
|
initializeTwilio() {
|
|
2205
2233
|
if (this.isInitialized)
|
|
@@ -2210,17 +2238,93 @@ class DialboxComponent {
|
|
|
2210
2238
|
return;
|
|
2211
2239
|
}
|
|
2212
2240
|
this.isInitialized = true;
|
|
2241
|
+
console.log('Initializing Twilio service...');
|
|
2213
2242
|
// Initialize Twilio service
|
|
2214
2243
|
this.twilioService.initializeTwilioDevice();
|
|
2244
|
+
// Check for any existing call first
|
|
2245
|
+
const currentCall = this.twilioService.getCurrentCall();
|
|
2246
|
+
if (currentCall) {
|
|
2247
|
+
this.handleIncomingCall(currentCall);
|
|
2248
|
+
}
|
|
2215
2249
|
// Subscribe to incoming calls to show dialpad when call comes in
|
|
2216
2250
|
const callSub = this.twilioService.currentCall.subscribe(call => {
|
|
2217
2251
|
if (call) {
|
|
2218
|
-
console.log('Incoming call received:', call);
|
|
2252
|
+
console.log('Incoming call received in component:', call);
|
|
2253
|
+
this.handleIncomingCall(call);
|
|
2254
|
+
}
|
|
2255
|
+
});
|
|
2256
|
+
// Subscribe to call state changes
|
|
2257
|
+
const callStateSub = this.twilioService.currentCallState.subscribe(state => {
|
|
2258
|
+
console.log('Call state changed to:', state);
|
|
2259
|
+
if (state === 'incoming' || state === 'in-progress') {
|
|
2219
2260
|
this.isCallInProgress = true;
|
|
2220
|
-
this.
|
|
2261
|
+
this._isDialpadHidden = false; // Force show the dialpad for incoming/active calls
|
|
2262
|
+
}
|
|
2263
|
+
else if (state === 'none') {
|
|
2264
|
+
this.isCallInProgress = false;
|
|
2221
2265
|
}
|
|
2222
2266
|
});
|
|
2223
2267
|
this.subscriptions.add(callSub);
|
|
2268
|
+
this.subscriptions.add(callStateSub);
|
|
2269
|
+
}
|
|
2270
|
+
handleIncomingCall(call) {
|
|
2271
|
+
console.log('Handling incoming call:', call);
|
|
2272
|
+
// Update call state
|
|
2273
|
+
this.isCallInProgress = true;
|
|
2274
|
+
// Force show the dialpad by directly setting the private field
|
|
2275
|
+
// to bypass any setter logic that might prevent showing it
|
|
2276
|
+
this._isDialpadHidden = false;
|
|
2277
|
+
// Update call data
|
|
2278
|
+
const callerNumber = call.parameters['From'] || 'Unknown';
|
|
2279
|
+
const callerName = call.parameters['CallerName'] || 'Unknown Caller';
|
|
2280
|
+
this.callData = {
|
|
2281
|
+
...this.callData,
|
|
2282
|
+
phone: callerNumber,
|
|
2283
|
+
name: callerName,
|
|
2284
|
+
img: 'assets/images/user.jpg',
|
|
2285
|
+
isIncomingCall: true,
|
|
2286
|
+
dial: true
|
|
2287
|
+
};
|
|
2288
|
+
// Add to incoming calls list if not already present
|
|
2289
|
+
const callExists = this.newIncomingCalls.some((c) => c.parameters['CallSid'] === call.parameters['CallSid']);
|
|
2290
|
+
if (!callExists) {
|
|
2291
|
+
this.newIncomingCalls = [...this.newIncomingCalls, call];
|
|
2292
|
+
this.incomingCallsList = [...this.newIncomingCalls];
|
|
2293
|
+
}
|
|
2294
|
+
// Emit event to notify parent components
|
|
2295
|
+
this.incomingCallInitiated.emit();
|
|
2296
|
+
// Set up call event handlers if not already set
|
|
2297
|
+
if (!call.listenerCount('accept')) {
|
|
2298
|
+
call.on('accept', () => {
|
|
2299
|
+
console.log('Call accepted:', call.parameters['CallSid']);
|
|
2300
|
+
this.isCallInProgress = true;
|
|
2301
|
+
this._isDialpadHidden = false; // Ensure dialpad stays open
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
if (!call.listenerCount('disconnect')) {
|
|
2305
|
+
call.on('disconnect', () => {
|
|
2306
|
+
console.log('Call disconnected:', call.parameters['CallSid']);
|
|
2307
|
+
this.isCallInProgress = false;
|
|
2308
|
+
// Remove from incoming calls list
|
|
2309
|
+
this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2310
|
+
this.newIncomingCalls = this.newIncomingCalls.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2311
|
+
// If no more calls, reset the state
|
|
2312
|
+
if (this.incomingCallsList.length === 0) {
|
|
2313
|
+
this.isCallInProgress = false;
|
|
2314
|
+
// Don't hide the dialpad if there are no more calls
|
|
2315
|
+
// Let the user decide when to close it
|
|
2316
|
+
}
|
|
2317
|
+
});
|
|
2318
|
+
}
|
|
2319
|
+
if (!call.listenerCount('cancel')) {
|
|
2320
|
+
call.on('cancel', () => {
|
|
2321
|
+
console.log('Call cancelled by caller:', call.parameters['CallSid']);
|
|
2322
|
+
this.isCallInProgress = false;
|
|
2323
|
+
// Remove from incoming calls list
|
|
2324
|
+
this.incomingCallsList = this.incomingCallsList.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2325
|
+
this.newIncomingCalls = this.newIncomingCalls.filter((item) => item.parameters['CallSid'] !== call.parameters['CallSid']);
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2224
2328
|
}
|
|
2225
2329
|
// ngOnChange() {
|
|
2226
2330
|
// this.initializeTwilio();
|