@vgroup/dialbox 0.0.24 → 0.0.26
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 +20 -1
- package/esm2020/lib/service/twilio-init.service.mjs +66 -0
- package/esm2020/lib/service/twilio.service.mjs +40 -7
- package/esm2020/public-api.mjs +4 -1
- package/fesm2015/vgroup-dialbox.mjs +124 -9
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +123 -9
- package/fesm2020/vgroup-dialbox.mjs.map +1 -1
- package/lib/service/twilio-init.service.d.ts +16 -0
- package/lib/service/twilio.service.d.ts +2 -0
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
|
@@ -14,7 +14,7 @@ import * as i3 from '@angular/common';
|
|
|
14
14
|
import { CommonModule } from '@angular/common';
|
|
15
15
|
import * as i3$1 from '@angular/forms';
|
|
16
16
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
17
|
-
import { Device } from '@twilio/voice-sdk';
|
|
17
|
+
import { Device as Device$1 } from '@twilio/voice-sdk';
|
|
18
18
|
|
|
19
19
|
const keypad = [
|
|
20
20
|
{
|
|
@@ -115,12 +115,45 @@ class TwilioService {
|
|
|
115
115
|
this.callerIdList = new BehaviorSubject([]);
|
|
116
116
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
117
117
|
}
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
// Update the Twilio token
|
|
119
|
+
updateToken(token) {
|
|
120
|
+
if (this.device) {
|
|
121
|
+
this.device.updateToken(token);
|
|
122
|
+
localStorage.setItem('twilio_token', token);
|
|
123
|
+
console.log('Twilio token updated');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.warn('Cannot update token: Twilio device not initialized');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Initialize Twilio device with token
|
|
130
|
+
initializeTwilioDevice(token) {
|
|
131
|
+
try {
|
|
132
|
+
if (!token) {
|
|
133
|
+
console.error('No Twilio token provided');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
// Store the token in localStorage
|
|
137
|
+
localStorage.setItem('twilio_token', token);
|
|
138
|
+
// Initialize Twilio device
|
|
139
|
+
// @ts-ignore - Device is loaded from Twilio client SDK
|
|
140
|
+
this.device = new Device(token, {
|
|
141
|
+
codecPreferences: ['opus', 'pcmu'],
|
|
142
|
+
debug: true
|
|
143
|
+
});
|
|
144
|
+
// Set up device event listeners
|
|
145
|
+
this.device.on('ready', (device) => {
|
|
146
|
+
console.log('Twilio Device Ready');
|
|
147
|
+
});
|
|
148
|
+
this.device.on('error', (error) => {
|
|
149
|
+
console.error('Twilio Device Error:', error);
|
|
150
|
+
this.currentCallState.next('error');
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error('Error initializing Twilio device:', error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
124
157
|
saveContact(payload) {
|
|
125
158
|
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Auth-Key': "Bearer " + localStorage.getItem('ext_token') }) };
|
|
126
159
|
return this.http.post(environment.apiUrl + '/utilities/phonebook/add/contacts/manually', payload, httpOptions);
|
|
@@ -1445,6 +1478,25 @@ class IncomingCallComponent {
|
|
|
1445
1478
|
if (!call.parameters) {
|
|
1446
1479
|
call.parameters = {};
|
|
1447
1480
|
}
|
|
1481
|
+
// Fetch user information when call is received
|
|
1482
|
+
if (this.twilioAuthId) {
|
|
1483
|
+
this.extensionService.getUserInformation(this.twilioAuthId).subscribe({
|
|
1484
|
+
next: (userInfo) => {
|
|
1485
|
+
console.log('User information:', userInfo);
|
|
1486
|
+
// Update the call data with user information
|
|
1487
|
+
if (userInfo && userInfo.data) {
|
|
1488
|
+
this.incomingCallData = {
|
|
1489
|
+
...this.incomingCallData,
|
|
1490
|
+
callerInfo: userInfo.data
|
|
1491
|
+
};
|
|
1492
|
+
this.selectedIncomingCallInfo.emit(this.incomingCallData);
|
|
1493
|
+
}
|
|
1494
|
+
},
|
|
1495
|
+
error: (error) => {
|
|
1496
|
+
console.error('Error fetching user information:', error);
|
|
1497
|
+
}
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1448
1500
|
this.sendIPforIncomingCall(this.twilioAuthId, '');
|
|
1449
1501
|
call.on('cancel', () => {
|
|
1450
1502
|
if (this.incomingCallData && this.incomingCallData.parameters && this.incomingCallData.parameters.CallSid) {
|
|
@@ -1714,7 +1766,7 @@ class CallProgressComponent {
|
|
|
1714
1766
|
codecPreferences: ['opus', 'pcmu'],
|
|
1715
1767
|
closeProtection: true,
|
|
1716
1768
|
};
|
|
1717
|
-
this.device = new Device(token.value, options);
|
|
1769
|
+
this.device = new Device$1(token.value, options);
|
|
1718
1770
|
this.call = await this.device.connect({
|
|
1719
1771
|
params: {
|
|
1720
1772
|
From: callData.from,
|
|
@@ -3083,6 +3135,68 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3083
3135
|
}]
|
|
3084
3136
|
}] });
|
|
3085
3137
|
|
|
3138
|
+
class TwilioInitService {
|
|
3139
|
+
constructor(twilioService, extensionService) {
|
|
3140
|
+
this.twilioService = twilioService;
|
|
3141
|
+
this.extensionService = extensionService;
|
|
3142
|
+
}
|
|
3143
|
+
// Call this method when your application starts (e.g., in app.component.ts)
|
|
3144
|
+
async initializeTwilio() {
|
|
3145
|
+
try {
|
|
3146
|
+
// 1. Get a token from your backend
|
|
3147
|
+
const token = await this.getTwilioToken();
|
|
3148
|
+
if (!token) {
|
|
3149
|
+
console.error('Failed to get Twilio token');
|
|
3150
|
+
return;
|
|
3151
|
+
}
|
|
3152
|
+
// 2. Initialize the Twilio device with the token
|
|
3153
|
+
this.twilioService.initializeTwilioDevice(token);
|
|
3154
|
+
// 3. Set up token refresh (optional, but recommended)
|
|
3155
|
+
this.setupTokenRefresh();
|
|
3156
|
+
}
|
|
3157
|
+
catch (error) {
|
|
3158
|
+
console.error('Error initializing Twilio:', error);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
async getTwilioToken() {
|
|
3162
|
+
// Replace this with your actual token retrieval logic
|
|
3163
|
+
// Example:
|
|
3164
|
+
// return this.extensionService.getTwilioToken().toPromise();
|
|
3165
|
+
// For now, we'll get it from localStorage if it exists
|
|
3166
|
+
const token = localStorage.getItem('twilio_token');
|
|
3167
|
+
if (!token) {
|
|
3168
|
+
throw new Error('Twilio token not found');
|
|
3169
|
+
}
|
|
3170
|
+
return token;
|
|
3171
|
+
}
|
|
3172
|
+
setupTokenRefresh() {
|
|
3173
|
+
// Refresh token every 30 minutes (Twilio tokens typically expire after 1 hour)
|
|
3174
|
+
this.tokenRefreshInterval = setInterval(async () => {
|
|
3175
|
+
try {
|
|
3176
|
+
const newToken = await this.getTwilioToken();
|
|
3177
|
+
this.twilioService.updateToken(newToken);
|
|
3178
|
+
}
|
|
3179
|
+
catch (error) {
|
|
3180
|
+
console.error('Error refreshing Twilio token:', error);
|
|
3181
|
+
}
|
|
3182
|
+
}, 30 * 60 * 1000); // 30 minutes
|
|
3183
|
+
}
|
|
3184
|
+
ngOnDestroy() {
|
|
3185
|
+
// Clean up the interval when the service is destroyed
|
|
3186
|
+
if (this.tokenRefreshInterval) {
|
|
3187
|
+
clearInterval(this.tokenRefreshInterval);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
TwilioInitService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioInitService, deps: [{ token: TwilioService }, { token: ExtensionService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
3192
|
+
TwilioInitService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioInitService, providedIn: 'root' });
|
|
3193
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TwilioInitService, decorators: [{
|
|
3194
|
+
type: Injectable,
|
|
3195
|
+
args: [{
|
|
3196
|
+
providedIn: 'root'
|
|
3197
|
+
}]
|
|
3198
|
+
}], ctorParameters: function () { return [{ type: TwilioService }, { type: ExtensionService }]; } });
|
|
3199
|
+
|
|
3086
3200
|
/*
|
|
3087
3201
|
* Public API Surface of dialbox
|
|
3088
3202
|
*/
|
|
@@ -3091,5 +3205,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3091
3205
|
* Generated bundle index. Do not edit.
|
|
3092
3206
|
*/
|
|
3093
3207
|
|
|
3094
|
-
export { CallProgressComponent, CallerIdDialogComponent, DialboxComponent, DialboxModule, IncomingCallComponent };
|
|
3208
|
+
export { CallProgressComponent, CallerIdDialogComponent, DialboxComponent, DialboxModule, IncomingCallComponent, TwilioInitService };
|
|
3095
3209
|
//# sourceMappingURL=vgroup-dialbox.mjs.map
|