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