@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/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const buffer_1 = require("buffer");
7
+ const VideoOnDemand_1 = __importDefault(require("./VideoOnDemand"));
8
+ const Live_1 = __importDefault(require("./Live"));
9
+ class Client {
10
+ constructor(props) {
11
+ this.mediaService = null; // Media service instance
12
+ this.liveStream = null; // Live stream service instance
13
+ this.accessTokenId = props === null || props === void 0 ? void 0 : props.accessTokenId;
14
+ this.secretKey = props === null || props === void 0 ? void 0 : props.secretKey;
15
+ this.validateSecrets();
16
+ this.mediaService = new VideoOnDemand_1.default();
17
+ this.liveStream = new Live_1.default();
18
+ // Encode the access token and secret key into a base64 string
19
+ if (this.accessTokenId && this.secretKey) {
20
+ this.encodedAuthToken = buffer_1.Buffer.from(`${this.accessTokenId}:${this.secretKey}`).toString("base64");
21
+ }
22
+ // Set up the default request object
23
+ this.RequestObject = {
24
+ httpAgent: "https",
25
+ domain: "v1.fastpix.io",
26
+ encodedAuthToken: this.encodedAuthToken,
27
+ };
28
+ }
29
+ // Validate the provided credentials
30
+ validateSecrets() {
31
+ if (!this.accessTokenId || typeof this.accessTokenId !== "string") {
32
+ throw new Error('Invalid accessTokenId: The "accessTokenId" is required.');
33
+ }
34
+ if (!this.secretKey || typeof this.secretKey !== "string") {
35
+ throw new Error('Invalid secretKey: The "secretKey" is required.');
36
+ }
37
+ }
38
+ // Media Methods
39
+ // Uploads media from a given URL
40
+ uploadMediaFromUrl(props) {
41
+ return this.mediaService
42
+ ? this.mediaService.createAsset(this.RequestObject, props)
43
+ : null;
44
+ }
45
+ // Uploads media from a file input.
46
+ uploadMediaFromDevice(props) {
47
+ return this.mediaService
48
+ ? this.mediaService.uploadAsset(this.RequestObject, props)
49
+ : null;
50
+ }
51
+ // Retrieves all media assets with pagination.
52
+ getAllMediaAssets(props) {
53
+ return this.mediaService
54
+ ? this.mediaService.getAllAssets(props, this.RequestObject)
55
+ : null;
56
+ }
57
+ // Fetches a media asset by its ID.
58
+ getMediaAssetById(props) {
59
+ return this.mediaService
60
+ ? this.mediaService.getAsset(props, this.RequestObject)
61
+ : null;
62
+ }
63
+ // Fetches information about a media asset by its ID.
64
+ getMediaAssetInfo(props) {
65
+ return this.mediaService
66
+ ? this.mediaService.getAssetInfo(props, this.RequestObject)
67
+ : null;
68
+ }
69
+ // Modifies metadata of an existing media asset.
70
+ updateMediaAsset(props, updateObject) {
71
+ return this.mediaService
72
+ ? this.mediaService.updateAsset(props, updateObject, this.RequestObject)
73
+ : null;
74
+ }
75
+ // Removes a media asset by its ID.
76
+ deleteMediaAsset(props) {
77
+ return this.mediaService
78
+ ? this.mediaService.deleteAsset(props, this.RequestObject)
79
+ : null;
80
+ }
81
+ // Creates a playback ID for a media asset.
82
+ generateMediaPlaybackId(props, accessPolicy) {
83
+ return this.mediaService
84
+ ? this.mediaService.addMediaPlaybackId(props, accessPolicy, this.RequestObject)
85
+ : null;
86
+ }
87
+ // Removes a playback ID from a media asset.
88
+ deleteMediaPlaybackId(props) {
89
+ return this.mediaService
90
+ ? this.mediaService.removeMediaPlaybackId(props, this.RequestObject)
91
+ : null;
92
+ }
93
+ // Initiates a new live stream.
94
+ initiateLiveStream(props) {
95
+ return this.liveStream
96
+ ? this.liveStream.createNewLiveStream(props, this.RequestObject)
97
+ : null;
98
+ }
99
+ // Retrieves all live streams with pagination.
100
+ getAllLiveStreams(props) {
101
+ return this.liveStream
102
+ ? this.liveStream.getAllLiveStreams(props, this.RequestObject)
103
+ : null;
104
+ }
105
+ // Fetches a live stream by its ID.
106
+ getLiveStreamById(props) {
107
+ return this.liveStream
108
+ ? this.liveStream.getLiveStream(props, this.RequestObject)
109
+ : null;
110
+ }
111
+ // Modifies an existing live stream.
112
+ updateLiveStream(props, updateObject) {
113
+ return this.liveStream
114
+ ? this.liveStream.updateLiveStream(props, updateObject, this.RequestObject)
115
+ : null;
116
+ }
117
+ // Removes a live stream by its ID.
118
+ deleteLiveStream(props) {
119
+ return this.liveStream
120
+ ? this.liveStream.deleteLiveStream(props, this.RequestObject)
121
+ : null;
122
+ }
123
+ // Creates a playback ID for a live stream.
124
+ generateLiveStreamPlaybackId(props, accessPolicy) {
125
+ return this.liveStream
126
+ ? this.liveStream.createLiveStreamPlaybackId(props, accessPolicy, this.RequestObject)
127
+ : null;
128
+ }
129
+ // Removes a playback ID from a live stream.
130
+ deleteLiveStreamPlaybackId(props) {
131
+ return this.liveStream
132
+ ? this.liveStream.removeLivePlaybackId(props, this.RequestObject)
133
+ : null;
134
+ }
135
+ // Fetches the playback policy for a live stream.
136
+ getLiveStreamPlaybackPolicy(props) {
137
+ return this.liveStream
138
+ ? this.liveStream.getLiveStreamPlaybackPolicy(props, this.RequestObject)
139
+ : null;
140
+ }
141
+ // Initiates a simulcast for a live stream.
142
+ initiateLiveStreamSimulcast(props, liveStreamObj) {
143
+ return this.liveStream
144
+ ? this.liveStream.createLiveStreamSimulcast(props, liveStreamObj, this.RequestObject)
145
+ : null;
146
+ }
147
+ // Retrieves a simulcast for a live stream.
148
+ getLiveStreamSimulcast(props) {
149
+ return this.liveStream
150
+ ? this.liveStream.getLiveStreamSimulcast(props, this.RequestObject)
151
+ : null;
152
+ }
153
+ // Modifies an existing simulcast for a live stream.
154
+ updateLiveStreamSimulcast(props, simulcastObj) {
155
+ return this.liveStream
156
+ ? this.liveStream.updateLiveStreamSimulcast(props, simulcastObj, this.RequestObject)
157
+ : null;
158
+ }
159
+ // Removes a simulcast from a live stream.
160
+ deleteLiveStreamSimulcast(props) {
161
+ return this.liveStream
162
+ ? this.liveStream.deleteLiveStreamSimulcast(props, this.RequestObject)
163
+ : null;
164
+ }
165
+ }
166
+ exports.default = Client;