@eluvio/elv-client-js 3.1.79 → 3.1.80

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,179 @@
1
+ // convert an offering to a just-started VoD-as-Live item
2
+
3
+ const Utility = require("./lib/Utility");
4
+
5
+ const {NewOpt} = require("./lib/options");
6
+
7
+ const Client = require("./lib/concerns/Client");
8
+ const ExistObjOrVer = require("./lib/concerns/ExistObjOrVer");
9
+ const kindOf = require("kind-of");
10
+ const R = require("ramda");
11
+
12
+
13
+ class ChannelGetTestUrls extends Utility {
14
+ blueprint() {
15
+ return {
16
+ concerns: [Client, ExistObjOrVer],
17
+ options: [
18
+ NewOpt("offeringKey",
19
+ {
20
+ default: "default",
21
+ descTemplate: "Which offering within channel to get URLs for",
22
+ type: "string"
23
+ })
24
+ ]
25
+ };
26
+ }
27
+
28
+ async body() {
29
+ const logger = this.logger;
30
+
31
+ // operations that need to wait on network access
32
+ // ----------------------------------------------------
33
+ const {libraryId, objectId, versionHash, offeringKey} = await this.concerns.ExistObjOrVer.argsProc();
34
+
35
+ const offerings = await this.concerns.ExistObjOrVer.metadata({subtree:"/channel/offerings"});
36
+ if(!offerings) {
37
+ throw Error("No offerings found in channel");
38
+ }
39
+
40
+ if(!offerings[offeringKey]) {
41
+ throw Error(`Offering '${offeringKey}' not found in channel`);
42
+ }
43
+
44
+ if(!offerings[offeringKey].items) throw Error(`/channel/offerings/${offeringKey}/items not found in object metadata`);
45
+
46
+ if(kindOf(offerings[offeringKey].items) !== "array") throw Error(`/channel/offerings/${offeringKey}/items in object metadata is not an array`);
47
+
48
+ if(offerings[offeringKey].items.length === 0) throw Error(`/channel/offerings/${offeringKey}/items in object metadata is empty`);
49
+
50
+ const client = await this.concerns.Client.get();
51
+
52
+
53
+ // get an auth token for each item to include in playout URLs
54
+ const mezAuthTokens = [];
55
+ const items = offerings[offeringKey].items;
56
+
57
+ const RE_URI_HASH = /\/(hq__[a-zA-Z0-9]+)\//;
58
+ logger.log("Generating auth tokens...");
59
+ for(let i = 0; i < items.length; i++) {
60
+ const itemURI = items[i].source["/"];
61
+ const mezVersionHash = RE_URI_HASH.exec(itemURI)[1];
62
+ if(!mezVersionHash) throw Error(`hash not found in item URI: ${itemURI}`);
63
+
64
+ const mezObjectId = this.concerns.Version.objectId({versionHash: mezVersionHash});
65
+ const mezLibId = await this.concerns.FabricObject.libraryId({objectId: mezObjectId});
66
+
67
+ mezAuthTokens.push(
68
+ await client.authClient.AuthorizationToken(
69
+ {
70
+ libraryId: mezLibId,
71
+ objectId: mezObjectId,
72
+ versionHash: mezVersionHash,
73
+ update: false
74
+ }
75
+ )
76
+ );
77
+ }
78
+
79
+
80
+ const url = await client.FabricUrl({
81
+ libraryId,
82
+ objectId,
83
+ versionHash,
84
+ rep: "channel/options.json"
85
+ });
86
+
87
+ logger.data("version_hash", versionHash);
88
+ logger.data("options_url", url);
89
+
90
+ logger.log();
91
+ logger.log(`Version hash: ${versionHash}`);
92
+ logger.log();
93
+
94
+ logger.log("Sample command for obtaining channel information (NOT for public distribution!)");
95
+ logger.log();
96
+ logger.log("curl '" + url + "' | jq");
97
+
98
+ const offeringUrl = await client.FabricUrl({
99
+ libraryId,
100
+ objectId,
101
+ versionHash,
102
+ rep: `channel/${offeringKey}/options.json`
103
+ });
104
+ logger.log();
105
+ logger.log("Sample command for obtaining test playout URLs (NOT for public distribution!)");
106
+ logger.log();
107
+ logger.log("curl '" + offeringUrl + "' | jq");
108
+
109
+ // NOTE: although following line calls ElvClient.AvailableOfferings(), it is not actually
110
+ // retrieving available offerings, it is retrieving all available playback formats for channel offering
111
+ // (due to handler setting)
112
+ const offeringOptions = await client.AvailableOfferings({
113
+ libraryId,
114
+ objectId,
115
+ versionHash,
116
+ handler: `channel/${offeringKey}`
117
+ });
118
+
119
+ let offUrlObj = new URL(offeringUrl);
120
+ const urlBase = offUrlObj.origin + offUrlObj.pathname;
121
+ const authToken = offUrlObj.searchParams.get("authorization");
122
+ let sid = "";
123
+ for(const [playoutFormatKey, playoutFormatInfo] of Object.entries(offeringOptions)) {
124
+ const pfUrlObj = new URL(playoutFormatInfo.uri, urlBase);
125
+ sid = pfUrlObj.searchParams.get("sid");
126
+ const playoutUrl = new URL(playoutFormatInfo.uri, urlBase);
127
+ playoutUrl.searchParams.set("authorization", authToken);
128
+ mezAuthTokens.forEach(t => playoutUrl.searchParams.append("authorization", t));
129
+ playoutUrl.searchParams.set("sid", sid);
130
+
131
+ logger.log();
132
+ logger.log(`Sample test playout URL for format '${playoutFormatKey}' (NOT for public distribution!):`);
133
+ logger.log();
134
+ logger.log(playoutUrl.toString());
135
+ }
136
+
137
+ const multiviewPresent = offerings[offeringKey].multiview &&
138
+ !R.empty(offerings[offeringKey].multiview);
139
+ if(multiviewPresent) {
140
+ const viewsUrl = await client.FabricUrl({
141
+ libraryId,
142
+ objectId,
143
+ versionHash,
144
+ rep: `channel/${offeringKey}/views.json`
145
+ });
146
+ const viewsUrlObj = new URL(viewsUrl);
147
+ viewsUrlObj.searchParams.set("sid", sid);
148
+ logger.log();
149
+ logger.log(`Sample offering '${offeringKey}' current available views URL (sid must be same as in playout URL):`);
150
+ logger.log();
151
+ logger.log(viewsUrlObj.toString());
152
+
153
+
154
+ const selectViewUrl = await client.FabricUrl({
155
+ libraryId,
156
+ objectId,
157
+ versionHash,
158
+ rep: `channel/${offeringKey}/select_view`
159
+ });
160
+ const viewSelectUrlObj = new URL(selectViewUrl);
161
+ viewSelectUrlObj.searchParams.set("sid", sid);
162
+
163
+ logger.log();
164
+ logger.log("Sample curl command to select view (sid must be same as in playout URL):");
165
+ logger.log();
166
+ logger.log(`curl -X POST '${viewSelectUrlObj.toString()}' -d '{"view":1}'`);
167
+ }
168
+ }
169
+
170
+ header() {
171
+ return `Get test playout URLs for channel object ${this.args.objectId}`;
172
+ }
173
+ }
174
+
175
+ if(require.main === module) {
176
+ Utility.cmdLineInvoke(ChannelGetTestUrls);
177
+ } else {
178
+ module.exports = ChannelGetTestUrls;
179
+ }
@@ -166,7 +166,6 @@ class MezzanineCreate extends Utility {
166
166
  logger.errorsAndWarnings(createResponse);
167
167
 
168
168
  const objectId = createResponse.id;
169
- await client.SetVisibility({id: objectId, visibility: 0});
170
169
 
171
170
  logger.log("Starting Mezzanine Job(s)");
172
171