@tarunzyraclavis/zyra-twilio-wrapper 1.0.0 → 1.0.9
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/dist/index.d.mts +38 -57
- package/dist/index.d.ts +38 -57
- package/dist/index.js +200 -297
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -297
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +352 -438
- package/types/interface.ts +4 -40
package/dist/index.js
CHANGED
|
@@ -70,19 +70,56 @@ function createErrorResult(error) {
|
|
|
70
70
|
|
|
71
71
|
// src/index.ts
|
|
72
72
|
var ZyraTwilioWrapper = class {
|
|
73
|
-
constructor(
|
|
73
|
+
constructor(config) {
|
|
74
74
|
this.device = null;
|
|
75
75
|
this.activeConnection = null;
|
|
76
76
|
this.isInitialized = false;
|
|
77
77
|
this.isInitializing = false;
|
|
78
|
+
this.isAuthenticated = false;
|
|
79
|
+
this.axiosInstance = import_axios2.default.create();
|
|
78
80
|
this.activeCallSid = null;
|
|
79
81
|
this.conferenceDetail = null;
|
|
80
82
|
this.participants = [];
|
|
81
83
|
this.waitUrl = "https://api.twilio.com/cowbell.mp3";
|
|
82
|
-
this.serverUrl =
|
|
83
|
-
this.identity =
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
84
|
+
this.serverUrl = config.serverUrl;
|
|
85
|
+
this.identity = config.identity;
|
|
86
|
+
this.sdkToken = config.sdkToken;
|
|
87
|
+
this.waitUrl = config.waitUrl || this.waitUrl;
|
|
88
|
+
this.conferenceName = `conf_${this.identity}_${Date.now()}`;
|
|
89
|
+
}
|
|
90
|
+
/* ------------------------------------------------------------------ */
|
|
91
|
+
/* AUTH */
|
|
92
|
+
/* ------------------------------------------------------------------ */
|
|
93
|
+
setupAxiosAuth(token) {
|
|
94
|
+
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
95
|
+
}
|
|
96
|
+
ensureAuthenticated() {
|
|
97
|
+
if (!this.isAuthenticated) {
|
|
98
|
+
throw new Error("SDK not authenticated.");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async verifySDKToken() {
|
|
102
|
+
if (!this.sdkToken) {
|
|
103
|
+
throw new Error("SDK token not provided");
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const res = await this.axiosInstance.post(
|
|
107
|
+
`${this.serverUrl}/voipSdk.verifySdkToken`,
|
|
108
|
+
{},
|
|
109
|
+
{ headers: { Authorization: `Bearer ${this.sdkToken}` } }
|
|
110
|
+
);
|
|
111
|
+
console.log("verifySDKToken :", res.data.result.data.verified);
|
|
112
|
+
if (res?.data?.result?.data?.verified) {
|
|
113
|
+
this.isAuthenticated = true;
|
|
114
|
+
this.setupAxiosAuth(this.sdkToken);
|
|
115
|
+
console.info("[verifySDKToken] SDK token verified");
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
throw new Error("Invalid SDK token");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
this.isAuthenticated = false;
|
|
121
|
+
throw new Error("SDK authentication failed");
|
|
122
|
+
}
|
|
86
123
|
}
|
|
87
124
|
// /**
|
|
88
125
|
// * Initialize the Twilio device and get token
|
|
@@ -94,31 +131,21 @@ var ZyraTwilioWrapper = class {
|
|
|
94
131
|
* @returns Promise that resolves when initialization is complete
|
|
95
132
|
*/
|
|
96
133
|
async init() {
|
|
134
|
+
this.ensureAuthenticated();
|
|
97
135
|
if (this.isInitialized) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
"SDK is already initialized. Call destroy() first to reinitialize."
|
|
100
|
-
);
|
|
136
|
+
throw new Error("SDK already initialized");
|
|
101
137
|
}
|
|
102
138
|
if (this.isInitializing) {
|
|
103
|
-
throw new Error("SDK initialization
|
|
139
|
+
throw new Error("SDK initialization already in progress");
|
|
104
140
|
}
|
|
105
141
|
this.isInitializing = true;
|
|
106
142
|
try {
|
|
107
|
-
if (!this.serverUrl) {
|
|
108
|
-
throw new Error("serverUrl is required");
|
|
109
|
-
}
|
|
110
|
-
if (!this.identity) {
|
|
111
|
-
throw new Error("identity is required");
|
|
112
|
-
}
|
|
113
143
|
const token = await this.generateToken();
|
|
114
|
-
this.device = new import_voice_sdk.Device(token, { logLevel:
|
|
144
|
+
this.device = new import_voice_sdk.Device(token, { logLevel: "info" });
|
|
115
145
|
this.setupDeviceEventHandlers();
|
|
116
146
|
await this.device.register();
|
|
117
147
|
this.isInitialized = true;
|
|
118
|
-
console.info("[init] Device
|
|
119
|
-
} catch (error) {
|
|
120
|
-
handleAxiosError(error, this.onError, "Failed to fetch token");
|
|
121
|
-
throw error;
|
|
148
|
+
console.info("[init] Device registered");
|
|
122
149
|
} finally {
|
|
123
150
|
this.isInitializing = false;
|
|
124
151
|
}
|
|
@@ -127,341 +154,217 @@ var ZyraTwilioWrapper = class {
|
|
|
127
154
|
async generateToken() {
|
|
128
155
|
try {
|
|
129
156
|
const payload = {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
157
|
+
json: {
|
|
158
|
+
identity: this.identity,
|
|
159
|
+
ttl: 3600,
|
|
160
|
+
incomingAllow: true
|
|
161
|
+
}
|
|
133
162
|
};
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
163
|
+
console.log("Generating token with payload:", payload);
|
|
164
|
+
const res = await this.axiosInstance.post(
|
|
165
|
+
`${this.serverUrl}/voipSdk.generateToken`,
|
|
166
|
+
payload
|
|
167
|
+
);
|
|
168
|
+
const token = res?.data?.result?.data?.token;
|
|
169
|
+
if (!token) throw new Error("Token missing");
|
|
139
170
|
return token;
|
|
140
171
|
} catch (error) {
|
|
141
|
-
handleAxiosError(error, this.onError, "
|
|
172
|
+
handleAxiosError(error, this.onError, "Token generation failed");
|
|
142
173
|
throw error;
|
|
143
174
|
}
|
|
144
175
|
}
|
|
145
|
-
// Private methods for handling the event for device
|
|
146
176
|
setupDeviceEventHandlers() {
|
|
147
177
|
if (!this.device) return;
|
|
148
|
-
this.device.on("registered", () =>
|
|
149
|
-
console.info("[Device] Registered");
|
|
150
|
-
this.onReady?.();
|
|
151
|
-
});
|
|
178
|
+
this.device.on("registered", () => this.onReady?.());
|
|
152
179
|
this.device.on("incoming", (conn) => {
|
|
153
|
-
|
|
180
|
+
this.activeConnection = conn;
|
|
154
181
|
conn.on("cancel", () => {
|
|
155
|
-
console.warn("[Device] Caller hung up before answer");
|
|
156
182
|
this.activeConnection = null;
|
|
157
183
|
this.onMissedCall?.();
|
|
158
184
|
});
|
|
159
|
-
conn.on("reject", () =>
|
|
160
|
-
console.warn("[Device] Call rejected");
|
|
161
|
-
this.activeConnection = null;
|
|
162
|
-
});
|
|
185
|
+
conn.on("reject", () => this.activeConnection = null);
|
|
163
186
|
conn.on("accept", () => console.info("[Device] Call accepted"));
|
|
164
|
-
this.activeConnection = conn;
|
|
165
187
|
this.onIncoming?.(conn);
|
|
166
188
|
});
|
|
167
|
-
this.device.on("disconnect", () => {
|
|
168
|
-
console.info("[Device] Call disconnected");
|
|
169
|
-
this.activeConnection = null;
|
|
170
|
-
this.onDisconnect?.();
|
|
171
|
-
});
|
|
172
189
|
this.device.on("connect", (conn) => {
|
|
173
|
-
console.info("[Device] Call connected");
|
|
174
190
|
this.activeConnection = conn;
|
|
175
191
|
this.onConnect?.(conn);
|
|
176
192
|
});
|
|
193
|
+
this.device.on("disconnect", () => {
|
|
194
|
+
this.activeConnection = null;
|
|
195
|
+
this.onDisconnect?.();
|
|
196
|
+
});
|
|
177
197
|
this.device.on("error", (error) => {
|
|
178
|
-
handleAxiosError(error, this.onError, "Device
|
|
198
|
+
handleAxiosError(error, this.onError, "Device error");
|
|
199
|
+
});
|
|
200
|
+
this.device.on("tokenWillExpire", async () => {
|
|
201
|
+
const token = await this.generateToken();
|
|
202
|
+
this.device?.updateToken(token);
|
|
179
203
|
});
|
|
180
204
|
}
|
|
205
|
+
/* ------------------------------------------------------------------ */
|
|
206
|
+
/* CALL CONTROL */
|
|
207
|
+
/* ------------------------------------------------------------------ */
|
|
181
208
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
get initialized() {
|
|
185
|
-
return this.isInitialized;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Destroy the SDK instance and clean up resources
|
|
189
|
-
*/
|
|
190
|
-
destroy() {
|
|
191
|
-
if (this.device) {
|
|
192
|
-
this.device.removeAllListeners();
|
|
193
|
-
this.device.on("error", (error) => {
|
|
194
|
-
handleAxiosError(error, this.onError, "Device encountered an error during destroy");
|
|
195
|
-
});
|
|
196
|
-
this.device.on("tokenWillExpire", async () => {
|
|
197
|
-
const token = await this.generateToken();
|
|
198
|
-
this.device?.updateToken(token);
|
|
199
|
-
});
|
|
200
|
-
this.device.destroy();
|
|
201
|
-
this.device = null;
|
|
202
|
-
}
|
|
203
|
-
this.isInitialized = false;
|
|
204
|
-
this.isInitializing = false;
|
|
205
|
-
this.activeConnection = null;
|
|
206
|
-
console.info("[destroy] Device destroyed and SDK state reset");
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Make an outgoing call or add participant to an existing call
|
|
210
|
-
*/
|
|
209
|
+
* Make an outgoing call or add participant to an existing call
|
|
210
|
+
*/
|
|
211
211
|
async makeCall(to) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (!to) {
|
|
216
|
-
console.warn("[makeCall] 'to' parameter is required");
|
|
217
|
-
return createErrorResult("[makeCall] 'to' parameter is required");
|
|
218
|
-
}
|
|
212
|
+
this.ensureAuthenticated();
|
|
213
|
+
if (!this.device) return createErrorResult("Device not initialized");
|
|
214
|
+
if (!to) return createErrorResult("Destination required");
|
|
219
215
|
if (!this.activeConnection) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
await this.getConferenceId();
|
|
230
|
-
});
|
|
231
|
-
connection.on("error", (error) => {
|
|
232
|
-
console.error("[makeCall] Connection error:", error.message);
|
|
233
|
-
this.onError?.(error);
|
|
234
|
-
});
|
|
235
|
-
connection.on("disconnect", () => {
|
|
236
|
-
console.info("[makeCall] Call disconnected.");
|
|
237
|
-
this.activeConnection = null;
|
|
238
|
-
this.onDisconnect?.();
|
|
239
|
-
});
|
|
240
|
-
console.info(`[makeCall] Outgoing call initiated to: ${to}`);
|
|
241
|
-
return createSuccessResult(`[makeCall] Outgoing call initiated to: ${to}`, connection);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
244
|
-
console.error("[makeCall] Failed to initiate call:", err.message);
|
|
245
|
-
this.onError?.(err);
|
|
246
|
-
return createErrorResult(`[makeCall] Failed to initiate call: ${err.message}`);
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
try {
|
|
250
|
-
console.info("[makeCall] Active call found. Holding and adding new participant...");
|
|
251
|
-
await this.holdAndAddParticipant(this.activeConnection.parameters.CallSid, to);
|
|
252
|
-
return createSuccessResult(`[makeCall] Outgoing participant ${to} added`, this.activeConnection);
|
|
253
|
-
} catch (error) {
|
|
254
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
255
|
-
console.error("[makeCall] Failed to add participant:", err.message);
|
|
256
|
-
this.onError?.(err);
|
|
257
|
-
return createErrorResult(`[makeCall] Failed to add participant: ${err.message}`);
|
|
258
|
-
}
|
|
216
|
+
const conn = await this.device.connect({
|
|
217
|
+
params: { To: to, conferenceName: this.conferenceName }
|
|
218
|
+
});
|
|
219
|
+
this.activeConnection = conn;
|
|
220
|
+
conn.on("accept", async () => {
|
|
221
|
+
this.activeCallSid = conn.parameters?.CallSid ?? null;
|
|
222
|
+
await this.getConferenceId();
|
|
223
|
+
});
|
|
224
|
+
return createSuccessResult("Call started", conn);
|
|
259
225
|
}
|
|
226
|
+
await this.holdAndAddParticipant(
|
|
227
|
+
this.activeConnection.parameters.CallSid,
|
|
228
|
+
to
|
|
229
|
+
);
|
|
230
|
+
return createSuccessResult("Participant added", this.activeConnection);
|
|
260
231
|
}
|
|
261
232
|
/**
|
|
262
|
-
|
|
263
|
-
|
|
233
|
+
* Accept incoming call
|
|
234
|
+
*/
|
|
264
235
|
acceptCall() {
|
|
265
|
-
if (!this.
|
|
266
|
-
|
|
267
|
-
console.warn(`[acceptCall] ${msg}`);
|
|
268
|
-
return createErrorResult(`[acceptCall] ${msg}`);
|
|
269
|
-
}
|
|
270
|
-
try {
|
|
271
|
-
this.activeConnection.accept();
|
|
272
|
-
console.info("[acceptCall] Call accepted successfully.");
|
|
273
|
-
return createSuccessResult("Call accepted successfully.", this.activeConnection);
|
|
274
|
-
} catch (error) {
|
|
275
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
276
|
-
console.error("[acceptCall] Failed:", err.message);
|
|
277
|
-
this.onError?.(err);
|
|
278
|
-
return createErrorResult(`[acceptCall] Failed: ${err.message}`);
|
|
236
|
+
if (!this.activeConnection) {
|
|
237
|
+
return createErrorResult("No incoming call");
|
|
279
238
|
}
|
|
239
|
+
this.activeConnection.accept();
|
|
240
|
+
return createSuccessResult("Call accepted", this.activeConnection);
|
|
280
241
|
}
|
|
281
242
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
243
|
+
* Hang up active call
|
|
244
|
+
*/
|
|
284
245
|
hangup() {
|
|
285
|
-
if (!this.device
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
this.device.disconnectAll();
|
|
292
|
-
this.activeConnection = null;
|
|
293
|
-
console.info("[hangup] Call hung up successfully.");
|
|
294
|
-
return createSuccessResult("Call hung up successfully.", this.activeConnection);
|
|
295
|
-
} catch (error) {
|
|
296
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
297
|
-
console.error("[hangup] Failed:", err.message);
|
|
298
|
-
this.onError?.(err);
|
|
299
|
-
return createErrorResult(`Failed to hang up: ${err.message}`);
|
|
300
|
-
}
|
|
246
|
+
if (!this.device) return createErrorResult("Device not initialized");
|
|
247
|
+
this.device.disconnectAll();
|
|
248
|
+
this.activeConnection = null;
|
|
249
|
+
return createSuccessResult("Call ended", null);
|
|
301
250
|
}
|
|
302
251
|
/**
|
|
303
|
-
|
|
304
|
-
|
|
252
|
+
* Reject incoming call
|
|
253
|
+
*/
|
|
305
254
|
rejectCall() {
|
|
306
|
-
if (!this.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
try {
|
|
312
|
-
this.activeConnection.reject();
|
|
313
|
-
this.activeConnection = null;
|
|
314
|
-
console.info("[rejectCall] Call rejected successfully.");
|
|
315
|
-
return createSuccessResult("[rejectCall] Call rejected successfully.", this.activeConnection);
|
|
316
|
-
} catch (error) {
|
|
317
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
318
|
-
console.error("[rejectCall] Failed:", err.message);
|
|
319
|
-
this.onError?.(err);
|
|
320
|
-
return createErrorResult(`Failed to reject call: ${err.message}`);
|
|
321
|
-
}
|
|
255
|
+
if (!this.activeConnection) return createErrorResult("No call to reject");
|
|
256
|
+
this.activeConnection.reject();
|
|
257
|
+
this.activeConnection = null;
|
|
258
|
+
return createSuccessResult("Call rejected", null);
|
|
322
259
|
}
|
|
323
260
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
261
|
+
* Toggle mute/unmute
|
|
262
|
+
*/
|
|
326
263
|
toggleMute(mute) {
|
|
327
|
-
if (!this.activeConnection)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
try {
|
|
332
|
-
this.activeConnection.mute(mute);
|
|
333
|
-
console.info(`[toggleMute] Call ${mute ? "muted" : "unmuted"} successfully.`);
|
|
334
|
-
return createSuccessResult(`Call ${mute ? "muted" : "unmuted"} successfully.`, this.activeConnection);
|
|
335
|
-
} catch (error) {
|
|
336
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
337
|
-
console.error("[toggleMute] Failed:", err.message);
|
|
338
|
-
this.onError?.(err);
|
|
339
|
-
return createErrorResult(`Failed to toggle mute: ${err.message}`);
|
|
340
|
-
}
|
|
264
|
+
if (!this.activeConnection) return createErrorResult("No active call");
|
|
265
|
+
this.activeConnection.mute(mute);
|
|
266
|
+
return createSuccessResult(`Mute ${mute}`, this.activeConnection);
|
|
341
267
|
}
|
|
268
|
+
/* ------------------------------------------------------------------ */
|
|
269
|
+
/* CONFERENCE API */
|
|
270
|
+
/* ------------------------------------------------------------------ */
|
|
342
271
|
/**
|
|
343
|
-
|
|
344
|
-
|
|
272
|
+
* Hold a call
|
|
273
|
+
*/
|
|
345
274
|
async hold(callSid) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
handleAxiosError(error, this.onError, "Failed to hold call");
|
|
355
|
-
const errMessage = error instanceof Error ? error.message : String(error);
|
|
356
|
-
return createErrorResult(`Failed to hold call: ${errMessage}`);
|
|
357
|
-
}
|
|
275
|
+
this.ensureAuthenticated();
|
|
276
|
+
const payload = {
|
|
277
|
+
callSid,
|
|
278
|
+
conferenceName: this.conferenceName,
|
|
279
|
+
waitUrl: this.waitUrl
|
|
280
|
+
};
|
|
281
|
+
await this.axiosInstance.post(`${this.serverUrl}/outgoingCall.hold`, payload);
|
|
282
|
+
return createSuccessResult("Call held", this.activeConnection);
|
|
358
283
|
}
|
|
359
284
|
/**
|
|
360
|
-
|
|
361
|
-
|
|
285
|
+
* Resume a held call
|
|
286
|
+
*/
|
|
362
287
|
async resume(callSid) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return createErrorResult(`Failed to resume call: ${errMessage}`);
|
|
374
|
-
}
|
|
288
|
+
this.ensureAuthenticated();
|
|
289
|
+
const payload = {
|
|
290
|
+
callSid,
|
|
291
|
+
conferenceName: this.conferenceName
|
|
292
|
+
};
|
|
293
|
+
await this.axiosInstance.post(
|
|
294
|
+
`${this.serverUrl}/outgoingCall.unhold`,
|
|
295
|
+
payload
|
|
296
|
+
);
|
|
297
|
+
return createSuccessResult("Call resumed", this.activeConnection);
|
|
375
298
|
}
|
|
376
299
|
/**
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
async holdAndAddParticipant(callSid,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
status: true,
|
|
392
|
-
holdResponse: holdRes.data,
|
|
393
|
-
addParticipantResponse: addRes.data
|
|
394
|
-
};
|
|
395
|
-
} catch (error) {
|
|
396
|
-
handleAxiosError(error, this.onError, "Failed to hold and add participant");
|
|
397
|
-
const errMessage = error instanceof Error ? error.message : String(error);
|
|
398
|
-
return createErrorResult(`Failed to hold/add participant: ${errMessage}`);
|
|
399
|
-
}
|
|
300
|
+
* Hold active call and add a new participant
|
|
301
|
+
*/
|
|
302
|
+
async holdAndAddParticipant(callSid, number) {
|
|
303
|
+
this.ensureAuthenticated();
|
|
304
|
+
await this.hold(callSid);
|
|
305
|
+
const payload = {
|
|
306
|
+
conferenceName: this.conferenceName,
|
|
307
|
+
newParticipantNo: number
|
|
308
|
+
};
|
|
309
|
+
const res = await this.axiosInstance.post(
|
|
310
|
+
`${this.serverUrl}/outgoingCall.addNewCallee`,
|
|
311
|
+
payload
|
|
312
|
+
);
|
|
313
|
+
return createSuccessResult("Participant added", res.data);
|
|
400
314
|
}
|
|
401
315
|
/**
|
|
402
|
-
|
|
403
|
-
|
|
316
|
+
* Fetch conference details
|
|
317
|
+
*/
|
|
404
318
|
async getConferenceId() {
|
|
405
|
-
|
|
406
|
-
const payload = {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
console.info("[getConferenceId] Conference details fetched successfully.");
|
|
416
|
-
return createSuccessResult("Call resumed successfully.", confDetails);
|
|
417
|
-
}
|
|
418
|
-
console.warn("[getConferenceId] No conference data returned from server.");
|
|
419
|
-
return { message: "No conference data returned.", status: false };
|
|
420
|
-
} catch (error) {
|
|
421
|
-
handleAxiosError(error, this.onError, "Failed to get conference ID");
|
|
422
|
-
const errMessage = error instanceof Error ? error.message : String(error);
|
|
423
|
-
return createErrorResult(`Failed to get conference ID: ${errMessage}`);
|
|
424
|
-
}
|
|
319
|
+
this.ensureAuthenticated();
|
|
320
|
+
const payload = {
|
|
321
|
+
conferenceName: this.conferenceName
|
|
322
|
+
};
|
|
323
|
+
const res = await this.axiosInstance.post(
|
|
324
|
+
`${this.serverUrl}/outgoingCall.getConferenceId`,
|
|
325
|
+
payload
|
|
326
|
+
);
|
|
327
|
+
this.conferenceDetail = res?.data?.result?.data ?? null;
|
|
328
|
+
return createSuccessResult("Conference fetched", this.conferenceDetail);
|
|
425
329
|
}
|
|
426
330
|
/**
|
|
427
|
-
|
|
428
|
-
|
|
331
|
+
* Get participants of a conference
|
|
332
|
+
*/
|
|
429
333
|
async getParticipants(conferenceSid) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return createSuccessResult("Participants fetched successfully.", this.participants);
|
|
439
|
-
}
|
|
440
|
-
console.warn("[getParticipants] No participants returned from server.");
|
|
441
|
-
return { message: "No participants returned.", status: false };
|
|
442
|
-
} catch (error) {
|
|
443
|
-
handleAxiosError(error, this.onError, "Failed to get participants");
|
|
444
|
-
const errMessage = error instanceof Error ? error.message : String(error);
|
|
445
|
-
return createErrorResult(`Failed to get participants: ${errMessage}`);
|
|
446
|
-
}
|
|
334
|
+
this.ensureAuthenticated();
|
|
335
|
+
const payload = { conferenceSid };
|
|
336
|
+
const res = await this.axiosInstance.post(
|
|
337
|
+
`${this.serverUrl}/outgoingCall.getParticipants`,
|
|
338
|
+
payload
|
|
339
|
+
);
|
|
340
|
+
this.participants = res?.data?.result?.data?.participants ?? [];
|
|
341
|
+
return createSuccessResult("Participants fetched", this.participants);
|
|
447
342
|
}
|
|
448
343
|
/**
|
|
449
|
-
|
|
450
|
-
|
|
344
|
+
* Remove a participant from a conference
|
|
345
|
+
*/
|
|
451
346
|
async removeParticipant(conferenceSid, callSid) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
347
|
+
this.ensureAuthenticated();
|
|
348
|
+
const payload = { conferenceSid, callSid };
|
|
349
|
+
const res = await this.axiosInstance.post(
|
|
350
|
+
`${this.serverUrl}/outgoingCall.removeParticipant`,
|
|
351
|
+
payload
|
|
352
|
+
);
|
|
353
|
+
return createSuccessResult("Participant removed", res.data);
|
|
354
|
+
}
|
|
355
|
+
/* ------------------------------------------------------------------ */
|
|
356
|
+
/* CLEANUP */
|
|
357
|
+
/* ------------------------------------------------------------------ */
|
|
358
|
+
destroy() {
|
|
359
|
+
if (this.device) {
|
|
360
|
+
this.device.removeAllListeners();
|
|
361
|
+
this.device.destroy();
|
|
362
|
+
this.device = null;
|
|
464
363
|
}
|
|
364
|
+
this.activeConnection = null;
|
|
365
|
+
this.isInitialized = false;
|
|
366
|
+
this.isInitializing = false;
|
|
367
|
+
this.isAuthenticated = false;
|
|
465
368
|
}
|
|
466
369
|
};
|
|
467
370
|
//# sourceMappingURL=index.js.map
|