@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
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# Method: uploadMediaFromUrl()
|
|
2
|
+
|
|
3
|
+
The `uploadMediaFromUrl` method allows you to upload media directly from a URL. This method requires the `inputs` array, which contains media objects specifying different types such as `video`, `audio` and `watermark`. Each media object can include various optional parameters like `audio`, `metadata`, `subtitle`, and `watermark`, depending on the media type specified.
|
|
4
|
+
|
|
5
|
+
In the response, a unique `id` is returned, which serves as the `mediaId` for managing further media operations such as retrieving media details, generating playback IDs, updating metadata, or deleting the asset.
|
|
6
|
+
|
|
7
|
+
### Parameters Details:
|
|
8
|
+
|
|
9
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
10
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------- |
|
|
11
|
+
| `inputs` (required) | Array of media objects containing details about each media type (`video`, `audio`, `text`, `watermark`). | Array | Array of objects specifying media details (see below). |
|
|
12
|
+
| `accessPolicy` (required) | Determines whether access to the streamed content is kept private or available to all. | String | `public`, `private`, `drm` |
|
|
13
|
+
| `metadata` | Metadata key-value pairs for the media (max 10 entries, each with a `key` and `value`). | Object | Key-value pairs (max 255 chars per key-value pair). |
|
|
14
|
+
| `subtitles` | Subtitles details for the video, including language name and BCP 47 language code. | Object | Subtitle object containing `name`, `metadata` and `languageCode`. |
|
|
15
|
+
| `optimizeAudio` | If `true`, enhances audio quality and volume. Defaults to `false`. Available only for pre-recorded content. | Boolean | `true`, `false` |
|
|
16
|
+
| `maxResolution` | The maximum resolution available for the video (e.g., `1080p`, `4k`). | String | `360p`, `480p`, `720p`, `1080p`, `1440p`, `1880p` |
|
|
17
|
+
| `mp4Support` | Specifies MP4 video support options: `capped_4k`, `audioOnly`, or both for offline viewing. | String | `capped_4k`, `audioOnly`, `audioOnly,capped_4k` |
|
|
18
|
+
|
|
19
|
+
### Inputs Array
|
|
20
|
+
|
|
21
|
+
Each element in the `inputs` array represents a media object containing different media types (like `video`, `audio`, `watermark`) with the following structure:
|
|
22
|
+
|
|
23
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
24
|
+
| ----------------- | ------------------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------- |
|
|
25
|
+
| `type` (required) | The type of media (e.g., `video`, `audio`, `watermark`). | String | `video`, `audio`, `watermark` |
|
|
26
|
+
| `url` (required) | URL of the media file to be uploaded (MP4, MOV, MKV, MP3, TS, etc.). | String | Valid URL path for the media file (e.g., MP4, MOV, MKV, MP3, TS). |
|
|
27
|
+
| `startTime` | Start time in seconds for encoding the media. | Number | Any non-negative integer value |
|
|
28
|
+
| `endTime` | End time in seconds for encoding the media. | Number | Any non-negative integer value greater than `startTime`. |
|
|
29
|
+
| `introUrl` | URL of the intro video to add at the beginning of the media. | String | Valid URL path for the intro media file. |
|
|
30
|
+
| `outroUrl` | URL of the outro video to add at the end of the media. | String | Valid URL path for the outro media file. |
|
|
31
|
+
| `expungeSegments` | List of `startTime-endTime` strings to remove specific segments from the video. | Array | Array of strings representing time ranges in the format `startTime-endTime`. |
|
|
32
|
+
| `watermark` | Watermark details to overlay on the video. | Object | See below for watermark parameters. |
|
|
33
|
+
| `audio` | Audio details, including any audio swap or overlay settings. | Object | See below for audio parameters. |
|
|
34
|
+
|
|
35
|
+
#### Watermark Object
|
|
36
|
+
|
|
37
|
+
If the media type is `"watermark"`, the following parameters are required:
|
|
38
|
+
|
|
39
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
40
|
+
| ------------- | ----------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------- |
|
|
41
|
+
| `type` | Type of overlay (currently only supports `'watermark'`). | String | `'watermark'` |
|
|
42
|
+
| `url` | URL of the watermark image to overlay on the media. | String | Valid URL path to the watermark image (PNG, JPEG, etc.). |
|
|
43
|
+
| `placement` | Placement details for positioning the watermark on the video. | Object | Placement object with alignment, margin, and size properties (see below). |
|
|
44
|
+
| `width` | Width of the watermark in pixels or percentage (e.g., `20%`, `200px`). | String | Any valid string for width (e.g., `20%`, `200px`). |
|
|
45
|
+
| `height` | Height of the watermark in pixels or percentage (e.g., `20%`, `200px`). | String | Any valid string for height (e.g., `20%`, `200px`). |
|
|
46
|
+
| `opacity` | Opacity of the watermark in percentage (0-100%). | String | Any integer value from `0` to `100` |
|
|
47
|
+
|
|
48
|
+
#### Placement Object for Watermark
|
|
49
|
+
|
|
50
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
51
|
+
| ------------- | ---------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------ |
|
|
52
|
+
| `xAlign` | Horizontal alignment of the watermark. Possible values: `left`, `center`, `right`. | String | `left`, `center`, `right` |
|
|
53
|
+
| `xMargin` | Horizontal margin from the edge of the video (in pixels). | String | Any non-negative integer value or percentage (e.g., `10px`, `5%`). |
|
|
54
|
+
| `yAlign` | Vertical alignment of the watermark. Possible values: `top`, `center`, `bottom`. | String | `top`, `center`, `bottom` |
|
|
55
|
+
| `yMargin` | Vertical margin from the edge of the video (in pixels). | String | Any non-negative integer value or percentage (e.g., `10px`, `5%`). |
|
|
56
|
+
|
|
57
|
+
#### Audio Object
|
|
58
|
+
|
|
59
|
+
If the media type is `"audio"`, the following parameters are relevant:
|
|
60
|
+
|
|
61
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
62
|
+
| -------------- | ------------------------------------------------------------------ | -------- | --------------------------------------------------------------------------------------------------- |
|
|
63
|
+
| `type` | Type of overlay (currently only supports `'audio'`). | String | `'audio'` |
|
|
64
|
+
| `swapTrackUrl` | URL of the audio track to replace the existing audio in the video. | String | Valid URL path for the new audio track (MP3, WAV, etc.). |
|
|
65
|
+
| `imposeTracks` | List of additional audio tracks to overlay on the video. | Array | Array of audio track objects with `url`, `startTime`, `endTime`, `fadeInLevel`, and `fadeOutLevel`. |
|
|
66
|
+
|
|
67
|
+
#### Impose Tracks Object for Audio
|
|
68
|
+
|
|
69
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
70
|
+
| -------------- | -------------------------------------------------------------------------- | -------- | ------------------------------------------------------------- |
|
|
71
|
+
| `url` | URL of the audio track to impose on the video. | String | Valid URL path to the additional audio file (MP3, WAV, etc.). |
|
|
72
|
+
| `startTime` | Start time in seconds for the imposed audio to begin. | Number | Any non-negative integer value |
|
|
73
|
+
| `endTime` | End time in seconds for the imposed audio to stop. | Number | Any non-negative integer value greater than `startTime`. |
|
|
74
|
+
| `fadeInLevel` | Level of fade-in effect in seconds for the imposed audio at the beginning. | Number | Any non-negative integer value |
|
|
75
|
+
| `fadeOutLevel` | Level of fade-out effect in seconds for the imposed audio at the end. | Number | Any non-negative integer value |
|
|
76
|
+
|
|
77
|
+
#### Metadata Object
|
|
78
|
+
|
|
79
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
80
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------ |
|
|
81
|
+
| `metadata` | Tag the video with key-value pairs for searchable metadata. Maximum of 10 entries, each with 255 characters. | Object | Up to 10 key-value pairs, each key and value being alphanumeric strings of up to 255 characters. |
|
|
82
|
+
|
|
83
|
+
#### Subtitles Object
|
|
84
|
+
|
|
85
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
86
|
+
| ----------------- | ----------------------------------------------------------- | -------- | -------------------------------------------------------------- |
|
|
87
|
+
| `metadata` | Metadata key-value pairs for the subtitles. Optional field. | Object | Key-value pairs (max 255 characters per key-value pair). |
|
|
88
|
+
| `languageName` (required) | Name of the language for the subtitles. | String | Any string, such as `"English"`, `"French"`, `"Spanish"`, etc. |
|
|
89
|
+
| `languageCode` | BCP 47 compliant language code (e.g., `"en"` for English). | String | Any valid BCP 47 language code (e.g., `"en"`, `"fr"`, `"es"`) |
|
|
90
|
+
|
|
91
|
+
### Example Request:
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
const uploadMedia = await fastpix.uploadMediaFromUrl({
|
|
95
|
+
metadata: {
|
|
96
|
+
newKey: "New Value",
|
|
97
|
+
},
|
|
98
|
+
subtitles: {
|
|
99
|
+
metadata: {
|
|
100
|
+
newKey: "New Value",
|
|
101
|
+
"newKey-1": "New Value",
|
|
102
|
+
},
|
|
103
|
+
languageName: "english",
|
|
104
|
+
languageCode: "en",
|
|
105
|
+
},
|
|
106
|
+
accessPolicy: "public", // required
|
|
107
|
+
optimizeAudio: true,
|
|
108
|
+
maxResolution: "1080p",
|
|
109
|
+
inputs: [
|
|
110
|
+
{
|
|
111
|
+
type: "video", // required
|
|
112
|
+
url: "https://static.fastpix.io/sample.mp4", //required
|
|
113
|
+
startTime: 0,
|
|
114
|
+
endTime: 5,
|
|
115
|
+
introUrl: "https://static.fastpix.io/sample.mp4",
|
|
116
|
+
outroUrl: "https://static.fastpix.io/sample.mp4",
|
|
117
|
+
expungeSegments: ["3-5", "6-8"],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
placement: {
|
|
121
|
+
xAlign: "left",
|
|
122
|
+
xMargin: "10%",
|
|
123
|
+
yAlign: "middle",
|
|
124
|
+
yMargin: "10%",
|
|
125
|
+
},
|
|
126
|
+
type: "watermark",
|
|
127
|
+
url: "https://static.fastpix.io/watermark-4k.png",
|
|
128
|
+
width: "25%",
|
|
129
|
+
height: "25%",
|
|
130
|
+
opacity: "80%",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: "audio",
|
|
134
|
+
swapTrackUrl:
|
|
135
|
+
"https://file-examples.com/storage/fe0e9b723466913cf9611b7/2017/11/file_example_MP3_700KB.mp3",
|
|
136
|
+
imposeTracks: [
|
|
137
|
+
{
|
|
138
|
+
url: "https://muxed.s3.amazonaws.com/example-impose-audio-track.m4a",
|
|
139
|
+
startTime: 0,
|
|
140
|
+
endTime: 5,
|
|
141
|
+
fadeInLevel: 1,
|
|
142
|
+
fadeOutLevel: 4,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
url: "https://muxed.s3.amazonaws.com/example-impose-audio-track.m4a",
|
|
146
|
+
startTime: 0,
|
|
147
|
+
endTime: 5,
|
|
148
|
+
fadeInLevel: 1,
|
|
149
|
+
fadeOutLevel: 4,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
mp4Support: "capped_4k",
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
console.log("Upload Response:", uploadMedia);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
# Method: uploadMediaFromDevice()
|
|
163
|
+
|
|
164
|
+
This method allows you to upload a video file directly from your local device to FastPix. By using this method with your desired media settings, you will receive an `uploadId` and a `url`. You can then use the `url` to upload your media via a HTTP `PUT` request. Note that `corsOrigin` and `accessPolicy` are mandatory fields, while the other parameters are optional.
|
|
165
|
+
|
|
166
|
+
In the response, a unique `uploadId` is returned, which serves as the `mediaId` for managing further media operations such as retrieving media details, generating playback IDs, updating metadata, or deleting the asset.
|
|
167
|
+
|
|
168
|
+
### Parameters Details:
|
|
169
|
+
|
|
170
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
171
|
+
| ------------------------------ | --------------------------------------------------------------------------------------------------------- | -------- | ---------------------- |
|
|
172
|
+
| `corsOrigin` (required) | The allowed origin for Cross-Origin Resource Sharing (CORS). Set to `"*"` to allow all origins. | String | Any valid URL or `"*"` |
|
|
173
|
+
| `pushMediaSettings` (required) | Configuration settings for the media upload, including access policy, resolution, and audio optimization. | Object | - |
|
|
174
|
+
|
|
175
|
+
### Push Media Settings Object
|
|
176
|
+
|
|
177
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
178
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------ |
|
|
179
|
+
| `accessPolicy` (required) | Determines whether the media access is private, public, or drm. | String | `private`, `public`, `drm` |
|
|
180
|
+
| `startTime` | The start time (in seconds) for encoding to begin within the video file. | Number | Any non-negative integer value |
|
|
181
|
+
| `endTime` | The end time (in seconds) for encoding to stop within the video file. | Number | Any non-negative integer value, must be greater than `startTime`. |
|
|
182
|
+
| `inputs` | Array of media input objects, each containing details such as URL, type, and additional metadata. | Array | Array of objects representing media input. |
|
|
183
|
+
| `metadata` | Tag the video with key-value pairs for searchable metadata. Maximum of 10 entries, each with 255 characters. | Object | Up to 10 key-value pairs, each key and value being alphanumeric strings of up to 255 characters. |
|
|
184
|
+
| `subtitles` | Subtitles details for the video, including language name and BCP 47 language code. | Object | Subtitle object containing `name`, `metadata` and `languageCode`. |
|
|
185
|
+
| `optimizeAudio` | If set to true, enhances the audio quality and volume. Defaults to true. Only available for pre-recorded content. | Boolean | `true`, `false` |
|
|
186
|
+
| `maxResolution` | Specifies the highest resolution available for the media (e.g., `"1080p"`). Defaults to `1080p`. | String | `144p`, `240p`, `360p`, `480p`, `720p`, `1080p`, `1440p`, `2160p` |
|
|
187
|
+
| `mp4Support` | Defines the MP4 video support options (`"capped_4k"`, `"audioOnly"`, or both for offline viewing). | String | `"capped_4k"`, `"audioOnly"`, `"both"` |
|
|
188
|
+
|
|
189
|
+
#### Inputs Object
|
|
190
|
+
|
|
191
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
192
|
+
| ----------------- | ----------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------- |
|
|
193
|
+
| `type` | The type of input. Possible values: `video`, `audio`, `text`, or `watermark`. | String | `video`, `audio`, `text`, `watermark` |
|
|
194
|
+
| `startTime` | The start time (in seconds) for the segment of the media to encode. | Number | Any non-negative integer value |
|
|
195
|
+
| `endTime` | The end time (in seconds) for the segment of the media to encode. | Number | Any non-negative integer value, must be greater than `startTime`. |
|
|
196
|
+
| `introUrl` | URL of the intro video to add at the beginning of the media. | String | Valid URL for intro media |
|
|
197
|
+
| `outroUrl` | URL of the outro video to add at the end of the media. | String | Valid URL for outro media |
|
|
198
|
+
| `expungeSegments` | Array of strings specifying start and end times of segments to remove from the video (e.g., `"0-10"`, `"50-60"`). | Array | Array of strings with the format `"startTime-endTime"`. |
|
|
199
|
+
| `watermark` | Watermark details, if `type = "watermark"`. Contains watermark URL and placement info. | Object | Object with watermark parameters. |
|
|
200
|
+
| `audio` | Audio track details if `type = "audio"`. Includes information on replacing or overlaying audio tracks. | Object | Object with audio-related parameters. |
|
|
201
|
+
|
|
202
|
+
#### Watermark Object
|
|
203
|
+
|
|
204
|
+
If the media type is `"watermark"`, the following parameters are required:
|
|
205
|
+
|
|
206
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
207
|
+
| ------------- | ----------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------- |
|
|
208
|
+
| `type` | Type of overlay (currently only supports `'watermark'`). | String | `'watermark'` |
|
|
209
|
+
| `url` | URL of the watermark image to overlay on the media. | String | Valid URL path to the watermark image (PNG, JPEG, etc.). |
|
|
210
|
+
| `placement` | Placement details for positioning the watermark on the video. | Object | Placement object with alignment, margin, and size properties (see below). |
|
|
211
|
+
| `width` | Width of the watermark in pixels or percentage (e.g., `20%`, `200px`). | String | Any valid string for width (e.g., `20%`, `200px`). |
|
|
212
|
+
| `height` | Height of the watermark in pixels or percentage (e.g., `20%`, `200px`). | String | Any valid string for height (e.g., `20%`, `200px`). |
|
|
213
|
+
| `opacity` | Opacity of the watermark in percentage (0-100%). | String | Any integer value from `0` to `100` |
|
|
214
|
+
|
|
215
|
+
#### Placement Object for Watermark
|
|
216
|
+
|
|
217
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
218
|
+
| ------------- | ---------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------ |
|
|
219
|
+
| `xAlign` | Horizontal alignment of the watermark. Possible values: `left`, `center`, `right`. | String | `left`, `center`, `right` |
|
|
220
|
+
| `xMargin` | Horizontal margin from the edge of the video (in pixels). | String | Any non-negative integer value or percentage (e.g., `10px`, `5%`). |
|
|
221
|
+
| `yAlign` | Vertical alignment of the watermark. Possible values: `top`, `center`, `bottom`. | String | `top`, `center`, `bottom` |
|
|
222
|
+
| `yMargin` | Vertical margin from the edge of the video (in pixels). | String | Any non-negative integer value or percentage (e.g., `10px`, `5%`). |
|
|
223
|
+
|
|
224
|
+
#### Audio Object
|
|
225
|
+
|
|
226
|
+
If the media type is `"audio"`, the following parameters are relevant:
|
|
227
|
+
|
|
228
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
229
|
+
| -------------- | ------------------------------------------------------------------ | -------- | --------------------------------------------------------------------------------------------------- |
|
|
230
|
+
| `type` | Type of overlay (currently only supports `'audio'`). | String | `'audio'` |
|
|
231
|
+
| `swapTrackUrl` | URL of the audio track to replace the existing audio in the video. | String | Valid URL path for the new audio track (MP3, WAV, etc.). |
|
|
232
|
+
| `imposeTracks` | List of additional audio tracks to overlay on the video. | Array | Array of audio track objects with `url`, `startTime`, `endTime`, `fadeInLevel`, and `fadeOutLevel`. |
|
|
233
|
+
|
|
234
|
+
#### Impose Tracks Object for Audio
|
|
235
|
+
|
|
236
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
237
|
+
| -------------- | -------------------------------------------------------------------------- | -------- | ------------------------------------------------------------- |
|
|
238
|
+
| `url` | URL of the audio track to impose on the video. | String | Valid URL path to the additional audio file (MP3, WAV, etc.). |
|
|
239
|
+
| `startTime` | Start time in seconds for the imposed audio to begin. | Number | Any non-negative integer value |
|
|
240
|
+
| `endTime` | End time in seconds for the imposed audio to stop. | Number | Any non-negative integer value greater than `startTime`. |
|
|
241
|
+
| `fadeInLevel` | Level of fade-in effect in seconds for the imposed audio at the beginning. | Number | Any non-negative integer value |
|
|
242
|
+
| `fadeOutLevel` | Level of fade-out effect in seconds for the imposed audio at the end. | Number | Any non-negative integer value |
|
|
243
|
+
|
|
244
|
+
#### Metadata Object
|
|
245
|
+
|
|
246
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
247
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------ | -------- | ------------------------------------------------------------------------------------------------ |
|
|
248
|
+
| `metadata` | Tag the video with key-value pairs for searchable metadata. Maximum of 10 entries, each with 255 characters. | Object | Up to 10 key-value pairs, each key and value being alphanumeric strings of up to 255 characters. |
|
|
249
|
+
|
|
250
|
+
#### Subtitles Object
|
|
251
|
+
|
|
252
|
+
| **Parameter** | **Description** | **Type** | **Accepted Values** |
|
|
253
|
+
| ----------------- | ----------------------------------------------------------- | -------- | -------------------------------------------------------------- |
|
|
254
|
+
| `metadata` | Metadata key-value pairs for the subtitles. Optional field. | Object | Key-value pairs (max 255 characters per key-value pair). |
|
|
255
|
+
| `languageName` (required) | Name of the language for the subtitles. | String | Any string, such as `"English"`, `"French"`, `"Spanish"`, etc. |
|
|
256
|
+
| `languageCode` | BCP 47 compliant language code (e.g., `"en"` for English). | String | Any valid BCP 47 language code (e.g., `"en"`, `"fr"`, `"es"`) |
|
|
257
|
+
|
|
258
|
+
### Example Request:
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
const uploadMedia = await fastpix.uploadMediaFromDevice({
|
|
262
|
+
pushMediaSettings: {
|
|
263
|
+
accessPolicy: "public",
|
|
264
|
+
metadata: { newKey: "New Value" },
|
|
265
|
+
subtitles: { languageName: "english", languageCode: "en" },
|
|
266
|
+
optimizeAudio: true,
|
|
267
|
+
maxResolution: "1080p",
|
|
268
|
+
startTime: 0,
|
|
269
|
+
endTime: 5,
|
|
270
|
+
inputs: [
|
|
271
|
+
{
|
|
272
|
+
type: "video",
|
|
273
|
+
startTime: 0,
|
|
274
|
+
endTime: 5,
|
|
275
|
+
introUrl: "https://static.fastpix.io/sample.mp4",
|
|
276
|
+
outroUrl: "https://static.fastpix.io/sample.mp4",
|
|
277
|
+
expungeSegments: ["2-4"],
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
placement: {
|
|
281
|
+
xAlign: "center",
|
|
282
|
+
xMargin: "10%",
|
|
283
|
+
yAlign: "middle",
|
|
284
|
+
yMargin: "10%",
|
|
285
|
+
},
|
|
286
|
+
type: "watermark",
|
|
287
|
+
url: "https://static.fastpix.io/watermark-4k.png",
|
|
288
|
+
width: "25%",
|
|
289
|
+
height: "25%",
|
|
290
|
+
opacity: "80%",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "audio",
|
|
294
|
+
swapTrackUrl:
|
|
295
|
+
"https://file-examples.com/storage/fe0e9b723466913cf9611b7/2017/11/file_example_MP3_700KB.mp3",
|
|
296
|
+
imposeTracks: [
|
|
297
|
+
{
|
|
298
|
+
url: "https://muxed.s3.amazonaws.com/example-impose-audio-track.m4a",
|
|
299
|
+
startTime: 0,
|
|
300
|
+
endTime: 5,
|
|
301
|
+
fadeInLevel: 1,
|
|
302
|
+
fadeOutLevel: 4,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
url: "https://muxed.s3.amazonaws.com/example-impose-audio-track.m4a",
|
|
306
|
+
startTime: 0,
|
|
307
|
+
endTime: 5,
|
|
308
|
+
fadeInLevel: 1,
|
|
309
|
+
fadeOutLevel: 4,
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
},
|
|
313
|
+
],
|
|
314
|
+
mp4Support: "capped_4k",
|
|
315
|
+
},
|
|
316
|
+
corsOrigin: "*",
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
console.log("Upload Response:", uploadMedia);
|
|
320
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fastpix/fastpix-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "FastPix API SDK for Node.js, written in TypeScript",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/index.mjs",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/*",
|
|
10
|
+
"types/*",
|
|
11
|
+
"docs/*"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"require": "./dist/index.cjs",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
23
|
+
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.cjs --platform=node --format=cjs",
|
|
24
|
+
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --platform=node --format=esm",
|
|
25
|
+
"build:types": "tsc",
|
|
26
|
+
"build": "npm run format && npm run build:esm && npm run build:cjs && npm run build:types"
|
|
27
|
+
},
|
|
28
|
+
"author": "FastPix, Inc",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.10.1",
|
|
32
|
+
"esbuild": "^0.24.0",
|
|
33
|
+
"prettier": "^3.4.2",
|
|
34
|
+
"ts-node": "^10.9.2",
|
|
35
|
+
"typescript": "^5.6.3"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Error field structure for detailed error reporting
|
|
2
|
+
type ErrorField = { key: string; value: string };
|
|
3
|
+
|
|
4
|
+
// Interface for pagination options
|
|
5
|
+
export interface PaginationProps {
|
|
6
|
+
limit?: number | string;
|
|
7
|
+
offset?: number | string;
|
|
8
|
+
orderBy?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Interface for access policy configuration
|
|
12
|
+
export interface AccessPolicy {
|
|
13
|
+
accessPolicy: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Interface for media properties
|
|
17
|
+
export interface MediaProps {
|
|
18
|
+
mediaId?: string;
|
|
19
|
+
playbackId?: string[] | string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Interface for update operations with dynamic key-value pairs
|
|
23
|
+
export interface UpdateObject {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Interface for live stream properties
|
|
28
|
+
export interface LiveStreamProps {
|
|
29
|
+
streamId?: string;
|
|
30
|
+
playbackId?: string[] | string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Interface for simulcast properties
|
|
34
|
+
export interface SimulcastProps {
|
|
35
|
+
streamId?: string;
|
|
36
|
+
simulcastId?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Interface for simulcast object configuration
|
|
40
|
+
export interface SimulcastObject {
|
|
41
|
+
url: string;
|
|
42
|
+
streamKey: string;
|
|
43
|
+
metadata?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Metadata object for tagging videos
|
|
47
|
+
interface Metadata {
|
|
48
|
+
[key: string]: string; // Key-value pairs for metadata
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Interface for configuration error response
|
|
52
|
+
export interface ConfigErrorResponse {
|
|
53
|
+
success: boolean;
|
|
54
|
+
error: {
|
|
55
|
+
code: number;
|
|
56
|
+
message: string;
|
|
57
|
+
fields?: ErrorField[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Interface for constructing request objects
|
|
62
|
+
export interface RequestObject {
|
|
63
|
+
httpAgent?: string;
|
|
64
|
+
domain?: string;
|
|
65
|
+
encodedAuthToken?: string;
|
|
66
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
67
|
+
body?: Record<string, any> | {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Interface for HTTP header options
|
|
71
|
+
export interface HeaderOptions {
|
|
72
|
+
method: string;
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": string;
|
|
75
|
+
Authorization: string;
|
|
76
|
+
};
|
|
77
|
+
body?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Interface for fetch responses
|
|
81
|
+
export interface FetchResponse {
|
|
82
|
+
success: boolean;
|
|
83
|
+
data?: any;
|
|
84
|
+
error?: {
|
|
85
|
+
code: number;
|
|
86
|
+
message: string;
|
|
87
|
+
fields?: ErrorField[];
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Input Media Settings object
|
|
92
|
+
interface InputMediaSettings {
|
|
93
|
+
maxResolution?: string; // Max resolution for encoding, default: 1080p
|
|
94
|
+
reconnectWindow?: number; // Reconnect window in seconds (60 to 1800, default: 60)
|
|
95
|
+
mediaPolicy?: string; // Determines media policy for VOD, default: public
|
|
96
|
+
metadata?: Metadata; // Optional dynamic metadata key-value pairs
|
|
97
|
+
enableDvrMode?: boolean; // Enable DVR mode, default: false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Interface for initiating live stream properties
|
|
101
|
+
export interface InitiateLiveStreamProps {
|
|
102
|
+
playbackSettings?: AccessPolicy; // Required playback settings
|
|
103
|
+
inputMediaSettings?: InputMediaSettings; // Required input media settings
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Interface for updating simulcast properties
|
|
107
|
+
export interface UpdateSimulcastProps {
|
|
108
|
+
isEnabled?: boolean;
|
|
109
|
+
metadata?: Metadata;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Interface for Fetcher utility methods
|
|
113
|
+
export interface FetcherProps {
|
|
114
|
+
fetchData(url: string, header: HeaderOptions): Promise<FetchResponse>;
|
|
115
|
+
constructUrl(
|
|
116
|
+
requestObj?: RequestObject,
|
|
117
|
+
path?: string,
|
|
118
|
+
queryParams?: string
|
|
119
|
+
): string;
|
|
120
|
+
constructHeaders(requestObj: RequestObject): HeaderOptions;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface WatermarkPlacement {
|
|
124
|
+
xAlign?: string;
|
|
125
|
+
xMargin?: string;
|
|
126
|
+
yAlign?: string;
|
|
127
|
+
yMargin?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
interface Watermark {
|
|
131
|
+
placement?: WatermarkPlacement;
|
|
132
|
+
type?: string;
|
|
133
|
+
url?: string;
|
|
134
|
+
width?: string;
|
|
135
|
+
height?: string;
|
|
136
|
+
opacity?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface ImposeTrack {
|
|
140
|
+
url?: string;
|
|
141
|
+
startTime?: number;
|
|
142
|
+
endTime?: number;
|
|
143
|
+
fadeInLevel?: number;
|
|
144
|
+
fadeOutLevel?: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface Audio {
|
|
148
|
+
type?: string;
|
|
149
|
+
swapTrackUrl?: string;
|
|
150
|
+
imposeTracks?: ImposeTrack[];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface VideoInput {
|
|
154
|
+
type?: string; // required
|
|
155
|
+
url?: string; // required
|
|
156
|
+
watermark?: Watermark;
|
|
157
|
+
placement?: WatermarkPlacement;
|
|
158
|
+
opacity?: string;
|
|
159
|
+
swapTrackUrl?: string;
|
|
160
|
+
audio?: Audio;
|
|
161
|
+
startTime?: number;
|
|
162
|
+
endTime?: number;
|
|
163
|
+
introUrl?: string;
|
|
164
|
+
outroUrl?: string;
|
|
165
|
+
width?: string;
|
|
166
|
+
height?: string;
|
|
167
|
+
expungeSegments?: string[];
|
|
168
|
+
imposeTracks?: ImposeTrack[];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
interface Subtitle {
|
|
172
|
+
metadata?: Record<string, string>; // Key-value pairs for metadata
|
|
173
|
+
languageName?: string;
|
|
174
|
+
languageCode?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface MediaSettings {
|
|
178
|
+
metadata?: Metadata;
|
|
179
|
+
subtitle?: Subtitle;
|
|
180
|
+
accessPolicy?: string; // required
|
|
181
|
+
optimizeAudio?: boolean;
|
|
182
|
+
maxResolution?: string;
|
|
183
|
+
inputs?: VideoInput[]; // Inputs are part of MediaSettings
|
|
184
|
+
mp4Support?: string;
|
|
185
|
+
startTime?: number;
|
|
186
|
+
endTime?: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
interface PushMediaSettings {
|
|
190
|
+
accessPolicy?: string; // required
|
|
191
|
+
metadata?: Metadata;
|
|
192
|
+
subtitles?: Subtitle;
|
|
193
|
+
optimizeAudio?: boolean;
|
|
194
|
+
maxResolution?: string;
|
|
195
|
+
startTime?: number;
|
|
196
|
+
endTime?: number;
|
|
197
|
+
inputs?: VideoInput[]; // Inputs are part of PushMediaSettings
|
|
198
|
+
mp4Support?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface UploadMediaFromUrlProps {
|
|
202
|
+
metadata?: Metadata;
|
|
203
|
+
subtitles?: Subtitle;
|
|
204
|
+
accessPolicy?: string; // required
|
|
205
|
+
optimizeAudio?: boolean;
|
|
206
|
+
maxResolution?: string;
|
|
207
|
+
inputs?: VideoInput[];
|
|
208
|
+
mp4Support?: string;
|
|
209
|
+
startTime?: number;
|
|
210
|
+
endTime?: number;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface DirectUploadRequest {
|
|
214
|
+
corsOrigin?: string;
|
|
215
|
+
pushMediaSettings?: PushMediaSettings; // Settings for media upload configuration, including inputs
|
|
216
|
+
mediaSettings?: MediaSettings; // General media settings including access control, resolution, etc.
|
|
217
|
+
}
|