@fastpix/fastpix-node 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.
- package/LICENSE +201 -0
- package/README.md +509 -0
- package/dist/Live/index.d.ts +19 -0
- package/dist/Live/index.js +200 -0
- package/dist/NetworkFetcher/index.d.ts +7 -0
- package/dist/NetworkFetcher/index.js +74 -0
- package/dist/VideoOnDemand/index.d.ts +16 -0
- package/dist/VideoOnDemand/index.js +166 -0
- package/dist/index.cjs +635 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +166 -0
- package/dist/index.mjs +614 -0
- package/docs/Live/CreateLiveStream.md +48 -0
- package/docs/Live/ManageLiveStreams.md +116 -0
- package/docs/Live/ManageStreamPlayback.md +86 -0
- package/docs/Live/ManageStreamSimulcast.md +133 -0
- package/docs/VideoOnDemand/ManageMedia.md +147 -0
- package/docs/VideoOnDemand/ManageMediaPlayback.md +61 -0
- package/docs/VideoOnDemand/UploadMedia.md +320 -0
- package/package.json +37 -0
- package/types/index.d.ts +217 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { Buffer } from "buffer";
|
|
3
|
+
|
|
4
|
+
// src/NetworkFetcher/index.ts
|
|
5
|
+
var Fetcher = class {
|
|
6
|
+
// Fetches data from the specified URL using the provided headers.
|
|
7
|
+
async fetchData(url, header) {
|
|
8
|
+
if (!url || !header) {
|
|
9
|
+
throw new Error("Invalid arguments: URL and header are required.");
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const response = await fetch(url, header);
|
|
13
|
+
if (response.ok) {
|
|
14
|
+
const successResponse = await response.json();
|
|
15
|
+
return successResponse;
|
|
16
|
+
}
|
|
17
|
+
if ([400, 401, 403, 404, 409, 422].includes(response.status)) {
|
|
18
|
+
const errorResponse = await response.json();
|
|
19
|
+
const configErrorResponse = {
|
|
20
|
+
success: false,
|
|
21
|
+
error: {
|
|
22
|
+
code: response.status,
|
|
23
|
+
message: errorResponse?.error?.message ?? response.statusText ?? "An unexpected error occurred"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
if (errorResponse?.error?.fields) {
|
|
27
|
+
configErrorResponse.error.fields = errorResponse.error.fields;
|
|
28
|
+
}
|
|
29
|
+
return configErrorResponse;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
error: {
|
|
34
|
+
code: response.status ?? 500,
|
|
35
|
+
message: response.statusText ?? "An internal server error occurred."
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`An error occurred while fetching data: ${error?.message ?? "Internal error"}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Constructs a complete URL based on the provided request object, path, and query parameters.
|
|
45
|
+
constructUrl(requestObj, path = "", queryParams = "") {
|
|
46
|
+
const protocol = requestObj?.httpAgent ?? "https";
|
|
47
|
+
const domain = requestObj?.domain ?? "v1.fastpix.io";
|
|
48
|
+
return `${protocol}://${domain}/${path}${queryParams}`;
|
|
49
|
+
}
|
|
50
|
+
// Constructs HTTP headers for a request based on the provided request object.
|
|
51
|
+
constructHeaders(requestObj) {
|
|
52
|
+
if (!requestObj?.encodedAuthToken) {
|
|
53
|
+
throw new Error("Authorization credentials are missing.");
|
|
54
|
+
}
|
|
55
|
+
const method = requestObj?.method ?? "GET";
|
|
56
|
+
const headers = {
|
|
57
|
+
"Content-Type": "application/json",
|
|
58
|
+
Authorization: `Basic ${requestObj.encodedAuthToken}`
|
|
59
|
+
};
|
|
60
|
+
const requestOptions = {
|
|
61
|
+
method,
|
|
62
|
+
headers
|
|
63
|
+
};
|
|
64
|
+
if (method !== "GET" && method !== "DELETE" && requestObj?.body) {
|
|
65
|
+
requestOptions.body = JSON.stringify(requestObj.body);
|
|
66
|
+
}
|
|
67
|
+
return requestOptions;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var NetworkFetcher_default = Fetcher;
|
|
71
|
+
|
|
72
|
+
// src/VideoOnDemand/index.ts
|
|
73
|
+
var Media = class {
|
|
74
|
+
constructor() {
|
|
75
|
+
this.fetch = new NetworkFetcher_default();
|
|
76
|
+
this.mediaPath = "on-demand";
|
|
77
|
+
}
|
|
78
|
+
// Creates a new media asset.
|
|
79
|
+
async createAsset(requestObj, props = {}) {
|
|
80
|
+
const path = this.mediaPath;
|
|
81
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
82
|
+
const { accessPolicy = "public", ...restProps } = props;
|
|
83
|
+
const constructObject = {
|
|
84
|
+
...requestObj,
|
|
85
|
+
method: "POST",
|
|
86
|
+
body: {
|
|
87
|
+
accessPolicy,
|
|
88
|
+
...restProps
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const createAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
92
|
+
const createUrlAsset = await this.fetch.fetchData(url, createAssetHeader);
|
|
93
|
+
return createUrlAsset;
|
|
94
|
+
}
|
|
95
|
+
// Uploads a media asset using direct upload.
|
|
96
|
+
async uploadAsset(requestObj, props = {
|
|
97
|
+
corsOrigin: "",
|
|
98
|
+
pushMediaSettings: {
|
|
99
|
+
accessPolicy: "public",
|
|
100
|
+
// Default access policy
|
|
101
|
+
inputs: []
|
|
102
|
+
// Default empty array for inputs (inside pushMediaSettings)
|
|
103
|
+
}
|
|
104
|
+
}) {
|
|
105
|
+
const path = `${this.mediaPath}/uploads`;
|
|
106
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
107
|
+
const {
|
|
108
|
+
corsOrigin = "*",
|
|
109
|
+
pushMediaSettings = { accessPolicy: "public" },
|
|
110
|
+
...restProps
|
|
111
|
+
} = props;
|
|
112
|
+
const { accessPolicy = "public", ...restPushMediaSettings } = pushMediaSettings;
|
|
113
|
+
const constructObject = {
|
|
114
|
+
...requestObj,
|
|
115
|
+
method: "POST",
|
|
116
|
+
body: {
|
|
117
|
+
corsOrigin,
|
|
118
|
+
pushMediaSettings: {
|
|
119
|
+
accessPolicy,
|
|
120
|
+
...restPushMediaSettings
|
|
121
|
+
},
|
|
122
|
+
...restProps
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const uploadAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
126
|
+
const uploadMediaAsset = await this.fetch.fetchData(url, uploadAssetHeader);
|
|
127
|
+
return uploadMediaAsset;
|
|
128
|
+
}
|
|
129
|
+
// Retrieves all media assets with pagination support.
|
|
130
|
+
async getAllAssets(props, requestObj) {
|
|
131
|
+
const path = this.mediaPath;
|
|
132
|
+
const queryParams = `?limit=${props?.limit ?? 10}&offset=${props?.offset ?? 1}&orderBy=${props?.orderBy ?? "desc"}`;
|
|
133
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
134
|
+
const constructObject = {
|
|
135
|
+
...requestObj,
|
|
136
|
+
method: "GET"
|
|
137
|
+
};
|
|
138
|
+
const getAllAssetsHeader = this.fetch.constructHeaders(constructObject);
|
|
139
|
+
const assetsResponse = await this.fetch.fetchData(url, getAllAssetsHeader);
|
|
140
|
+
return assetsResponse;
|
|
141
|
+
}
|
|
142
|
+
// Retrieves details of a specific media asset.
|
|
143
|
+
async getAsset(props, requestObj) {
|
|
144
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}`;
|
|
145
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
146
|
+
const constructObject = {
|
|
147
|
+
...requestObj,
|
|
148
|
+
method: "GET"
|
|
149
|
+
};
|
|
150
|
+
const getAssetsHeader = this.fetch.constructHeaders(constructObject);
|
|
151
|
+
const assetsResponse = await this.fetch.fetchData(url, getAssetsHeader);
|
|
152
|
+
return assetsResponse;
|
|
153
|
+
}
|
|
154
|
+
// Retrieves detailed information about a media asset's input.
|
|
155
|
+
async getAssetInfo(props, requestObj) {
|
|
156
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}/input-info`;
|
|
157
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
158
|
+
const constructObject = {
|
|
159
|
+
...requestObj,
|
|
160
|
+
method: "GET"
|
|
161
|
+
};
|
|
162
|
+
const getAssetInfoHeader = this.fetch.constructHeaders(constructObject);
|
|
163
|
+
const assetInfoResponse = await this.fetch.fetchData(
|
|
164
|
+
url,
|
|
165
|
+
getAssetInfoHeader
|
|
166
|
+
);
|
|
167
|
+
return assetInfoResponse;
|
|
168
|
+
}
|
|
169
|
+
// Updates the details of a media asset.
|
|
170
|
+
async updateAsset(props, updateObject, requestObj) {
|
|
171
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}`;
|
|
172
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
173
|
+
const constructObject = {
|
|
174
|
+
...requestObj,
|
|
175
|
+
method: "PATCH",
|
|
176
|
+
body: {
|
|
177
|
+
...updateObject ?? {}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const updateAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
181
|
+
const updateAssetResponse = await this.fetch.fetchData(
|
|
182
|
+
url,
|
|
183
|
+
updateAssetHeader
|
|
184
|
+
);
|
|
185
|
+
return updateAssetResponse;
|
|
186
|
+
}
|
|
187
|
+
// Deletes a media asset.
|
|
188
|
+
async deleteAsset(props, requestObj) {
|
|
189
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}`;
|
|
190
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
191
|
+
const constructObject = {
|
|
192
|
+
...requestObj,
|
|
193
|
+
method: "DELETE"
|
|
194
|
+
};
|
|
195
|
+
const deleteAssetHeader = this.fetch.constructHeaders(constructObject);
|
|
196
|
+
const deleteAssetResponse = await this.fetch.fetchData(
|
|
197
|
+
url,
|
|
198
|
+
deleteAssetHeader
|
|
199
|
+
);
|
|
200
|
+
return deleteAssetResponse;
|
|
201
|
+
}
|
|
202
|
+
// Adds a playback ID to a media asset with a specific access policy.
|
|
203
|
+
async addMediaPlaybackId(props, playbackPolicy, requestObj) {
|
|
204
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}/playback-ids`;
|
|
205
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
206
|
+
const constructObject = {
|
|
207
|
+
...requestObj,
|
|
208
|
+
method: "POST",
|
|
209
|
+
body: {
|
|
210
|
+
accessPolicy: playbackPolicy?.accessPolicy ?? "public"
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const createPlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
214
|
+
const createPlaybackIdResponse = await this.fetch.fetchData(
|
|
215
|
+
url,
|
|
216
|
+
createPlaybackIdHeader
|
|
217
|
+
);
|
|
218
|
+
return createPlaybackIdResponse;
|
|
219
|
+
}
|
|
220
|
+
// Removes a playback ID from a media asset.
|
|
221
|
+
async removeMediaPlaybackId(props, requestObj) {
|
|
222
|
+
const path = `${this.mediaPath}/${props?.mediaId ?? ""}/playback-ids`;
|
|
223
|
+
let queryParams = "";
|
|
224
|
+
if (props?.playbackId) {
|
|
225
|
+
if (Array.isArray(props.playbackId)) {
|
|
226
|
+
const playbackIdParams = props.playbackId.map(
|
|
227
|
+
(id) => "playbackId=" + id
|
|
228
|
+
);
|
|
229
|
+
queryParams = "?" + playbackIdParams.join("&");
|
|
230
|
+
} else if (typeof props.playbackId === "string") {
|
|
231
|
+
queryParams = "?playbackId=" + props.playbackId;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
235
|
+
const constructObject = {
|
|
236
|
+
...requestObj,
|
|
237
|
+
method: "DELETE"
|
|
238
|
+
};
|
|
239
|
+
const deletePlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
240
|
+
const deletePlaybackIdResponse = await this.fetch.fetchData(
|
|
241
|
+
url,
|
|
242
|
+
deletePlaybackIdHeader
|
|
243
|
+
);
|
|
244
|
+
return deletePlaybackIdResponse;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var VideoOnDemand_default = Media;
|
|
248
|
+
|
|
249
|
+
// src/Live/index.ts
|
|
250
|
+
var LiveStream = class {
|
|
251
|
+
constructor() {
|
|
252
|
+
this.fetch = new NetworkFetcher_default();
|
|
253
|
+
this.livePath = "live/streams";
|
|
254
|
+
}
|
|
255
|
+
// Creates a new live stream with the given properties.
|
|
256
|
+
async createNewLiveStream(props, requestObj) {
|
|
257
|
+
const path = this.livePath;
|
|
258
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
259
|
+
const constructObject = {
|
|
260
|
+
...requestObj,
|
|
261
|
+
method: "POST",
|
|
262
|
+
body: {
|
|
263
|
+
playbackSettings: {
|
|
264
|
+
accessPolicy: props?.playbackSettings?.accessPolicy ?? "public"
|
|
265
|
+
},
|
|
266
|
+
inputMediaSettings: {
|
|
267
|
+
...props?.inputMediaSettings
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
const createLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
272
|
+
const createLiveStreamResponse = await this.fetch.fetchData(
|
|
273
|
+
url,
|
|
274
|
+
createLiveStreamHeader
|
|
275
|
+
);
|
|
276
|
+
return createLiveStreamResponse;
|
|
277
|
+
}
|
|
278
|
+
// Retrieves all live streams with pagination support.
|
|
279
|
+
async getAllLiveStreams(props, requestObj) {
|
|
280
|
+
const path = this.livePath;
|
|
281
|
+
const queryParams = `?limit=${props?.limit ?? 10}&offset=${props?.offset ?? 1}&orderBy=${props?.orderBy ?? "desc"}`;
|
|
282
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
283
|
+
const constructObject = {
|
|
284
|
+
...requestObj,
|
|
285
|
+
method: "GET"
|
|
286
|
+
};
|
|
287
|
+
const getAllLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
288
|
+
const getAllLiveStreamResponse = await this.fetch.fetchData(
|
|
289
|
+
url,
|
|
290
|
+
getAllLiveStreamHeader
|
|
291
|
+
);
|
|
292
|
+
return getAllLiveStreamResponse;
|
|
293
|
+
}
|
|
294
|
+
// Retrieves details of a specific live stream.
|
|
295
|
+
async getLiveStream(props, requestObj) {
|
|
296
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}`;
|
|
297
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
298
|
+
const constructObject = {
|
|
299
|
+
...requestObj,
|
|
300
|
+
method: "GET"
|
|
301
|
+
};
|
|
302
|
+
const getLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
303
|
+
const getLiveStreamResponse = await this.fetch.fetchData(
|
|
304
|
+
url,
|
|
305
|
+
getLiveStreamHeader
|
|
306
|
+
);
|
|
307
|
+
return getLiveStreamResponse;
|
|
308
|
+
}
|
|
309
|
+
// Updates a live stream with new properties.
|
|
310
|
+
async updateLiveStream(props, updateObject, requestObj) {
|
|
311
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}`;
|
|
312
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
313
|
+
const constructObject = {
|
|
314
|
+
...requestObj,
|
|
315
|
+
method: "PATCH",
|
|
316
|
+
body: {
|
|
317
|
+
...updateObject ?? {}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
const updateLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
321
|
+
const updateLiveStreamResponse = await this.fetch.fetchData(
|
|
322
|
+
url,
|
|
323
|
+
updateLiveStreamHeader
|
|
324
|
+
);
|
|
325
|
+
return updateLiveStreamResponse;
|
|
326
|
+
}
|
|
327
|
+
// Deletes a specific live stream.
|
|
328
|
+
async deleteLiveStream(props, requestObj) {
|
|
329
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}`;
|
|
330
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
331
|
+
const constructObject = {
|
|
332
|
+
...requestObj,
|
|
333
|
+
method: "DELETE"
|
|
334
|
+
};
|
|
335
|
+
const deleteLiveStream = this.fetch.constructHeaders(constructObject);
|
|
336
|
+
const deleteLiveStreamResponse = await this.fetch.fetchData(
|
|
337
|
+
url,
|
|
338
|
+
deleteLiveStream
|
|
339
|
+
);
|
|
340
|
+
return deleteLiveStreamResponse;
|
|
341
|
+
}
|
|
342
|
+
// Creates a playback ID for a live stream with specified access policy.
|
|
343
|
+
async createLiveStreamPlaybackId(props, playbackPolicy, requestObj) {
|
|
344
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/playback-ids`;
|
|
345
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
346
|
+
const constructObject = {
|
|
347
|
+
...requestObj,
|
|
348
|
+
method: "POST",
|
|
349
|
+
body: {
|
|
350
|
+
accessPolicy: playbackPolicy?.accessPolicy ?? "public"
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const createPlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
354
|
+
const createPlaybackIdResponse = await this.fetch.fetchData(
|
|
355
|
+
url,
|
|
356
|
+
createPlaybackIdHeader
|
|
357
|
+
);
|
|
358
|
+
return createPlaybackIdResponse;
|
|
359
|
+
}
|
|
360
|
+
// Removes a playback ID associated with a live stream.
|
|
361
|
+
async removeLivePlaybackId(props, requestObj) {
|
|
362
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/playback-ids`;
|
|
363
|
+
let queryParams = "";
|
|
364
|
+
if (props?.playbackId) {
|
|
365
|
+
if (Array.isArray(props.playbackId)) {
|
|
366
|
+
const playbackIdParams = props.playbackId.map(
|
|
367
|
+
(id) => "playbackId=" + id
|
|
368
|
+
);
|
|
369
|
+
queryParams = "?" + playbackIdParams.join("&");
|
|
370
|
+
} else if (typeof props.playbackId === "string") {
|
|
371
|
+
queryParams = "?playbackId=" + props.playbackId;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const url = this.fetch.constructUrl(requestObj, path, queryParams);
|
|
375
|
+
const constructObject = {
|
|
376
|
+
...requestObj,
|
|
377
|
+
method: "DELETE"
|
|
378
|
+
};
|
|
379
|
+
const deletePlaybackIdHeader = this.fetch.constructHeaders(constructObject);
|
|
380
|
+
const deletePlaybackIdResponse = await this.fetch.fetchData(
|
|
381
|
+
url,
|
|
382
|
+
deletePlaybackIdHeader
|
|
383
|
+
);
|
|
384
|
+
return deletePlaybackIdResponse;
|
|
385
|
+
}
|
|
386
|
+
// Retrieves the playback policy for a specific playback ID in a live stream.
|
|
387
|
+
async getLiveStreamPlaybackPolicy(props, requestObj) {
|
|
388
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/playback-ids/${props?.playbackId}`;
|
|
389
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
390
|
+
const constructObject = {
|
|
391
|
+
...requestObj,
|
|
392
|
+
method: "GET"
|
|
393
|
+
};
|
|
394
|
+
const getLiveStreamPlaybackPolicyHeader = this.fetch.constructHeaders(constructObject);
|
|
395
|
+
const getLiveStreamPlaybackPolicyResponse = await this.fetch.fetchData(
|
|
396
|
+
url,
|
|
397
|
+
getLiveStreamPlaybackPolicyHeader
|
|
398
|
+
);
|
|
399
|
+
return getLiveStreamPlaybackPolicyResponse;
|
|
400
|
+
}
|
|
401
|
+
// Creates a new simulcast target for a live stream.
|
|
402
|
+
async createLiveStreamSimulcast(props, liveStreamObj, requestObj) {
|
|
403
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/simulcast`;
|
|
404
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
405
|
+
const constructObject = {
|
|
406
|
+
...requestObj,
|
|
407
|
+
method: "POST",
|
|
408
|
+
body: {
|
|
409
|
+
...liveStreamObj
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const createSimulCastHeader = this.fetch.constructHeaders(constructObject);
|
|
413
|
+
const createSimulCastResponse = await this.fetch.fetchData(
|
|
414
|
+
url,
|
|
415
|
+
createSimulCastHeader
|
|
416
|
+
);
|
|
417
|
+
return createSimulCastResponse;
|
|
418
|
+
}
|
|
419
|
+
// Retrieves details of a specific simulcast target for a live stream.
|
|
420
|
+
async getLiveStreamSimulcast(props, requestObj) {
|
|
421
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/simulcast/${props?.simulcastId}`;
|
|
422
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
423
|
+
const constructObject = {
|
|
424
|
+
...requestObj,
|
|
425
|
+
method: "GET"
|
|
426
|
+
};
|
|
427
|
+
const getSimulcastHeader = this.fetch.constructHeaders(constructObject);
|
|
428
|
+
const getSimulcastResponse = await this.fetch.fetchData(
|
|
429
|
+
url,
|
|
430
|
+
getSimulcastHeader
|
|
431
|
+
);
|
|
432
|
+
return getSimulcastResponse;
|
|
433
|
+
}
|
|
434
|
+
// Updates an existing simulcast target for a live stream.
|
|
435
|
+
async updateLiveStreamSimulcast(props, simulcastObj, requestObj) {
|
|
436
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/simulcast/${props?.simulcastId}`;
|
|
437
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
438
|
+
const constructObject = {
|
|
439
|
+
...requestObj,
|
|
440
|
+
method: "PUT",
|
|
441
|
+
body: {
|
|
442
|
+
...simulcastObj
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const updateLiveStreamHeader = this.fetch.constructHeaders(constructObject);
|
|
446
|
+
const updateLiveStreamResponse = await this.fetch.fetchData(
|
|
447
|
+
url,
|
|
448
|
+
updateLiveStreamHeader
|
|
449
|
+
);
|
|
450
|
+
return updateLiveStreamResponse;
|
|
451
|
+
}
|
|
452
|
+
// Deletes an existing simulcast target from a live stream.
|
|
453
|
+
async deleteLiveStreamSimulcast(props, requestObj) {
|
|
454
|
+
const path = `${this.livePath}/${props?.streamId ?? ""}/simulcast/${props?.simulcastId}`;
|
|
455
|
+
const url = this.fetch.constructUrl(requestObj, path);
|
|
456
|
+
const constructObject = {
|
|
457
|
+
...requestObj,
|
|
458
|
+
method: "DELETE"
|
|
459
|
+
};
|
|
460
|
+
const deleteSimulcastHeader = this.fetch.constructHeaders(constructObject);
|
|
461
|
+
const deleteSimulcastResponse = await this.fetch.fetchData(
|
|
462
|
+
url,
|
|
463
|
+
deleteSimulcastHeader
|
|
464
|
+
);
|
|
465
|
+
return deleteSimulcastResponse;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
var Live_default = LiveStream;
|
|
469
|
+
|
|
470
|
+
// src/index.ts
|
|
471
|
+
var Client = class {
|
|
472
|
+
// Request configuration object
|
|
473
|
+
constructor(props) {
|
|
474
|
+
// Secret key for authentication
|
|
475
|
+
this.mediaService = null;
|
|
476
|
+
// Media service instance
|
|
477
|
+
this.liveStream = null;
|
|
478
|
+
this.accessTokenId = props?.accessTokenId;
|
|
479
|
+
this.secretKey = props?.secretKey;
|
|
480
|
+
this.validateSecrets();
|
|
481
|
+
this.mediaService = new VideoOnDemand_default();
|
|
482
|
+
this.liveStream = new Live_default();
|
|
483
|
+
if (this.accessTokenId && this.secretKey) {
|
|
484
|
+
this.encodedAuthToken = Buffer.from(
|
|
485
|
+
`${this.accessTokenId}:${this.secretKey}`
|
|
486
|
+
).toString("base64");
|
|
487
|
+
}
|
|
488
|
+
this.RequestObject = {
|
|
489
|
+
httpAgent: "https",
|
|
490
|
+
domain: "v1.fastpix.io",
|
|
491
|
+
encodedAuthToken: this.encodedAuthToken
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
// Validate the provided credentials
|
|
495
|
+
validateSecrets() {
|
|
496
|
+
if (!this.accessTokenId || typeof this.accessTokenId !== "string") {
|
|
497
|
+
throw new Error(
|
|
498
|
+
'Invalid accessTokenId: The "accessTokenId" is required.'
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
if (!this.secretKey || typeof this.secretKey !== "string") {
|
|
502
|
+
throw new Error('Invalid secretKey: The "secretKey" is required.');
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
// Media Methods
|
|
506
|
+
// Uploads media from a given URL
|
|
507
|
+
uploadMediaFromUrl(props) {
|
|
508
|
+
return this.mediaService ? this.mediaService.createAsset(this.RequestObject, props) : null;
|
|
509
|
+
}
|
|
510
|
+
// Uploads media from a file input.
|
|
511
|
+
uploadMediaFromDevice(props) {
|
|
512
|
+
return this.mediaService ? this.mediaService.uploadAsset(this.RequestObject, props) : null;
|
|
513
|
+
}
|
|
514
|
+
// Retrieves all media assets with pagination.
|
|
515
|
+
getAllMediaAssets(props) {
|
|
516
|
+
return this.mediaService ? this.mediaService.getAllAssets(props, this.RequestObject) : null;
|
|
517
|
+
}
|
|
518
|
+
// Fetches a media asset by its ID.
|
|
519
|
+
getMediaAssetById(props) {
|
|
520
|
+
return this.mediaService ? this.mediaService.getAsset(props, this.RequestObject) : null;
|
|
521
|
+
}
|
|
522
|
+
// Fetches information about a media asset by its ID.
|
|
523
|
+
getMediaAssetInfo(props) {
|
|
524
|
+
return this.mediaService ? this.mediaService.getAssetInfo(props, this.RequestObject) : null;
|
|
525
|
+
}
|
|
526
|
+
// Modifies metadata of an existing media asset.
|
|
527
|
+
updateMediaAsset(props, updateObject) {
|
|
528
|
+
return this.mediaService ? this.mediaService.updateAsset(props, updateObject, this.RequestObject) : null;
|
|
529
|
+
}
|
|
530
|
+
// Removes a media asset by its ID.
|
|
531
|
+
deleteMediaAsset(props) {
|
|
532
|
+
return this.mediaService ? this.mediaService.deleteAsset(props, this.RequestObject) : null;
|
|
533
|
+
}
|
|
534
|
+
// Creates a playback ID for a media asset.
|
|
535
|
+
generateMediaPlaybackId(props, accessPolicy) {
|
|
536
|
+
return this.mediaService ? this.mediaService.addMediaPlaybackId(
|
|
537
|
+
props,
|
|
538
|
+
accessPolicy,
|
|
539
|
+
this.RequestObject
|
|
540
|
+
) : null;
|
|
541
|
+
}
|
|
542
|
+
// Removes a playback ID from a media asset.
|
|
543
|
+
deleteMediaPlaybackId(props) {
|
|
544
|
+
return this.mediaService ? this.mediaService.removeMediaPlaybackId(props, this.RequestObject) : null;
|
|
545
|
+
}
|
|
546
|
+
// Initiates a new live stream.
|
|
547
|
+
initiateLiveStream(props) {
|
|
548
|
+
return this.liveStream ? this.liveStream.createNewLiveStream(props, this.RequestObject) : null;
|
|
549
|
+
}
|
|
550
|
+
// Retrieves all live streams with pagination.
|
|
551
|
+
getAllLiveStreams(props) {
|
|
552
|
+
return this.liveStream ? this.liveStream.getAllLiveStreams(props, this.RequestObject) : null;
|
|
553
|
+
}
|
|
554
|
+
// Fetches a live stream by its ID.
|
|
555
|
+
getLiveStreamById(props) {
|
|
556
|
+
return this.liveStream ? this.liveStream.getLiveStream(props, this.RequestObject) : null;
|
|
557
|
+
}
|
|
558
|
+
// Modifies an existing live stream.
|
|
559
|
+
updateLiveStream(props, updateObject) {
|
|
560
|
+
return this.liveStream ? this.liveStream.updateLiveStream(
|
|
561
|
+
props,
|
|
562
|
+
updateObject,
|
|
563
|
+
this.RequestObject
|
|
564
|
+
) : null;
|
|
565
|
+
}
|
|
566
|
+
// Removes a live stream by its ID.
|
|
567
|
+
deleteLiveStream(props) {
|
|
568
|
+
return this.liveStream ? this.liveStream.deleteLiveStream(props, this.RequestObject) : null;
|
|
569
|
+
}
|
|
570
|
+
// Creates a playback ID for a live stream.
|
|
571
|
+
generateLiveStreamPlaybackId(props, accessPolicy) {
|
|
572
|
+
return this.liveStream ? this.liveStream.createLiveStreamPlaybackId(
|
|
573
|
+
props,
|
|
574
|
+
accessPolicy,
|
|
575
|
+
this.RequestObject
|
|
576
|
+
) : null;
|
|
577
|
+
}
|
|
578
|
+
// Removes a playback ID from a live stream.
|
|
579
|
+
deleteLiveStreamPlaybackId(props) {
|
|
580
|
+
return this.liveStream ? this.liveStream.removeLivePlaybackId(props, this.RequestObject) : null;
|
|
581
|
+
}
|
|
582
|
+
// Fetches the playback policy for a live stream.
|
|
583
|
+
getLiveStreamPlaybackPolicy(props) {
|
|
584
|
+
return this.liveStream ? this.liveStream.getLiveStreamPlaybackPolicy(props, this.RequestObject) : null;
|
|
585
|
+
}
|
|
586
|
+
// Initiates a simulcast for a live stream.
|
|
587
|
+
initiateLiveStreamSimulcast(props, liveStreamObj) {
|
|
588
|
+
return this.liveStream ? this.liveStream.createLiveStreamSimulcast(
|
|
589
|
+
props,
|
|
590
|
+
liveStreamObj,
|
|
591
|
+
this.RequestObject
|
|
592
|
+
) : null;
|
|
593
|
+
}
|
|
594
|
+
// Retrieves a simulcast for a live stream.
|
|
595
|
+
getLiveStreamSimulcast(props) {
|
|
596
|
+
return this.liveStream ? this.liveStream.getLiveStreamSimulcast(props, this.RequestObject) : null;
|
|
597
|
+
}
|
|
598
|
+
// Modifies an existing simulcast for a live stream.
|
|
599
|
+
updateLiveStreamSimulcast(props, simulcastObj) {
|
|
600
|
+
return this.liveStream ? this.liveStream.updateLiveStreamSimulcast(
|
|
601
|
+
props,
|
|
602
|
+
simulcastObj,
|
|
603
|
+
this.RequestObject
|
|
604
|
+
) : null;
|
|
605
|
+
}
|
|
606
|
+
// Removes a simulcast from a live stream.
|
|
607
|
+
deleteLiveStreamSimulcast(props) {
|
|
608
|
+
return this.liveStream ? this.liveStream.deleteLiveStreamSimulcast(props, this.RequestObject) : null;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var index_default = Client;
|
|
612
|
+
export {
|
|
613
|
+
index_default as default
|
|
614
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Method: initiateLiveStream()
|
|
2
|
+
|
|
3
|
+
The `initiateLiveStream` method allows you to start a live stream with specific configurations. You can define settings for playback, input media, and metadata. This method returns the details of the initiated stream, including the unique `streamId` and `streamKey` that you can use for managing further live stream operations.
|
|
4
|
+
|
|
5
|
+
### Parameter Details:
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
9
|
+
| -------------------- | ------------------------------------------------------------------------- | -------- | ------------------- |
|
|
10
|
+
| `playbackSettings` | Defines settings related to playback, such as access policy. | `Object` | See details below |
|
|
11
|
+
| `inputMediaSettings` | Defines settings related to the media being streamed, such as resolution. | `Object` | See details below |
|
|
12
|
+
|
|
13
|
+
#### playbackSettings
|
|
14
|
+
|
|
15
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
16
|
+
| -------------- | --------------------------------------------------------------------------------- | -------- | ----------------------- |
|
|
17
|
+
| `accessPolicy` | Determines if access to the streamed content is kept private or available to all. | `String` | `"public"`, `"private"` |
|
|
18
|
+
|
|
19
|
+
#### inputMediaSettings
|
|
20
|
+
|
|
21
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
22
|
+
| ----------------- | ---------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------- |
|
|
23
|
+
| `maxResolution` | Sets the maximum resolution for the live stream. | `String` | `"1080p"`, `"720p"`, `"480p"` |
|
|
24
|
+
| `reconnectWindow` | The time in seconds to wait before reconnecting the stream if it's interrupted. | `Integer` | 60 to 1800 seconds |
|
|
25
|
+
| `mediaPolicy` | Determines whether the recorded stream is private or public when converted to VOD. | `String` | `"public"`, `"private"` |
|
|
26
|
+
| `metadata` | Optional metadata for tagging the live stream. Up to 10 key-value pairs. | `Object` | Any valid key-value pair (max 255 characters per key and value) |
|
|
27
|
+
| `enableDvrMode` | Enables or disables DVR mode for the live stream. When enabled, viewers can rewind the stream. | `Boolean` | `true`, `false` |
|
|
28
|
+
|
|
29
|
+
### Example Request:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
// Define the live stream request with custom configurations
|
|
33
|
+
const liveStreamRequest = {
|
|
34
|
+
playbackSettings: {
|
|
35
|
+
accessPolicy: "public", // Defines the access level of the live stream (public or private)
|
|
36
|
+
},
|
|
37
|
+
inputMediaSettings: {
|
|
38
|
+
maxResolution: "1080p", // Set the maximum resolution of the live stream
|
|
39
|
+
reconnectWindow: 60, // Set the duration for reconnecting the stream in seconds
|
|
40
|
+
mediaPolicy: "public", // Define media policy (public or private)
|
|
41
|
+
enableDvrMode: true, // Enable DVR mode to allow viewers to rewind the live stream
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Initiating the live stream
|
|
46
|
+
const generateLiveStream = await fastpix.initiateLiveStream(liveStreamRequest);
|
|
47
|
+
console.log("Live Stream initiated successfully:", generateLiveStream);
|
|
48
|
+
```
|