@vgroup/dialbox 0.0.25 → 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/service/twilio-init.service.mjs +66 -0
- package/esm2020/lib/service/twilio.service.mjs +34 -49
- package/esm2020/public-api.mjs +3 -1
- package/fesm2015/vgroup-dialbox.mjs +101 -50
- package/fesm2015/vgroup-dialbox.mjs.map +1 -1
- package/fesm2020/vgroup-dialbox.mjs +96 -49
- 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 +1 -1
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
|
@@ -114,59 +114,44 @@ class TwilioService {
|
|
|
114
114
|
this.isAvailableNumber = new BehaviorSubject(false);
|
|
115
115
|
this.callerIdList = new BehaviorSubject([]);
|
|
116
116
|
this.triggerSMSReload = new BehaviorSubject(false);
|
|
117
|
-
this.initializeTwilioDevice();
|
|
118
117
|
}
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.
|
|
125
|
-
return;
|
|
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');
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.currentCallState.next('incoming');
|
|
146
|
-
this.callType.next('INCOMING');
|
|
147
|
-
// Set up call event handlers
|
|
148
|
-
call.on('accept', () => {
|
|
149
|
-
console.log('Call accepted');
|
|
150
|
-
this.currentCallState.next('in-progress');
|
|
151
|
-
this.isIncomingCallPicked.next(true);
|
|
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
|
|
152
143
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.currentCallState.next('none');
|
|
157
|
-
this.isIncomingCallPicked.next(false);
|
|
144
|
+
// Set up device event listeners
|
|
145
|
+
this.device.on('ready', (device) => {
|
|
146
|
+
console.log('Twilio Device Ready');
|
|
158
147
|
});
|
|
159
|
-
|
|
160
|
-
console.
|
|
161
|
-
this.
|
|
162
|
-
this.currentCallState.next('none');
|
|
148
|
+
this.device.on('error', (error) => {
|
|
149
|
+
console.error('Twilio Device Error:', error);
|
|
150
|
+
this.currentCallState.next('error');
|
|
163
151
|
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
updateToken(token) {
|
|
168
|
-
if (this.device) {
|
|
169
|
-
this.device.updateToken(token);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error('Error initializing Twilio device:', error);
|
|
170
155
|
}
|
|
171
156
|
}
|
|
172
157
|
saveContact(payload) {
|
|
@@ -3150,6 +3135,68 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3150
3135
|
}]
|
|
3151
3136
|
}] });
|
|
3152
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
|
+
|
|
3153
3200
|
/*
|
|
3154
3201
|
* Public API Surface of dialbox
|
|
3155
3202
|
*/
|
|
@@ -3158,5 +3205,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
3158
3205
|
* Generated bundle index. Do not edit.
|
|
3159
3206
|
*/
|
|
3160
3207
|
|
|
3161
|
-
export { CallProgressComponent, CallerIdDialogComponent, DialboxComponent, DialboxModule, IncomingCallComponent };
|
|
3208
|
+
export { CallProgressComponent, CallerIdDialogComponent, DialboxComponent, DialboxModule, IncomingCallComponent, TwilioInitService };
|
|
3162
3209
|
//# sourceMappingURL=vgroup-dialbox.mjs.map
|