@unboundcx/sdk 1.0.0

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.
@@ -0,0 +1,380 @@
1
+ export class VideoService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ async clearToken() {
7
+ const params = {};
8
+ const result = await this.sdk._fetch(`/video/clearVideoToken`, 'POST', params, true);
9
+ return result;
10
+ }
11
+
12
+ async joinRoom(room, password, email) {
13
+ this.sdk.validateParams(
14
+ { room, password, email },
15
+ {
16
+ room: { type: 'string', required: true },
17
+ password: { type: 'string', required: false },
18
+ email: { type: 'string', required: false },
19
+ },
20
+ );
21
+
22
+ const params = {
23
+ body: {
24
+ password,
25
+ email,
26
+ tokenType: 'cookie',
27
+ },
28
+ };
29
+ const result = await this.sdk._fetch(`/video/${room}/join`, 'POST', params);
30
+ return result;
31
+ }
32
+
33
+ async updateParticipant(roomId, participantId, update) {
34
+ this.sdk.validateParams(
35
+ { roomId, participantId, update },
36
+ {
37
+ roomId: { type: 'string', required: true },
38
+ participantId: { type: 'string', required: true },
39
+ update: { type: 'object', required: true },
40
+ },
41
+ );
42
+ const params = {
43
+ body: {
44
+ ...update,
45
+ },
46
+ };
47
+ const result = await this.sdk._fetch(
48
+ `/video/${roomId}/${participantId}`,
49
+ 'PUT',
50
+ params,
51
+ );
52
+ return result;
53
+ }
54
+
55
+ async removeParticipant(roomId, participantId) {
56
+ this.sdk.validateParams(
57
+ { roomId, participantId },
58
+ {
59
+ roomId: { type: 'string', required: true },
60
+ participantId: { type: 'string', required: true },
61
+ },
62
+ );
63
+ const params = {
64
+ body: {
65
+ participantId,
66
+ },
67
+ };
68
+ const result = await this.sdk._fetch(
69
+ `/video/${roomId}/leave`,
70
+ 'DELETE',
71
+ params,
72
+ );
73
+ return result;
74
+ }
75
+
76
+ async leaveRoom(roomId) {
77
+ this.sdk.validateParams(
78
+ { roomId },
79
+ {
80
+ roomId: { type: 'string', required: true },
81
+ },
82
+ );
83
+ const params = {};
84
+ const result = await this.sdk._fetch(
85
+ `/video/${roomId}/leave`,
86
+ 'DELETE',
87
+ params,
88
+ );
89
+ return result;
90
+ }
91
+
92
+ async mute(
93
+ roomId,
94
+ participantId,
95
+ mediaType,
96
+ isMute,
97
+ noDevice = false,
98
+ streamCreation = false,
99
+ ) {
100
+ this.sdk.validateParams(
101
+ { roomId, participantId, mediaType, isMute, noDevice, streamCreation },
102
+ {
103
+ roomId: { type: 'string', required: true },
104
+ participantId: { type: 'string', required: true },
105
+ mediaType: { type: 'string', required: true }, // camera, microphone
106
+ isMute: { type: 'boolean', required: true },
107
+ noDevice: { type: 'boolean', required: false },
108
+ streamCreation: { type: 'boolean', required: false },
109
+ },
110
+ );
111
+ const params = {
112
+ body: {
113
+ isMute,
114
+ noDevice,
115
+ streamCreation,
116
+ },
117
+ };
118
+ const result = await this.sdk._fetch(
119
+ `/video/${roomId}/${participantId}/mute/${mediaType}`,
120
+ 'PUT',
121
+ params,
122
+ );
123
+ return result;
124
+ }
125
+
126
+ async createRoom({
127
+ name,
128
+ password,
129
+ startTime,
130
+ endTime,
131
+ duration,
132
+ durationUnit,
133
+ timezone,
134
+ waitingRoom,
135
+ hosts,
136
+ participants,
137
+ startCameraMuted,
138
+ startCameraMutedAfter,
139
+ startMicrophoneMuted,
140
+ startMicrophoneMutedAfter,
141
+ }) {
142
+ this.sdk.validateParams(
143
+ {
144
+ name,
145
+ password,
146
+ startTime,
147
+ endTime,
148
+ duration,
149
+ durationUnit,
150
+ timezone,
151
+ waitingRoom,
152
+ hosts,
153
+ participants,
154
+ startCameraMuted,
155
+ startCameraMutedAfter,
156
+ startMicrophoneMuted,
157
+ startMicrophoneMutedAfter,
158
+ },
159
+ {
160
+ name: { type: 'string', required: false },
161
+ password: { type: 'string', required: false },
162
+ startTime: { type: 'string', required: false },
163
+ endTime: { type: 'string', required: false },
164
+ duration: { type: 'number', required: false },
165
+ durationUnit: { type: 'string', required: false },
166
+ timezone: { type: 'string', required: false },
167
+ waitingRoom: { type: 'boolean', required: false },
168
+ hosts: { type: 'array', required: false },
169
+ participants: { type: 'array', required: false },
170
+ startCameraMuted: { type: 'boolean', required: false },
171
+ startCameraMutedAfter: { type: 'number', required: false },
172
+ startMicrophoneMuted: { type: 'boolean', required: false },
173
+ startMicrophoneMutedAfter: { type: 'number', required: false },
174
+ },
175
+ );
176
+ const params = {
177
+ body: {
178
+ name,
179
+ password,
180
+ startTime,
181
+ endTime,
182
+ duration,
183
+ durationUnit,
184
+ timezone,
185
+ waitingRoom,
186
+ hosts,
187
+ participants,
188
+ startCameraMuted,
189
+ startCameraMutedAfter,
190
+ startMicrophoneMuted,
191
+ startMicrophoneMutedAfter,
192
+ },
193
+ };
194
+ const result = await this.sdk._fetch(`/video`, 'POST', params);
195
+ return result;
196
+ }
197
+
198
+ async updateRoom(roomId, update) {
199
+ this.sdk.validateParams(
200
+ { roomId, update },
201
+ {
202
+ roomId: { type: 'string', required: true },
203
+ update: { type: 'object', required: true },
204
+ },
205
+ );
206
+
207
+ // Validate specific update fields if they exist
208
+ const validationSchema = {};
209
+ if ('name' in update) validationSchema.name = { type: 'string' };
210
+ if ('password' in update) validationSchema.password = { type: 'string' };
211
+ if ('startTime' in update) validationSchema.startTime = { type: 'string' };
212
+ if ('endTime' in update) validationSchema.endTime = { type: 'string' };
213
+ if ('timezone' in update) validationSchema.timezone = { type: 'string' };
214
+ if ('waitingRoom' in update) validationSchema.waitingRoom = { type: 'boolean' };
215
+ if ('hosts' in update) validationSchema.hosts = { type: 'array' };
216
+ if ('participants' in update) validationSchema.participants = { type: 'array' };
217
+ if ('startCameraMuted' in update) validationSchema.startCameraMuted = { type: 'boolean' };
218
+ if ('startCameraMutedAfter' in update) validationSchema.startCameraMutedAfter = { type: 'number' };
219
+ if ('startMicrophoneMuted' in update) validationSchema.startMicrophoneMuted = { type: 'boolean' };
220
+ if ('startMicrophoneMutedAfter' in update) validationSchema.startMicrophoneMutedAfter = { type: 'number' };
221
+
222
+ if (Object.keys(validationSchema).length > 0) {
223
+ this.sdk.validateParams(update, validationSchema);
224
+ }
225
+
226
+ const params = {
227
+ body: {
228
+ ...update,
229
+ },
230
+ };
231
+ const result = await this.sdk._fetch(`/video/${roomId}`, 'PUT', params);
232
+ return result;
233
+ }
234
+
235
+ async placeCall(roomId, phoneNumber, callerIdNumber) {
236
+ this.sdk.validateParams(
237
+ { roomId, phoneNumber, callerIdNumber },
238
+ {
239
+ roomId: { type: 'string', required: true },
240
+ phoneNumber: { type: 'string', required: true },
241
+ callerIdNumber: { type: 'string', required: false },
242
+ },
243
+ );
244
+
245
+ const params = {
246
+ body: {
247
+ phoneNumber,
248
+ callerIdNumber,
249
+ },
250
+ };
251
+ const result = await this.sdk._fetch(
252
+ `/video/${roomId}/placeOutboundCall`,
253
+ 'POST',
254
+ params,
255
+ );
256
+ return result;
257
+ }
258
+
259
+ async listMeetings(options = {}) {
260
+ // Validate optional parameters
261
+ const validationSchema = {};
262
+ if ('startDate' in options) validationSchema.startDate = { type: 'string' };
263
+ if ('endDate' in options) validationSchema.endDate = { type: 'string' };
264
+ if ('limit' in options) validationSchema.limit = { type: 'number' };
265
+ if ('offset' in options) validationSchema.offset = { type: 'number' };
266
+
267
+ if (Object.keys(validationSchema).length > 0) {
268
+ this.sdk.validateParams(options, validationSchema);
269
+ }
270
+
271
+ const params = {
272
+ query: options,
273
+ };
274
+
275
+ const result = await this.sdk._fetch('/video/meetings', 'GET', params);
276
+ return result;
277
+ }
278
+
279
+ async getMeetingAnalytics(roomId, params = {}) {
280
+ this.sdk.validateParams(
281
+ { roomId },
282
+ {
283
+ roomId: { type: 'string', required: true },
284
+ }
285
+ );
286
+
287
+ // Validate optional parameters
288
+ const validationSchema = {};
289
+ if ('participantId' in params) validationSchema.participantId = { type: 'string' };
290
+ if ('startTime' in params) validationSchema.startTime = { type: 'string' };
291
+ if ('endTime' in params) validationSchema.endTime = { type: 'string' };
292
+ if ('granularity' in params) validationSchema.granularity = { type: 'string' };
293
+ if ('timezone' in params) validationSchema.timezone = { type: 'string' };
294
+ if (Object.keys(validationSchema).length > 0) {
295
+ this.sdk.validateParams(params, validationSchema);
296
+ }
297
+
298
+ const options = {
299
+ query: params,
300
+ }
301
+
302
+ const result = await this.sdk._fetch(`/video/meetings/${roomId}/analytics`, 'GET', options);
303
+ return result;
304
+ }
305
+
306
+ async deleteRoom(roomId) {
307
+ this.sdk.validateParams(
308
+ { roomId },
309
+ {
310
+ roomId: { type: 'string', required: true },
311
+ },
312
+ );
313
+ const params = {};
314
+ const result = await this.sdk._fetch(`/video/${roomId}`, 'DELETE', params);
315
+ return result;
316
+ }
317
+
318
+ async addParticipant(roomId, participant) {
319
+ this.sdk.validateParams(
320
+ { roomId, participant },
321
+ {
322
+ roomId: { type: 'string', required: true },
323
+ participant: { type: 'object', required: true },
324
+ },
325
+ );
326
+
327
+ const params = {
328
+ body: participant,
329
+ };
330
+
331
+ const result = await this.sdk._fetch(`/video/${roomId}/participants`, 'POST', params);
332
+ return result;
333
+ }
334
+
335
+ async closeRoom(roomId) {
336
+ this.sdk.validateParams(
337
+ { roomId },
338
+ {
339
+ roomId: { type: 'string', required: true },
340
+ },
341
+ );
342
+
343
+ const params = {};
344
+ const result = await this.sdk._fetch(`/video/${roomId}/close`, 'POST', params);
345
+ return result;
346
+ }
347
+
348
+ async validateGuestToken(token) {
349
+ this.sdk.validateParams(
350
+ { token },
351
+ {
352
+ token: { type: 'string', required: true },
353
+ },
354
+ );
355
+
356
+ const params = {
357
+ body: { token },
358
+ };
359
+
360
+ const result = await this.sdk._fetch('/video/validateGuestToken', 'POST', params);
361
+ return result;
362
+ }
363
+
364
+ async logStats(roomId, stats) {
365
+ this.sdk.validateParams(
366
+ { roomId, stats },
367
+ {
368
+ roomId: { type: 'string', required: true },
369
+ stats: { type: 'object', required: true },
370
+ },
371
+ );
372
+
373
+ const params = {
374
+ body: stats,
375
+ };
376
+
377
+ const result = await this.sdk._fetch(`/video/${roomId}/stats`, 'POST', params);
378
+ return result;
379
+ }
380
+ }