@eluvio/elv-client-js 4.0.111 → 4.0.113

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.
Files changed (125) hide show
  1. package/package.json +1 -1
  2. package/src/FrameClient.js +2 -0
  3. package/dist/ElvClient-min.js +0 -67
  4. package/dist/ElvClient-node-min.js +0 -66
  5. package/dist/ElvFrameClient-min.js +0 -60
  6. package/dist/ElvPermissionsClient-min.js +0 -60
  7. package/dist/ElvWalletClient-min.js +0 -67
  8. package/dist/ElvWalletClient-node-min.js +0 -66
  9. package/dist/src/AuthorizationClient.js +0 -2157
  10. package/dist/src/ContentObjectAudit.js +0 -175
  11. package/dist/src/ContentObjectVerification.js +0 -281
  12. package/dist/src/Crypto.js +0 -412
  13. package/dist/src/ElvClient.js +0 -2049
  14. package/dist/src/ElvWallet.js +0 -245
  15. package/dist/src/EthClient.js +0 -1154
  16. package/dist/src/FrameClient.js +0 -485
  17. package/dist/src/HttpClient.js +0 -315
  18. package/dist/src/Id.js +0 -21
  19. package/dist/src/LogMessage.js +0 -25
  20. package/dist/src/PermissionsClient.js +0 -1544
  21. package/dist/src/RemoteSigner.js +0 -385
  22. package/dist/src/UserProfileClient.js +0 -1450
  23. package/dist/src/Utils.js +0 -894
  24. package/dist/src/Validation.js +0 -121
  25. package/dist/src/abr_profiles/abr_profile_live_drm.js +0 -1661
  26. package/dist/src/abr_profiles/abr_profile_live_to_vod.js +0 -1606
  27. package/dist/src/client/ABRPublishing.js +0 -1018
  28. package/dist/src/client/AccessGroups.js +0 -1503
  29. package/dist/src/client/ContentAccess.js +0 -5173
  30. package/dist/src/client/ContentManagement.js +0 -2680
  31. package/dist/src/client/Contracts.js +0 -1520
  32. package/dist/src/client/Files.js +0 -2181
  33. package/dist/src/client/LiveConf.js +0 -567
  34. package/dist/src/client/LiveStream.js +0 -2638
  35. package/dist/src/client/NFT.js +0 -162
  36. package/dist/src/client/NTP.js +0 -581
  37. package/dist/src/contracts/v2/AccessIndexor.js +0 -831
  38. package/dist/src/contracts/v2/Accessible.js +0 -31
  39. package/dist/src/contracts/v2/BaseAccessControlGroup.js +0 -1263
  40. package/dist/src/contracts/v2/BaseAccessWallet.js +0 -1609
  41. package/dist/src/contracts/v2/BaseAccessWalletFactory.js +0 -93
  42. package/dist/src/contracts/v2/BaseContent.js +0 -1076
  43. package/dist/src/contracts/v2/BaseContentFactory.js +0 -219
  44. package/dist/src/contracts/v2/BaseContentSpace.js +0 -1352
  45. package/dist/src/contracts/v2/BaseContentType.js +0 -364
  46. package/dist/src/contracts/v2/BaseFactory.js +0 -107
  47. package/dist/src/contracts/v2/BaseGroupFactory.js +0 -93
  48. package/dist/src/contracts/v2/BaseLibrary.js +0 -1041
  49. package/dist/src/contracts/v2/BaseLibraryFactory.js +0 -96
  50. package/dist/src/contracts/v2/Certifyer.js +0 -86
  51. package/dist/src/contracts/v2/Container.js +0 -540
  52. package/dist/src/contracts/v2/Content.js +0 -443
  53. package/dist/src/contracts/v2/Editable.js +0 -306
  54. package/dist/src/contracts/v2/ExternalUserWallet.js +0 -379
  55. package/dist/src/contracts/v2/IFactorySpace.js +0 -57
  56. package/dist/src/contracts/v2/IKmsSpace.js +0 -52
  57. package/dist/src/contracts/v2/INodeSpace.js +0 -18
  58. package/dist/src/contracts/v2/IUserSpace.js +0 -18
  59. package/dist/src/contracts/v2/LvRecordableStream.js +0 -1037
  60. package/dist/src/contracts/v2/LvRecording.js +0 -627
  61. package/dist/src/contracts/v2/LvStreamRightsHolder.js +0 -562
  62. package/dist/src/contracts/v2/MetaObject.js +0 -119
  63. package/dist/src/contracts/v2/Node.js +0 -167
  64. package/dist/src/contracts/v2/NodeSpace.js +0 -273
  65. package/dist/src/contracts/v2/Ownable.js +0 -87
  66. package/dist/src/contracts/v2/PaymentService.js +0 -627
  67. package/dist/src/contracts/v2/Precompile.js +0 -15
  68. package/dist/src/contracts/v2/Transactable.js +0 -82
  69. package/dist/src/contracts/v2/UserSpace.js +0 -29
  70. package/dist/src/contracts/v2/Utils.js +0 -18
  71. package/dist/src/contracts/v2/Verifier.js +0 -53
  72. package/dist/src/contracts/v2/strings.js +0 -4
  73. package/dist/src/contracts/v3/AccessIndexor.js +0 -774
  74. package/dist/src/contracts/v3/Accessible.js +0 -232
  75. package/dist/src/contracts/v3/Adminable.js +0 -107
  76. package/dist/src/contracts/v3/AvailsDelivery.js +0 -586
  77. package/dist/src/contracts/v3/BaseAccessControlGroup.js +0 -1603
  78. package/dist/src/contracts/v3/BaseAccessWallet.js +0 -1628
  79. package/dist/src/contracts/v3/BaseAccessWalletFactory.js +0 -112
  80. package/dist/src/contracts/v3/BaseContent.js +0 -1312
  81. package/dist/src/contracts/v3/BaseContentFactory.js +0 -183
  82. package/dist/src/contracts/v3/BaseContentFactoryExt.js +0 -175
  83. package/dist/src/contracts/v3/BaseContentSpace.js +0 -1515
  84. package/dist/src/contracts/v3/BaseContentType.js +0 -527
  85. package/dist/src/contracts/v3/BaseFactory.js +0 -126
  86. package/dist/src/contracts/v3/BaseGroupFactory.js +0 -112
  87. package/dist/src/contracts/v3/BaseLibrary.js +0 -1204
  88. package/dist/src/contracts/v3/BaseLibraryFactory.js +0 -115
  89. package/dist/src/contracts/v3/BaseTenantSpace.js +0 -1587
  90. package/dist/src/contracts/v3/Certifyer.js +0 -86
  91. package/dist/src/contracts/v3/Container.js +0 -739
  92. package/dist/src/contracts/v3/Content.js +0 -438
  93. package/dist/src/contracts/v3/CounterObject.js +0 -243
  94. package/dist/src/contracts/v3/Editable.js +0 -519
  95. package/dist/src/contracts/v3/EncToken.js +0 -4
  96. package/dist/src/contracts/v3/ExternalUserWallet.js +0 -587
  97. package/dist/src/contracts/v3/IAdmin.js +0 -18
  98. package/dist/src/contracts/v3/IFactorySpace.js +0 -57
  99. package/dist/src/contracts/v3/IKmsSpace.js +0 -52
  100. package/dist/src/contracts/v3/INodeSpace.js +0 -18
  101. package/dist/src/contracts/v3/IUserSpace.js +0 -32
  102. package/dist/src/contracts/v3/LvRecordableStream.js +0 -1032
  103. package/dist/src/contracts/v3/LvRecording.js +0 -650
  104. package/dist/src/contracts/v3/LvStreamRightsHolder.js +0 -557
  105. package/dist/src/contracts/v3/MetaObject.js +0 -144
  106. package/dist/src/contracts/v3/Node.js +0 -178
  107. package/dist/src/contracts/v3/NodeSpace.js +0 -284
  108. package/dist/src/contracts/v3/Ownable.js +0 -98
  109. package/dist/src/contracts/v3/PaymentService.js +0 -622
  110. package/dist/src/contracts/v3/Precompile.js +0 -26
  111. package/dist/src/contracts/v3/TenantFuncsBase.js +0 -351
  112. package/dist/src/contracts/v3/Transactable.js +0 -82
  113. package/dist/src/contracts/v3/UserSpace.js +0 -43
  114. package/dist/src/contracts/v3/Utils.js +0 -18
  115. package/dist/src/contracts/v3/Verifier.js +0 -53
  116. package/dist/src/contracts/v3/strings.js +0 -4
  117. package/dist/src/contracts/v3b/BaseAccessControlGroup.js +0 -1704
  118. package/dist/src/events/Topics.js +0 -1793
  119. package/dist/src/index.js +0 -8
  120. package/dist/src/walletClient/ClientMethods.js +0 -3102
  121. package/dist/src/walletClient/Configuration.js +0 -38
  122. package/dist/src/walletClient/Notifications.js +0 -168
  123. package/dist/src/walletClient/Profile.js +0 -332
  124. package/dist/src/walletClient/Utils.js +0 -281
  125. package/dist/src/walletClient/index.js +0 -2106
@@ -1,2638 +0,0 @@
1
- var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
- var _defineProperty = require("@babel/runtime/helpers/defineProperty");
3
- var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
- var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
5
- var _this = this;
6
- /**
7
- * Methods for Live Stream creation and management
8
- *
9
- * @module ElvClient/LiveStream
10
- */
11
-
12
- var _require = require("./LiveConf"),
13
- LiveConf = _require.LiveConf;
14
- var path = require("path");
15
- var fs = require("fs");
16
- var HttpClient = require("../HttpClient");
17
- var Fraction = require("fraction.js");
18
- var _require2 = require("../Validation"),
19
- ValidateObject = _require2.ValidateObject,
20
- ValidatePresence = _require2.ValidatePresence;
21
- var ContentObjectAudit = require("../ContentObjectAudit");
22
- var MakeTxLessToken = /*#__PURE__*/function () {
23
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
24
- var client, libraryId, objectId, versionHash, tok;
25
- return _regeneratorRuntime.wrap(function _callee$(_context) {
26
- while (1) switch (_context.prev = _context.next) {
27
- case 0:
28
- client = _ref.client, libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash;
29
- _context.next = 3;
30
- return client.authClient.AuthorizationToken({
31
- libraryId: libraryId,
32
- objectId: objectId,
33
- versionHash: versionHash,
34
- channelAuth: false,
35
- noCache: true,
36
- noAuth: true
37
- });
38
- case 3:
39
- tok = _context.sent;
40
- return _context.abrupt("return", tok);
41
- case 5:
42
- case "end":
43
- return _context.stop();
44
- }
45
- }, _callee);
46
- }));
47
- return function MakeTxLessToken(_x) {
48
- return _ref2.apply(this, arguments);
49
- };
50
- }();
51
- var Sleep = function Sleep(ms) {
52
- return new Promise(function (resolve) {
53
- return setTimeout(resolve, ms);
54
- });
55
- };
56
- var CueInfo = /*#__PURE__*/function () {
57
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
58
- var eventId, status, cues, lroStatusResponse, eventStart, eventEnd, _i, _Object$values, value, _i2, _Object$values2, event;
59
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
60
- while (1) switch (_context2.prev = _context2.next) {
61
- case 0:
62
- eventId = _ref3.eventId, status = _ref3.status;
63
- _context2.prev = 1;
64
- _context2.t0 = _this.utils;
65
- _context2.next = 5;
66
- return HttpClient.Fetch(status.lro_status_url);
67
- case 5:
68
- _context2.t1 = _context2.sent;
69
- _context2.next = 8;
70
- return _context2.t0.ResponseToJson.call(_context2.t0, _context2.t1);
71
- case 8:
72
- lroStatusResponse = _context2.sent;
73
- console.log("lroStatusResponse", lroStatusResponse);
74
- cues = lroStatusResponse.custom.cues;
75
- _context2.next = 17;
76
- break;
77
- case 13:
78
- _context2.prev = 13;
79
- _context2.t2 = _context2["catch"](1);
80
- console.log("LRO status failed", _context2.t2);
81
- return _context2.abrupt("return", {
82
- error: "failed to retrieve status",
83
- eventId: eventId
84
- });
85
- case 17:
86
- _i = 0, _Object$values = Object.values(cues);
87
- case 18:
88
- if (!(_i < _Object$values.length)) {
89
- _context2.next = 37;
90
- break;
91
- }
92
- value = _Object$values[_i];
93
- _i2 = 0, _Object$values2 = Object.values(value.descriptors);
94
- case 21:
95
- if (!(_i2 < _Object$values2.length)) {
96
- _context2.next = 34;
97
- break;
98
- }
99
- event = _Object$values2[_i2];
100
- if (!(event.id == eventId)) {
101
- _context2.next = 31;
102
- break;
103
- }
104
- _context2.t3 = event.type_id;
105
- _context2.next = _context2.t3 === 32 ? 27 : _context2.t3 === 16 ? 27 : _context2.t3 === 33 ? 29 : _context2.t3 === 17 ? 29 : 31;
106
- break;
107
- case 27:
108
- eventStart = value.insertion_time;
109
- return _context2.abrupt("break", 31);
110
- case 29:
111
- eventEnd = value.insertion_time;
112
- return _context2.abrupt("break", 31);
113
- case 31:
114
- _i2++;
115
- _context2.next = 21;
116
- break;
117
- case 34:
118
- _i++;
119
- _context2.next = 18;
120
- break;
121
- case 37:
122
- return _context2.abrupt("return", {
123
- eventStart: eventStart,
124
- eventEnd: eventEnd,
125
- eventId: eventId
126
- });
127
- case 38:
128
- case "end":
129
- return _context2.stop();
130
- }
131
- }, _callee2, null, [[1, 13]]);
132
- }));
133
- return function CueInfo(_x2) {
134
- return _ref4.apply(this, arguments);
135
- };
136
- }();
137
-
138
- /**
139
- * Set the offering for the live stream
140
- *
141
- * @methodGroup Live Stream
142
- * @namedParams
143
- * @param {Object} client - The client object
144
- * @param {string} libraryId - ID of the library for the new live stream object
145
- * @param {string} objectId - ID of the new live stream object
146
- * @param {string=} typeAbrMaster - Content type hash
147
- * @param {string=} typeLiveStream - Content type hash
148
- * @param {string} streamUrl - Live source URL
149
- * @param {object} abrProfile - ABR Profile for the offering
150
- * @param {number} aBitRate - Audio bitrate
151
- * @param {number} aChannels - Audio channels
152
- * @param {number} aSampleRate - Audio sample rate
153
- * @param {number} aStreamIndex - Audio stream index
154
- * @param {string} aTimeBase - Audio time base as a fraction, e.g. "1/48000" (usually equal to 1/aSampleRate)
155
- * @param {string} aChannelLayout - Channel layout, e.g. "stereo"
156
- * @param {number} vBitRate - Video bitrate
157
- * @param {number} vHeight - Video height
158
- * @param {number} vStreamIndex - Video stream index
159
- * @param {number} vWidth - Video width
160
- * @param {string} vDisplayAspectRatio - Display aspect ratio as a fraction, e.g. "16/9"
161
- * @param {string} vFrameRate - Frame rate as an integer, e.g. "30"
162
- * @param {string} vTimeBase - Time base as a fraction, e.g. "1/30000"
163
- *
164
- * @return {Promise<string>} - Final hash of the live stream object
165
- */
166
- var StreamGenerateOffering = /*#__PURE__*/function () {
167
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
168
- var client, libraryId, objectId, typeAbrMaster, typeLiveStream, streamUrl, abrProfile, aBitRate, aChannels, aSampleRate, aStreamIndex, aTimeBase, aChannelLayout, vBitRate, vHeight, vStreamIndex, vWidth, vDisplayAspectRatio, vFrameRate, vTimeBase, DUMMY_DURATION, aDurationTs, vDurationTs, sourceAudioStream, sourceVideoStream, DUMMY_STREAM, sourceStreams, maxStreamIndex, i, sources, variants, production_master, metadata, editResponse, writeToken, finalizeResponse, masterVersionHash, createResponse, versionHash, finalHash;
169
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
170
- while (1) switch (_context3.prev = _context3.next) {
171
- case 0:
172
- client = _ref5.client, libraryId = _ref5.libraryId, objectId = _ref5.objectId, typeAbrMaster = _ref5.typeAbrMaster, typeLiveStream = _ref5.typeLiveStream, streamUrl = _ref5.streamUrl, abrProfile = _ref5.abrProfile, aBitRate = _ref5.aBitRate, aChannels = _ref5.aChannels, aSampleRate = _ref5.aSampleRate, aStreamIndex = _ref5.aStreamIndex, aTimeBase = _ref5.aTimeBase, aChannelLayout = _ref5.aChannelLayout, vBitRate = _ref5.vBitRate, vHeight = _ref5.vHeight, vStreamIndex = _ref5.vStreamIndex, vWidth = _ref5.vWidth, vDisplayAspectRatio = _ref5.vDisplayAspectRatio, vFrameRate = _ref5.vFrameRate, vTimeBase = _ref5.vTimeBase;
173
- // compute duration_ts
174
- DUMMY_DURATION = 1001; // should result in integer duration_ts values for both audio and video
175
- aDurationTs = Fraction(aTimeBase).inverse().mul(DUMMY_DURATION).valueOf();
176
- vDurationTs = Fraction(vTimeBase).inverse().mul(DUMMY_DURATION).valueOf(); // construct /production_master/sources/STREAM_URL/streams
177
- sourceAudioStream = {
178
- "bit_rate": aBitRate,
179
- "channel_layout": aChannelLayout,
180
- "channels": aChannels,
181
- "codec_name": "aac",
182
- "duration": DUMMY_DURATION,
183
- "duration_ts": aDurationTs,
184
- "frame_count": 0,
185
- "language": "",
186
- "max_bit_rate": aBitRate,
187
- "sample_rate": aSampleRate,
188
- "start_pts": 0,
189
- "start_time": 0,
190
- "time_base": aTimeBase,
191
- "type": "StreamAudio"
192
- };
193
- sourceVideoStream = {
194
- "bit_rate": vBitRate,
195
- "codec_name": "h264",
196
- "display_aspect_ratio": vDisplayAspectRatio,
197
- "duration": DUMMY_DURATION,
198
- "duration_ts": vDurationTs,
199
- "field_order": "progressive",
200
- "frame_count": 0,
201
- "frame_rate": vFrameRate,
202
- "hdr": null,
203
- "height": vHeight,
204
- "language": "",
205
- "max_bit_rate": vBitRate,
206
- "sample_aspect_ratio": "1",
207
- "start_pts": 0,
208
- "start_time": 0,
209
- "time_base": vTimeBase,
210
- "type": "StreamVideo",
211
- "width": vWidth
212
- }; // placeholder stream to use if [aStreamIndex, vStreamIndex].sort() is not [0,1]
213
- DUMMY_STREAM = {
214
- "bit_rate": 0,
215
- "codec_name": "",
216
- "duration": DUMMY_DURATION,
217
- "duration_ts": 2500 * DUMMY_DURATION,
218
- "frame_count": 1,
219
- "language": "",
220
- "max_bit_rate": 0,
221
- "start_pts": 0,
222
- "start_time": 0,
223
- "time_base": "1/2500",
224
- "type": "StreamData"
225
- };
226
- sourceStreams = [];
227
- maxStreamIndex = Math.max(aStreamIndex, vStreamIndex);
228
- for (i = 0; i <= maxStreamIndex; i++) {
229
- if (i === aStreamIndex) {
230
- sourceStreams.push(sourceAudioStream);
231
- } else if (i === vStreamIndex) {
232
- sourceStreams.push(sourceVideoStream);
233
- } else {
234
- sourceStreams.push(DUMMY_STREAM);
235
- }
236
- }
237
-
238
- // construct /production_master/sources
239
- sources = _defineProperty({}, streamUrl, {
240
- "container_format": {
241
- "duration": DUMMY_DURATION,
242
- "filename": streamUrl,
243
- "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
244
- "start_time": 0
245
- },
246
- "streams": sourceStreams
247
- }); // construct /production_master/variants
248
- variants = {
249
- "default": {
250
- "streams": {
251
- "audio": {
252
- "default_for_media_type": false,
253
- "label": "",
254
- "language": "",
255
- "mapping_info": "",
256
- "sources": [{
257
- "files_api_path": streamUrl,
258
- "stream_index": aStreamIndex
259
- }]
260
- },
261
- "video": {
262
- "default_for_media_type": false,
263
- "label": "",
264
- "language": "",
265
- "mapping_info": "",
266
- "sources": [{
267
- "files_api_path": streamUrl,
268
- "stream_index": vStreamIndex
269
- }]
270
- }
271
- }
272
- }
273
- }; // construct /production_master
274
- production_master = {
275
- sources: sources,
276
- variants: variants
277
- }; // get existing metadata
278
- console.log("Retrieving current metadata...");
279
- _context3.next = 16;
280
- return client.ContentObjectMetadata({
281
- libraryId: libraryId,
282
- objectId: objectId
283
- });
284
- case 16:
285
- metadata = _context3.sent;
286
- // add /production_master to metadata
287
- metadata.production_master = production_master;
288
-
289
- // write back to object
290
- console.log("Getting write token...");
291
- _context3.next = 21;
292
- return client.EditContentObject({
293
- libraryId: libraryId,
294
- objectId: objectId,
295
- options: {
296
- type: typeAbrMaster
297
- }
298
- });
299
- case 21:
300
- editResponse = _context3.sent;
301
- writeToken = editResponse.write_token;
302
- console.log("New write token: ".concat(writeToken));
303
- console.log("Writing back metadata with /production_master added...");
304
- _context3.next = 27;
305
- return client.ReplaceMetadata({
306
- libraryId: libraryId,
307
- metadata: metadata,
308
- objectId: objectId,
309
- writeToken: writeToken
310
- });
311
- case 27:
312
- console.log("Finalizing...");
313
- _context3.next = 30;
314
- return client.FinalizeContentObject({
315
- libraryId: libraryId,
316
- objectId: objectId,
317
- writeToken: writeToken
318
- });
319
- case 30:
320
- finalizeResponse = _context3.sent;
321
- masterVersionHash = finalizeResponse.hash;
322
- console.log("Finalized, new version hash: ".concat(masterVersionHash));
323
-
324
- // Generate offering
325
- _context3.next = 35;
326
- return client.CreateABRMezzanine({
327
- libraryId: libraryId,
328
- objectId: objectId,
329
- masterVersionHash: masterVersionHash,
330
- variant: "default",
331
- offeringKey: "default",
332
- abrProfile: abrProfile
333
- });
334
- case 35:
335
- createResponse = _context3.sent;
336
- if (createResponse.warnings.length > 0) {
337
- console.log("WARNINGS:");
338
- console.log(JSON.stringify(createResponse.warnings, null, 2));
339
- }
340
- if (createResponse.errors.length > 0) {
341
- console.log("ERRORS:");
342
- console.log(JSON.stringify(createResponse.errors, null, 2));
343
- }
344
- versionHash = createResponse.hash;
345
- console.log("New version hash: ".concat(versionHash));
346
-
347
- // get new metadata
348
- console.log("Retrieving revised metadata with offering...");
349
- _context3.next = 43;
350
- return client.ContentObjectMetadata({
351
- libraryId: libraryId,
352
- versionHash: versionHash
353
- });
354
- case 43:
355
- metadata = _context3.sent;
356
- console.log("Moving /abr_mezzanine/offerings to /offerings and removing /abr_mezzanine...");
357
- metadata.offerings = metadata.abr_mezzanine.offerings;
358
- delete metadata.abr_mezzanine;
359
-
360
- // add items to media_struct needed to use options.json handler
361
- metadata.offerings["default"].media_struct.duration_rat = "".concat(DUMMY_DURATION);
362
-
363
- // write back to object
364
- console.log("Getting write token...");
365
- _context3.next = 51;
366
- return client.EditContentObject({
367
- libraryId: libraryId,
368
- objectId: objectId,
369
- options: {
370
- type: typeLiveStream
371
- }
372
- });
373
- case 51:
374
- editResponse = _context3.sent;
375
- writeToken = editResponse.write_token;
376
- console.log("New write token: ".concat(writeToken));
377
- console.log("Writing back metadata with /offerings...");
378
- _context3.next = 57;
379
- return client.ReplaceMetadata({
380
- libraryId: libraryId,
381
- metadata: metadata,
382
- objectId: objectId,
383
- writeToken: writeToken
384
- });
385
- case 57:
386
- console.log("Finalizing...");
387
- _context3.next = 60;
388
- return client.FinalizeContentObject({
389
- libraryId: libraryId,
390
- objectId: objectId,
391
- writeToken: writeToken
392
- });
393
- case 60:
394
- finalizeResponse = _context3.sent;
395
- finalHash = finalizeResponse.hash;
396
- console.log("Finalized, new version hash: ".concat(finalHash));
397
- return _context3.abrupt("return", finalHash);
398
- case 64:
399
- case "end":
400
- return _context3.stop();
401
- }
402
- }, _callee3);
403
- }));
404
- return function StreamGenerateOffering(_x3) {
405
- return _ref6.apply(this, arguments);
406
- };
407
- }();
408
-
409
- /**
410
- * Retrieve the status of the current live stream session
411
- *
412
- * @methodGroup Live Stream
413
- * @namedParams
414
- * @param {string} name - Object ID or name of the live stream object
415
- * @param {boolean=} stopLro - If specified, will stop LRO
416
- * @param {boolean=} showParams - If specified, will return recording_params with status
417
- * States:
418
- * unconfigured - no live_recording_config
419
- * uninitialized - no live_recording config generated
420
- * inactive - live_recording config initialized but no 'edge write token'
421
- * stopped - edge-write-token but not started
422
- * starting - LRO running but no source data yet
423
- * running - stream is running and producing output
424
- * stalled - LRO running but no source data (so not producing output)
425
- *
426
- * @return {Promise<Object>} - The status response for the object, as well as logs, warnings and errors from the master initialization
427
- */
428
- exports.StreamStatus = /*#__PURE__*/function () {
429
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
430
- var name, _ref7$stopLro, stopLro, _ref7$showParams, showParams, objectId, status, libraryId, mainMeta, fabURI, edgeWriteToken, edgeMeta, recordings, sequence, period, tlro, videoLastFinalizationTimeEpochSec, videoFinalizedParts, sinceLastFinalize, recording_period, insertions, i, insertionTimeSinceEpoch, state, lroStatus, segDurationMeta, playout_urls, playout_options, hls_clear_enabled, hls_aes128_enabled, hls_sample_aes_enabled, networkInfo, token, embed_net, embed_url;
431
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
432
- while (1) switch (_context4.prev = _context4.next) {
433
- case 0:
434
- name = _ref7.name, _ref7$stopLro = _ref7.stopLro, stopLro = _ref7$stopLro === void 0 ? false : _ref7$stopLro, _ref7$showParams = _ref7.showParams, showParams = _ref7$showParams === void 0 ? false : _ref7$showParams;
435
- objectId = name;
436
- status = {
437
- name: name
438
- };
439
- _context4.prev = 3;
440
- _context4.next = 6;
441
- return this.ContentObjectLibraryId({
442
- objectId: objectId
443
- });
444
- case 6:
445
- libraryId = _context4.sent;
446
- status.library_id = libraryId;
447
- status.object_id = objectId;
448
- _context4.next = 11;
449
- return this.ContentObjectMetadata({
450
- libraryId: libraryId,
451
- objectId: objectId,
452
- select: ["live_recording_config", "live_recording"]
453
- });
454
- case 11:
455
- mainMeta = _context4.sent;
456
- status.reference_url = mainMeta.live_recording_config.reference_url;
457
- if (!(mainMeta.live_recording_config == undefined || mainMeta.live_recording_config.url == undefined)) {
458
- _context4.next = 16;
459
- break;
460
- }
461
- status.state = "unconfigured";
462
- return _context4.abrupt("return", status);
463
- case 16:
464
- if (!(mainMeta.live_recording == undefined || mainMeta.live_recording.fabric_config == undefined || mainMeta.live_recording.playout_config == undefined || mainMeta.live_recording.recording_config == undefined)) {
465
- _context4.next = 19;
466
- break;
467
- }
468
- status.state = "uninitialized";
469
- return _context4.abrupt("return", status);
470
- case 19:
471
- fabURI = mainMeta.live_recording.fabric_config.ingress_node_api;
472
- if (!(fabURI === undefined)) {
473
- _context4.next = 24;
474
- break;
475
- }
476
- console.log("bad fabric config - missing ingress node API");
477
- status.state = "uninitialized";
478
- return _context4.abrupt("return", status);
479
- case 24:
480
- // Support both hostname and URL ingress_node_api
481
- if (!fabURI.startsWith("http")) {
482
- // Assume https
483
- fabURI = "https://" + fabURI;
484
- }
485
- status.fabric_api = fabURI;
486
- status.url = mainMeta.live_recording.recording_config.recording_params.origin_url;
487
- edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
488
- if (edgeWriteToken) {
489
- _context4.next = 31;
490
- break;
491
- }
492
- status.state = "inactive";
493
- return _context4.abrupt("return", status);
494
- case 31:
495
- this.RecordWriteToken({
496
- writeToken: edgeWriteToken,
497
- fabricNodeUrl: fabURI
498
- });
499
- status.edge_write_token = edgeWriteToken;
500
- status.stream_id = edgeWriteToken; // By convention the stream ID is its write token
501
- _context4.prev = 34;
502
- _context4.next = 37;
503
- return this.ContentObjectMetadata({
504
- libraryId: libraryId,
505
- objectId: objectId,
506
- writeToken: edgeWriteToken,
507
- select: ["live_recording"]
508
- });
509
- case 37:
510
- edgeMeta = _context4.sent;
511
- _context4.next = 45;
512
- break;
513
- case 40:
514
- _context4.prev = 40;
515
- _context4.t0 = _context4["catch"](34);
516
- console.error("Unable to read edge write token metadata. Has token been deleted?", _context4.t0);
517
- status.state = "inactive";
518
- return _context4.abrupt("return", status);
519
- case 45:
520
- status.edge_meta_size = JSON.stringify(edgeMeta || "").length;
521
-
522
- // If a stream has never been started return state 'inactive'
523
- if (!(edgeMeta.live_recording === undefined || edgeMeta.live_recording.recordings === undefined || edgeMeta.live_recording.recordings.recording_sequence === undefined)) {
524
- _context4.next = 49;
525
- break;
526
- }
527
- status.state = "stopped";
528
- return _context4.abrupt("return", status);
529
- case 49:
530
- recordings = edgeMeta.live_recording.recordings;
531
- status.recording_period_sequence = recordings.recording_sequence;
532
- sequence = recordings.recording_sequence;
533
- period = recordings.live_offering[sequence - 1];
534
- tlro = period.live_recording_handle;
535
- status.tlro = tlro;
536
- videoLastFinalizationTimeEpochSec = -1;
537
- videoFinalizedParts = 0;
538
- sinceLastFinalize = -1;
539
- if (period.finalized_parts_info && period.finalized_parts_info.video && period.finalized_parts_info.video.last_finalization_time) {
540
- videoLastFinalizationTimeEpochSec = period.finalized_parts_info.video.last_finalization_time / 1000000;
541
- videoFinalizedParts = period.finalized_parts_info.video.n_parts;
542
- sinceLastFinalize = Math.floor(new Date().getTime() / 1000) - videoLastFinalizationTimeEpochSec;
543
- }
544
- recording_period = {
545
- activation_time_epoch_sec: period.recording_start_time_epoch_sec,
546
- start_time_epoch_sec: period.start_time_epoch_sec,
547
- start_time_text: new Date(period.start_time_epoch_sec * 1000).toLocaleString(),
548
- end_time_epoch_sec: period.end_time_epoch_sec,
549
- end_time_text: period.end_time_epoch_sec === 0 ? null : new Date(period.end_time_epoch_sec * 1000).toLocaleString(),
550
- video_parts: videoFinalizedParts,
551
- video_last_part_finalized_epoch_sec: videoLastFinalizationTimeEpochSec,
552
- video_since_last_finalize_sec: sinceLastFinalize
553
- };
554
- status.recording_period = recording_period;
555
- _context4.next = 63;
556
- return this.FabricUrl({
557
- libraryId: libraryId,
558
- objectId: objectId,
559
- writeToken: edgeWriteToken,
560
- call: "live/status/" + tlro
561
- });
562
- case 63:
563
- status.lro_status_url = _context4.sent;
564
- status.insertions = [];
565
- if (edgeMeta.live_recording.playout_config.interleaves != undefined && edgeMeta.live_recording.playout_config.interleaves[sequence] != undefined) {
566
- insertions = edgeMeta.live_recording.playout_config.interleaves[sequence];
567
- for (i = 0; i < insertions.length; i++) {
568
- insertionTimeSinceEpoch = recording_period.start_time_epoch_sec + insertions[i].insertion_time;
569
- status.insertions[i] = {
570
- insertion_time_since_start: insertions[i].insertion_time,
571
- insertion_time: new Date(insertionTimeSinceEpoch * 1000).toISOString(),
572
- insertion_time_local: new Date(insertionTimeSinceEpoch * 1000).toLocaleString(),
573
- target: insertions[i].playout
574
- };
575
- }
576
- }
577
- if (showParams) {
578
- status.recording_params = edgeMeta.live_recording.recording_config.recording_params;
579
- }
580
- state = "stopped";
581
- lroStatus = "";
582
- _context4.prev = 69;
583
- _context4.t1 = this.utils;
584
- _context4.next = 73;
585
- return HttpClient.Fetch(status.lro_status_url);
586
- case 73:
587
- _context4.t2 = _context4.sent;
588
- _context4.next = 76;
589
- return _context4.t1.ResponseToJson.call(_context4.t1, _context4.t2);
590
- case 76:
591
- lroStatus = _context4.sent;
592
- state = lroStatus.state;
593
- status.warnings = lroStatus.custom && lroStatus.custom.warnings;
594
- status.quality = lroStatus.custom && lroStatus.custom.quality;
595
- if (lroStatus.custom && lroStatus.custom.status) {
596
- status.recording_status = lroStatus.custom.status;
597
- }
598
- _context4.next = 89;
599
- break;
600
- case 83:
601
- _context4.prev = 83;
602
- _context4.t3 = _context4["catch"](69);
603
- console.log("LRO Status (failed): ", _context4.t3.response.statusCode);
604
- status.state = "stopped";
605
- status.error = _context4.t3.response;
606
- return _context4.abrupt("return", status);
607
- case 89:
608
- segDurationMeta = edgeMeta.live_recording.recording_config.recording_params.xc_params.seg_duration; // Convert LRO 'state' to desired 'state'
609
- if (state === "running" && videoLastFinalizationTimeEpochSec <= 0) {
610
- state = "starting";
611
- } else if (state === "running" && segDurationMeta !== undefined && sinceLastFinalize > parseInt(segDurationMeta) + 5) {
612
- state = "stalled";
613
- } else if (state == "terminated") {
614
- state = "stopped";
615
- }
616
- status.state = state;
617
- if (!((state === "running" || state === "stalled" || state === "starting") && stopLro)) {
618
- _context4.next = 111;
619
- break;
620
- }
621
- _context4.next = 95;
622
- return this.FabricUrl({
623
- libraryId: libraryId,
624
- objectId: objectId,
625
- writeToken: edgeWriteToken,
626
- call: "live/stop/" + tlro
627
- });
628
- case 95:
629
- lroStopUrl = _context4.sent;
630
- _context4.prev = 96;
631
- _context4.t4 = this.utils;
632
- _context4.next = 100;
633
- return HttpClient.Fetch(lroStopUrl);
634
- case 100:
635
- _context4.t5 = _context4.sent;
636
- _context4.next = 103;
637
- return _context4.t4.ResponseToJson.call(_context4.t4, _context4.t5);
638
- case 103:
639
- console.log("LRO Stop: ", lroStatus.body);
640
- _context4.next = 109;
641
- break;
642
- case 106:
643
- _context4.prev = 106;
644
- _context4.t6 = _context4["catch"](96);
645
- console.log("LRO Stop (failed): ", _context4.t6.response.statusCode);
646
- case 109:
647
- state = "stopped";
648
- status.state = state;
649
- case 111:
650
- if (!(state === "running")) {
651
- _context4.next = 142;
652
- break;
653
- }
654
- playout_urls = {};
655
- _context4.next = 115;
656
- return this.PlayoutOptions({
657
- objectId: objectId,
658
- linkPath: "public/asset_metadata/sources/default"
659
- });
660
- case 115:
661
- playout_options = _context4.sent;
662
- hls_clear_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods.clear !== undefined;
663
- if (!hls_clear_enabled) {
664
- _context4.next = 121;
665
- break;
666
- }
667
- _context4.next = 120;
668
- return this.FabricUrl({
669
- libraryId: libraryId,
670
- objectId: objectId,
671
- rep: "playout/default/hls-clear/playlist.m3u8"
672
- });
673
- case 120:
674
- playout_urls.hls_clear = _context4.sent;
675
- case 121:
676
- hls_aes128_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods["aes-128"] !== undefined;
677
- if (!hls_aes128_enabled) {
678
- _context4.next = 126;
679
- break;
680
- }
681
- _context4.next = 125;
682
- return this.FabricUrl({
683
- libraryId: libraryId,
684
- objectId: objectId,
685
- rep: "playout/default/hls-aes128/playlist.m3u8"
686
- });
687
- case 125:
688
- playout_urls.hls_aes128 = _context4.sent;
689
- case 126:
690
- hls_sample_aes_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods["sample-aes"] !== undefined;
691
- if (!hls_sample_aes_enabled) {
692
- _context4.next = 131;
693
- break;
694
- }
695
- _context4.next = 130;
696
- return this.FabricUrl({
697
- libraryId: libraryId,
698
- objectId: objectId,
699
- rep: "playout/default/hls-sample-aes/playlist.m3u8"
700
- });
701
- case 130:
702
- playout_urls.hls_sample_aes = _context4.sent;
703
- case 131:
704
- _context4.next = 133;
705
- return this.NetworkInfo();
706
- case 133:
707
- networkInfo = _context4.sent;
708
- _context4.next = 136;
709
- return this.authClient.AuthorizationToken({
710
- libraryId: libraryId,
711
- objectId: objectId,
712
- channelAuth: false,
713
- noCache: true,
714
- noAuth: true
715
- });
716
- case 136:
717
- token = _context4.sent;
718
- embed_net = "main";
719
- if (networkInfo.name.includes("demo")) {
720
- embed_net = "demo";
721
- }
722
- embed_url = "https://embed.v3.contentfabric.io/?net=".concat(embed_net, "&p&ct=h&oid=").concat(objectId, "&mt=lv&ath=").concat(token);
723
- playout_urls.embed_url = embed_url;
724
- status.playout_urls = playout_urls;
725
- case 142:
726
- _context4.next = 147;
727
- break;
728
- case 144:
729
- _context4.prev = 144;
730
- _context4.t7 = _context4["catch"](3);
731
- console.error(_context4.t7);
732
- case 147:
733
- return _context4.abrupt("return", status);
734
- case 148:
735
- case "end":
736
- return _context4.stop();
737
- }
738
- }, _callee4, this, [[3, 144], [34, 40], [69, 83], [96, 106]]);
739
- }));
740
- return function (_x4) {
741
- return _ref8.apply(this, arguments);
742
- };
743
- }();
744
-
745
- /**
746
- * Create a new edge write token
747
- *
748
- * @methodGroup Live Stream
749
- * @namedParams
750
- * @param {string} name - Object ID or name of the live stream object
751
- * @param {boolean=} start - If specified, will start the stream after creation
752
- *
753
- * @return {Promise<Object>} - The status response for the object
754
- *
755
- */
756
- exports.StreamCreate = /*#__PURE__*/function () {
757
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
758
- var name, _ref9$start, start, status, objectId, libraryId, liveRecording, fabURI, response, edgeToken, writeToken, objectHash;
759
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
760
- while (1) switch (_context5.prev = _context5.next) {
761
- case 0:
762
- name = _ref9.name, _ref9$start = _ref9.start, start = _ref9$start === void 0 ? false : _ref9$start;
763
- _context5.next = 3;
764
- return this.StreamStatus({
765
- name: name
766
- });
767
- case 3:
768
- status = _context5.sent;
769
- if (!(status.state != "uninitialized" && status.state !== "inactive" && status.state !== "terminated" && status.state !== "stopped")) {
770
- _context5.next = 6;
771
- break;
772
- }
773
- return _context5.abrupt("return", {
774
- state: status.state,
775
- error: "stream still active - must terminate first"
776
- });
777
- case 6:
778
- objectId = status.object_id;
779
- console.log("START: ", name, "start", start);
780
- _context5.next = 10;
781
- return this.ContentObjectLibraryId({
782
- objectId: objectId
783
- });
784
- case 10:
785
- libraryId = _context5.sent;
786
- _context5.next = 13;
787
- return this.ContentObjectMetadata({
788
- libraryId: libraryId,
789
- objectId: objectId,
790
- metadataSubtree: "/live_recording"
791
- });
792
- case 13:
793
- liveRecording = _context5.sent;
794
- fabURI = liveRecording.fabric_config.ingress_node_api; // Support both hostname and URL ingress_node_api
795
- if (!fabURI.startsWith("http")) {
796
- // Assume https
797
- fabURI = "https://" + fabURI;
798
- }
799
- this.SetNodes({
800
- fabricURIs: [fabURI]
801
- });
802
- console.log("Node URI", fabURI, "ID", liveRecording.fabric_config.ingress_node_id);
803
- _context5.next = 20;
804
- return this.EditContentObject({
805
- libraryId: libraryId,
806
- objectId: objectId
807
- });
808
- case 20:
809
- response = _context5.sent;
810
- edgeToken = response.write_token;
811
- console.log("Edge token:", edgeToken);
812
-
813
- /*
814
- * Set the metadata, including the edge token.
815
- */
816
- _context5.next = 25;
817
- return this.EditContentObject({
818
- libraryId: libraryId,
819
- objectId: objectId
820
- });
821
- case 25:
822
- response = _context5.sent;
823
- writeToken = response.write_token;
824
- this.Log("Merging metadata: ", libraryId, objectId, writeToken);
825
- _context5.next = 30;
826
- return this.MergeMetadata({
827
- libraryId: libraryId,
828
- objectId: objectId,
829
- writeToken: writeToken,
830
- metadata: {
831
- live_recording: {
832
- status: {
833
- edge_write_token: edgeToken,
834
- state: "active" // indicates there is an active session (set to 'closed' when done)
835
- },
836
-
837
- fabric_config: {
838
- edge_write_token: edgeToken
839
- }
840
- }
841
- }
842
- });
843
- case 30:
844
- this.Log("Finalizing content draft: ", libraryId, objectId, writeToken);
845
- _context5.next = 33;
846
- return this.FinalizeContentObject({
847
- libraryId: libraryId,
848
- objectId: objectId,
849
- writeToken: writeToken,
850
- commitMessage: "Create stream edge write token " + edgeToken
851
- });
852
- case 33:
853
- response = _context5.sent;
854
- objectHash = response.hash;
855
- this.Log("Finalized object: ", objectHash);
856
- status = {
857
- object_id: objectId,
858
- hash: objectHash,
859
- library_id: libraryId,
860
- stream_id: edgeToken,
861
- edge_write_token: edgeToken,
862
- fabric_api: fabURI,
863
- state: "stopped"
864
- };
865
- if (start) {
866
- status = this.StreamStartOrStopOrReset({
867
- name: name,
868
- op: start
869
- });
870
- }
871
- return _context5.abrupt("return", status);
872
- case 39:
873
- case "end":
874
- return _context5.stop();
875
- }
876
- }, _callee5, this);
877
- }));
878
- return function (_x5) {
879
- return _ref10.apply(this, arguments);
880
- };
881
- }();
882
-
883
- /**
884
- * Start, stop or reset a stream within the current session (current edge write token)
885
- *
886
- * @methodGroup Live Stream
887
- * @namedParams
888
- * @param {string} name - Object ID or name of the live stream object
889
- * @param {string} op - The operation to perform. Possible values:
890
- * 'start'
891
- * 'reset' - Stops current LRO recording and starts a new one. Does
892
- * not create a new edge write token (just creates a new recording
893
- * period in the existing edge write token)
894
- * - 'stop'
895
- *
896
- * @return {Promise<Object>} - The status response for the stream
897
- *
898
- */
899
- exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
900
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
901
- var name, op, status, _tries, tries;
902
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
903
- while (1) switch (_context6.prev = _context6.next) {
904
- case 0:
905
- name = _ref11.name, op = _ref11.op;
906
- _context6.prev = 1;
907
- _context6.next = 4;
908
- return this.StreamStatus({
909
- name: name
910
- });
911
- case 4:
912
- status = _context6.sent;
913
- if (!(status.state != "stopped")) {
914
- _context6.next = 9;
915
- break;
916
- }
917
- if (!(op === "start")) {
918
- _context6.next = 9;
919
- break;
920
- }
921
- status.error = "Unable to start stream - state: " + status.state;
922
- return _context6.abrupt("return", status);
923
- case 9:
924
- if (!(status.state == "running" || status.state == "starting" || status.state == "stalled")) {
925
- _context6.next = 31;
926
- break;
927
- }
928
- _context6.prev = 10;
929
- _context6.next = 13;
930
- return this.CallBitcodeMethod({
931
- libraryId: status.library_id,
932
- objectId: status.object_id,
933
- writeToken: status.edge_write_token,
934
- method: "/live/stop/" + status.tlro,
935
- constant: false
936
- });
937
- case 13:
938
- _context6.next = 17;
939
- break;
940
- case 15:
941
- _context6.prev = 15;
942
- _context6.t0 = _context6["catch"](10);
943
- case 17:
944
- // Wait until LRO is terminated
945
- _tries = 10;
946
- case 18:
947
- if (!(status.state != "stopped" && _tries-- > 0)) {
948
- _context6.next = 27;
949
- break;
950
- }
951
- console.log("Wait to terminate - ", status.state);
952
- _context6.next = 22;
953
- return Sleep(1000);
954
- case 22:
955
- _context6.next = 24;
956
- return this.StreamStatus({
957
- name: name
958
- });
959
- case 24:
960
- status = _context6.sent;
961
- _context6.next = 18;
962
- break;
963
- case 27:
964
- console.log("Status after stop - ", status.state);
965
- if (!(_tries <= 0)) {
966
- _context6.next = 31;
967
- break;
968
- }
969
- console.log("Failed to stop");
970
- return _context6.abrupt("return", status);
971
- case 31:
972
- if (!(op === "stop")) {
973
- _context6.next = 33;
974
- break;
975
- }
976
- return _context6.abrupt("return", status);
977
- case 33:
978
- console.log("STARTING", "edge_write_token", status.edge_write_token);
979
- _context6.prev = 34;
980
- _context6.next = 37;
981
- return this.CallBitcodeMethod({
982
- libraryId: status.library_id,
983
- objectId: status.object_id,
984
- writeToken: status.edge_write_token,
985
- method: "/live/start",
986
- constant: false
987
- });
988
- case 37:
989
- _context6.next = 43;
990
- break;
991
- case 39:
992
- _context6.prev = 39;
993
- _context6.t1 = _context6["catch"](34);
994
- console.log("LRO Start (failed): ", _context6.t1);
995
- return _context6.abrupt("return", {
996
- state: status.state,
997
- error: "LRO start failed - must create a stream first"
998
- });
999
- case 43:
1000
- // Wait until LRO is 'starting'
1001
- tries = 10;
1002
- case 44:
1003
- if (!(status.state != "starting" && tries-- > 0)) {
1004
- _context6.next = 53;
1005
- break;
1006
- }
1007
- console.log("Wait to start - ", status.state);
1008
- _context6.next = 48;
1009
- return Sleep(1000);
1010
- case 48:
1011
- _context6.next = 50;
1012
- return this.StreamStatus({
1013
- name: name
1014
- });
1015
- case 50:
1016
- status = _context6.sent;
1017
- _context6.next = 44;
1018
- break;
1019
- case 53:
1020
- console.log("Status after restart - ", status.state);
1021
- return _context6.abrupt("return", status);
1022
- case 57:
1023
- _context6.prev = 57;
1024
- _context6.t2 = _context6["catch"](1);
1025
- console.error(_context6.t2);
1026
- case 60:
1027
- case "end":
1028
- return _context6.stop();
1029
- }
1030
- }, _callee6, this, [[1, 57], [10, 15], [34, 39]]);
1031
- }));
1032
- return function (_x6) {
1033
- return _ref12.apply(this, arguments);
1034
- };
1035
- }();
1036
-
1037
- /**
1038
- * Close the edge write token and make the stream object inactive.
1039
- *
1040
- * @methodGroup Live Stream
1041
- * @namedParams
1042
- * @param {string} name - Object ID or name of the live stream object
1043
- *
1044
- * @return {Promise<Object>} - The finalize response for the stream object
1045
- */
1046
- exports.StreamStopSession = /*#__PURE__*/function () {
1047
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref13) {
1048
- var name, objectId, libraryId, mainMeta, fabURI, metaEdgeWriteToken, streamMetadata, status, _yield$this$EditConte, writeToken, newState, stopTime, finalizeMetadata, fin;
1049
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
1050
- while (1) switch (_context7.prev = _context7.next) {
1051
- case 0:
1052
- name = _ref13.name;
1053
- _context7.prev = 1;
1054
- this.Log("Terminating stream session for: ".concat(name));
1055
- objectId = name;
1056
- _context7.next = 6;
1057
- return this.ContentObjectLibraryId({
1058
- objectId: objectId
1059
- });
1060
- case 6:
1061
- libraryId = _context7.sent;
1062
- _context7.next = 9;
1063
- return this.ContentObjectMetadata({
1064
- libraryId: libraryId,
1065
- objectId: objectId
1066
- });
1067
- case 9:
1068
- mainMeta = _context7.sent;
1069
- fabURI = mainMeta.live_recording.fabric_config.ingress_node_api; // Support both hostname and URL ingress_node_api
1070
- if (!fabURI.startsWith("http")) {
1071
- // Assume https
1072
- fabURI = "https://" + fabURI;
1073
- }
1074
- this.SetNodes({
1075
- fabricURIs: [fabURI]
1076
- });
1077
- metaEdgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
1078
- if (metaEdgeWriteToken) {
1079
- _context7.next = 16;
1080
- break;
1081
- }
1082
- return _context7.abrupt("return", {
1083
- state: "inactive",
1084
- error: "The stream is not active"
1085
- });
1086
- case 16:
1087
- _context7.prev = 16;
1088
- _context7.next = 19;
1089
- return this.ContentObjectMetadata({
1090
- libraryId: libraryId,
1091
- objectId: objectId,
1092
- writeToken: metaEdgeWriteToken
1093
- });
1094
- case 19:
1095
- streamMetadata = _context7.sent;
1096
- _context7.next = 22;
1097
- return this.StreamStatus({
1098
- name: name
1099
- });
1100
- case 22:
1101
- status = _context7.sent;
1102
- if (!(status.state !== "stopped")) {
1103
- _context7.next = 25;
1104
- break;
1105
- }
1106
- return _context7.abrupt("return", {
1107
- state: status.state,
1108
- error: "The stream must be stopped before terminating"
1109
- });
1110
- case 25:
1111
- _context7.next = 27;
1112
- return this.DeleteWriteToken({
1113
- libraryId: libraryId,
1114
- writeToken: metaEdgeWriteToken
1115
- });
1116
- case 27:
1117
- _context7.next = 32;
1118
- break;
1119
- case 29:
1120
- _context7.prev = 29;
1121
- _context7.t0 = _context7["catch"](16);
1122
- this.Log("Unable to retrieve metadata for edge write token");
1123
- case 32:
1124
- _context7.next = 34;
1125
- return this.EditContentObject({
1126
- libraryId: libraryId,
1127
- objectId: objectId
1128
- });
1129
- case 34:
1130
- _yield$this$EditConte = _context7.sent;
1131
- writeToken = _yield$this$EditConte.writeToken;
1132
- // Set stop time and inactive state
1133
- newState = "inactive";
1134
- stopTime = Math.floor(new Date().getTime() / 1000);
1135
- finalizeMetadata = {
1136
- live_recording: {
1137
- status: {
1138
- edge_write_token: "",
1139
- state: newState,
1140
- recording_stop_time: stopTime
1141
- },
1142
- fabric_config: {
1143
- edge_write_token: ""
1144
- }
1145
- }
1146
- };
1147
- _context7.next = 41;
1148
- return this.MergeMetadata({
1149
- libraryId: libraryId,
1150
- objectId: objectId,
1151
- writeToken: writeToken,
1152
- metadata: finalizeMetadata
1153
- });
1154
- case 41:
1155
- _context7.next = 43;
1156
- return this.FinalizeContentObject({
1157
- libraryId: libraryId,
1158
- objectId: objectId,
1159
- writeToken: writeToken,
1160
- commitMessage: "Deactivate live stream - stop time ".concat(stopTime)
1161
- });
1162
- case 43:
1163
- fin = _context7.sent;
1164
- return _context7.abrupt("return", {
1165
- fin: fin,
1166
- name: name,
1167
- state: newState
1168
- });
1169
- case 47:
1170
- _context7.prev = 47;
1171
- _context7.t1 = _context7["catch"](1);
1172
- console.error(_context7.t1);
1173
- case 50:
1174
- case "end":
1175
- return _context7.stop();
1176
- }
1177
- }, _callee7, this, [[1, 47], [16, 29]]);
1178
- }));
1179
- return function (_x7) {
1180
- return _ref14.apply(this, arguments);
1181
- };
1182
- }();
1183
-
1184
- /**
1185
- * Initialize the stream object
1186
- *
1187
- * @methodGroup Live Stream
1188
- * @namedParams
1189
- * @param {string} name - Object ID or name of the live stream object
1190
- * @param {boolean=} drm - If specified, playout will be DRM protected
1191
- * @param {string=} format - Specify the list of playout formats and DRM to support,
1192
- comma-separated (hls-clear, hls-aes128, hls-sample-aes,
1193
- hls-fairplay)
1194
- *
1195
- * @return {Promise<Object>} - The name, object ID, and state of the stream
1196
- */
1197
- exports.StreamInitialize = /*#__PURE__*/function () {
1198
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref15) {
1199
- var name, _ref15$drm, drm, format, typeAbrMaster, typeLiveStream, tenantContractId, _yield$this$ContentOb, live_stream, title, res;
1200
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
1201
- while (1) switch (_context8.prev = _context8.next) {
1202
- case 0:
1203
- name = _ref15.name, _ref15$drm = _ref15.drm, drm = _ref15$drm === void 0 ? false : _ref15$drm, format = _ref15.format;
1204
- _context8.next = 3;
1205
- return this.userProfileClient.TenantContractId();
1206
- case 3:
1207
- tenantContractId = _context8.sent;
1208
- _context8.next = 6;
1209
- return this.ContentObjectMetadata({
1210
- libraryId: tenantContractId.replace("iten", "ilib"),
1211
- objectId: tenantContractId.replace("iten", "iq__"),
1212
- metadataSubtree: "public/content_types",
1213
- select: ["live_stream", "title"]
1214
- });
1215
- case 6:
1216
- _yield$this$ContentOb = _context8.sent;
1217
- live_stream = _yield$this$ContentOb.live_stream;
1218
- title = _yield$this$ContentOb.title;
1219
- if (live_stream) {
1220
- typeLiveStream = live_stream;
1221
- }
1222
- if (title) {
1223
- typeAbrMaster = title;
1224
- }
1225
- if (!(typeAbrMaster === undefined || typeLiveStream === undefined)) {
1226
- _context8.next = 14;
1227
- break;
1228
- }
1229
- console.log("ERROR - unable to find content types", "ABR Master", typeAbrMaster, "Live Stream", typeLiveStream);
1230
- return _context8.abrupt("return", {});
1231
- case 14:
1232
- _context8.next = 16;
1233
- return this.StreamSetOfferingAndDRM({
1234
- name: name,
1235
- typeAbrMaster: typeAbrMaster,
1236
- typeLiveStream: typeLiveStream,
1237
- drm: drm,
1238
- format: format
1239
- });
1240
- case 16:
1241
- res = _context8.sent;
1242
- return _context8.abrupt("return", res);
1243
- case 18:
1244
- case "end":
1245
- return _context8.stop();
1246
- }
1247
- }, _callee8, this);
1248
- }));
1249
- return function (_x8) {
1250
- return _ref16.apply(this, arguments);
1251
- };
1252
- }();
1253
-
1254
- /**
1255
- * Create a dummy VoD offering and initialize DRM keys.
1256
- *
1257
- * @methodGroup Live Stream
1258
- * @namedParams
1259
- * @param {string} name - Object ID or name of the live stream object
1260
- * @param {string=} typeAbrMaster - Content type hash
1261
- * @param {string=} typeLiveStream - Content type hash
1262
- * @param {boolean=} drm - If specified, DRM will be applied to the stream
1263
- * @param {string=} format - A list of playout formats and DRM to support, comma-separated
1264
- * (hls-clear, hls-aes128, hls-sample-aes, hls-fairplay). If specified,
1265
- * this will take precedence over the drm value
1266
- *
1267
- * @return {Promise<Object>} - The name, object ID, and state of the stream
1268
- */
1269
- exports.StreamSetOfferingAndDRM = /*#__PURE__*/function () {
1270
- var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref17) {
1271
- var name, typeAbrMaster, typeLiveStream, _ref17$drm, drm, format, status, objectId, aBitRate, aChannels, aSampleRate, aStreamIndex, aTimeBase, aChannelLayout, vBitRate, vHeight, vStreamIndex, vWidth, vDisplayAspectRatio, vFrameRate, vTimeBase, abrProfileDefault, playoutFormats, abrProfile, formats, i, libraryId, mainMeta, fabURI, streamUrl;
1272
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
1273
- while (1) switch (_context9.prev = _context9.next) {
1274
- case 0:
1275
- name = _ref17.name, typeAbrMaster = _ref17.typeAbrMaster, typeLiveStream = _ref17.typeLiveStream, _ref17$drm = _ref17.drm, drm = _ref17$drm === void 0 ? false : _ref17$drm, format = _ref17.format;
1276
- _context9.next = 3;
1277
- return this.StreamStatus({
1278
- name: name
1279
- });
1280
- case 3:
1281
- status = _context9.sent;
1282
- if (!(status.state != "uninitialized" && status.state != "inactive" && status.state != "stopped")) {
1283
- _context9.next = 6;
1284
- break;
1285
- }
1286
- return _context9.abrupt("return", {
1287
- state: status.state,
1288
- error: "stream still active - must terminate first"
1289
- });
1290
- case 6:
1291
- objectId = status.object_id;
1292
- console.log("INIT: ", name, objectId);
1293
- aBitRate = 128000;
1294
- aChannels = 2;
1295
- aSampleRate = 48000;
1296
- aStreamIndex = 1;
1297
- aTimeBase = "1/48000";
1298
- aChannelLayout = "stereo";
1299
- vBitRate = 14000000;
1300
- vHeight = 720;
1301
- vStreamIndex = 0;
1302
- vWidth = 1280;
1303
- vDisplayAspectRatio = "16/9";
1304
- vFrameRate = "30000/1001";
1305
- vTimeBase = "1/30000"; // "1/16000";
1306
- abrProfileDefault = require("../abr_profiles/abr_profile_live_drm.js");
1307
- abrProfile = JSON.parse(JSON.stringify(abrProfileDefault));
1308
- if (!format) {
1309
- _context9.next = 43;
1310
- break;
1311
- }
1312
- drm = true; // Override DRM parameter
1313
- playoutFormats = {};
1314
- formats = format.split(",");
1315
- i = 0;
1316
- case 28:
1317
- if (!(i < formats.length)) {
1318
- _context9.next = 41;
1319
- break;
1320
- }
1321
- if (!(formats[i] === "hls-clear")) {
1322
- _context9.next = 33;
1323
- break;
1324
- }
1325
- abrProfile.drm_optional = true;
1326
- playoutFormats["hls-clear"] = {
1327
- "drm": null,
1328
- "protocol": {
1329
- "type": "ProtoHls"
1330
- }
1331
- };
1332
- return _context9.abrupt("continue", 38);
1333
- case 33:
1334
- if (!(formats[i] === "dash-clear")) {
1335
- _context9.next = 37;
1336
- break;
1337
- }
1338
- abrProfile.drm_optional = true;
1339
- playoutFormats["dash-clear"] = {
1340
- "drm": null,
1341
- "protocol": {
1342
- "min_buffer_length": 2,
1343
- "type": "ProtoDash"
1344
- }
1345
- };
1346
- return _context9.abrupt("continue", 38);
1347
- case 37:
1348
- playoutFormats[formats[i]] = abrProfile.playout_formats[formats[i]];
1349
- case 38:
1350
- i++;
1351
- _context9.next = 28;
1352
- break;
1353
- case 41:
1354
- _context9.next = 44;
1355
- break;
1356
- case 43:
1357
- if (!drm) {
1358
- abrProfile.drm_optional = true;
1359
- playoutFormats = {
1360
- "hls-clear": {
1361
- "drm": null,
1362
- "protocol": {
1363
- "type": "ProtoHls"
1364
- }
1365
- },
1366
- "dash-clear": {
1367
- "drm": null,
1368
- "protocol": {
1369
- "min_buffer_length": 2,
1370
- "type": "ProtoDash"
1371
- }
1372
- }
1373
- };
1374
- } else {
1375
- playoutFormats = Object.assign({}, abrProfile.playout_formats);
1376
- }
1377
- case 44:
1378
- abrProfile.playout_formats = playoutFormats;
1379
- _context9.next = 47;
1380
- return this.ContentObjectLibraryId({
1381
- objectId: objectId
1382
- });
1383
- case 47:
1384
- libraryId = _context9.sent;
1385
- _context9.prev = 48;
1386
- _context9.next = 51;
1387
- return this.ContentObjectMetadata({
1388
- libraryId: libraryId,
1389
- objectId: objectId
1390
- });
1391
- case 51:
1392
- mainMeta = _context9.sent;
1393
- fabURI = mainMeta.live_recording.fabric_config.ingress_node_api; // Support both hostname and URL ingress_node_api
1394
- if (!fabURI.startsWith("http")) {
1395
- // Assume https
1396
- fabURI = "https://" + fabURI;
1397
- }
1398
- this.SetNodes({
1399
- fabricURIs: [fabURI]
1400
- });
1401
- streamUrl = mainMeta.live_recording.recording_config.recording_params.origin_url;
1402
- _context9.next = 58;
1403
- return StreamGenerateOffering({
1404
- client: this,
1405
- libraryId: libraryId,
1406
- objectId: objectId,
1407
- typeAbrMaster: typeAbrMaster,
1408
- typeLiveStream: typeLiveStream,
1409
- streamUrl: streamUrl,
1410
- abrProfile: abrProfile,
1411
- aBitRate: aBitRate,
1412
- aChannels: aChannels,
1413
- aSampleRate: aSampleRate,
1414
- aStreamIndex: aStreamIndex,
1415
- aTimeBase: aTimeBase,
1416
- aChannelLayout: aChannelLayout,
1417
- vBitRate: vBitRate,
1418
- vHeight: vHeight,
1419
- vStreamIndex: vStreamIndex,
1420
- vWidth: vWidth,
1421
- vDisplayAspectRatio: vDisplayAspectRatio,
1422
- vFrameRate: vFrameRate,
1423
- vTimeBase: vTimeBase
1424
- });
1425
- case 58:
1426
- console.log("Finished generating offering");
1427
- return _context9.abrupt("return", {
1428
- name: name,
1429
- object_id: objectId,
1430
- state: "initialized"
1431
- });
1432
- case 62:
1433
- _context9.prev = 62;
1434
- _context9.t0 = _context9["catch"](48);
1435
- console.error(_context9.t0);
1436
- case 65:
1437
- case "end":
1438
- return _context9.stop();
1439
- }
1440
- }, _callee9, this, [[48, 62]]);
1441
- }));
1442
- return function (_x9) {
1443
- return _ref18.apply(this, arguments);
1444
- };
1445
- }();
1446
-
1447
- /**
1448
- * Add a content insertion entry
1449
- *
1450
- * @methodGroup Live Stream
1451
- * @namedParams
1452
- * @param {string} name - Object ID or name of the live stream object
1453
- * @param {number} insertionTime - Time in seconds (float)
1454
- * @param {boolean=} sinceStart - If specified, time specified will be elapsed seconds
1455
- * since stream start, otherwise, time will be elapsed since epoch
1456
- * @param {number=} duration - Time in seconds (float). Default: 20.0
1457
- * @param {string} targetHash - The target content object hash (playable)
1458
- * @param {boolean=} remove - If specified, will remove the inseration at the exact 'time' (instead of adding)
1459
- *
1460
- * @return {Promise<Object>} - Insertions, as well as any errors from bad insertions
1461
- */
1462
- exports.StreamInsertion = /*#__PURE__*/function () {
1463
- var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref19) {
1464
- var name, insertionTime, _ref19$sinceStart, sinceStart, duration, targetHash, _ref19$remove, remove, offeringMeta, insertionInfo, audioAbrDuration, videoAbrDuration, objectId, libraryId, mainMeta, fabURI, edgeWriteToken, edgeMeta, recordings, sequence, streamStartTime, period, playoutConfig, insertions, res, errs, currentTime, insertionDone, newInsertion, i;
1465
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
1466
- while (1) switch (_context10.prev = _context10.next) {
1467
- case 0:
1468
- name = _ref19.name, insertionTime = _ref19.insertionTime, _ref19$sinceStart = _ref19.sinceStart, sinceStart = _ref19$sinceStart === void 0 ? false : _ref19$sinceStart, duration = _ref19.duration, targetHash = _ref19.targetHash, _ref19$remove = _ref19.remove, remove = _ref19$remove === void 0 ? false : _ref19$remove;
1469
- _context10.next = 3;
1470
- return this.ContentObjectMetadata({
1471
- versionHash: targetHash,
1472
- metadataSubtree: "/offerings/default"
1473
- });
1474
- case 3:
1475
- offeringMeta = _context10.sent;
1476
- insertionInfo = {
1477
- duration_sec: 0 // Minimum of video and audio duration
1478
- };
1479
-
1480
- ["video", "audio"].forEach(function (mt) {
1481
- var stream = offeringMeta.media_struct.streams[mt];
1482
- insertionInfo[mt] = {
1483
- seg_duration_sec: stream.optimum_seg_dur["float"],
1484
- duration_sec: stream.duration["float"],
1485
- frame_rate_rat: stream.rate
1486
- };
1487
- if (insertionInfo.duration_sec === 0 || stream.duration["float"] < insertionInfo.duration_sec) {
1488
- insertionInfo.duration_sec = stream.duration["float"];
1489
- }
1490
- });
1491
- audioAbrDuration = insertionInfo.audio.seg_duration_sec;
1492
- videoAbrDuration = insertionInfo.video.seg_duration_sec;
1493
- if (!(audioAbrDuration === 0 || videoAbrDuration === 0)) {
1494
- _context10.next = 10;
1495
- break;
1496
- }
1497
- throw new Error("Bad segment duration hash:", targetHash);
1498
- case 10:
1499
- if (!(duration === undefined)) {
1500
- _context10.next = 14;
1501
- break;
1502
- }
1503
- duration = insertionInfo.duration_sec; // Use full duration of the insertion
1504
- _context10.next = 16;
1505
- break;
1506
- case 14:
1507
- if (!(duration > insertionInfo.duration_sec)) {
1508
- _context10.next = 16;
1509
- break;
1510
- }
1511
- throw new Error("Bad duration - larger than insertion object duration", insertionInfo.duration_sec);
1512
- case 16:
1513
- objectId = name;
1514
- _context10.next = 19;
1515
- return this.ContentObjectLibraryId({
1516
- objectId: objectId
1517
- });
1518
- case 19:
1519
- libraryId = _context10.sent;
1520
- _context10.next = 22;
1521
- return this.ContentObjectMetadata({
1522
- libraryId: libraryId,
1523
- objectId: objectId
1524
- });
1525
- case 22:
1526
- mainMeta = _context10.sent;
1527
- fabURI = mainMeta.live_recording.fabric_config.ingress_node_api; // Support both hostname and URL ingress_node_api
1528
- if (!fabURI.startsWith("http")) {
1529
- // Assume https
1530
- fabURI = "https://" + fabURI;
1531
- }
1532
- this.SetNodes({
1533
- fabricURIs: [fabURI]
1534
- });
1535
- edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
1536
- _context10.next = 29;
1537
- return this.ContentObjectMetadata({
1538
- libraryId: libraryId,
1539
- objectId: objectId,
1540
- writeToken: edgeWriteToken
1541
- });
1542
- case 29:
1543
- edgeMeta = _context10.sent;
1544
- // Find stream start time (from the most recent recording section)
1545
- recordings = edgeMeta.live_recording.recordings;
1546
- sequence = 1;
1547
- streamStartTime = 0;
1548
- if (recordings != undefined && recordings.recording_sequence != undefined) {
1549
- // We have at least one recording - check if still active
1550
- sequence = recordings.recording_sequence;
1551
- period = recordings.live_offering[sequence - 1];
1552
- if (period.end_time_epoch_sec > 0) {
1553
- // The last period is closed - apply insertions to the next period
1554
- sequence++;
1555
- } else {
1556
- // The period is active
1557
- streamStartTime = period.start_time_epoch_sec;
1558
- }
1559
- }
1560
- if (!(streamStartTime === 0)) {
1561
- _context10.next = 37;
1562
- break;
1563
- }
1564
- if (!(sinceStart === false)) {
1565
- _context10.next = 37;
1566
- break;
1567
- }
1568
- throw new Error("Stream not running - must use 'time since start'");
1569
- case 37:
1570
- // Find the current period playout configuration
1571
- if (edgeMeta.live_recording.playout_config.interleaves === undefined) {
1572
- edgeMeta.live_recording.playout_config.interleaves = {};
1573
- }
1574
- if (edgeMeta.live_recording.playout_config.interleaves[sequence] === undefined) {
1575
- edgeMeta.live_recording.playout_config.interleaves[sequence] = [];
1576
- }
1577
- playoutConfig = edgeMeta.live_recording.playout_config;
1578
- insertions = playoutConfig.interleaves[sequence];
1579
- res = {};
1580
- if (!sinceStart) {
1581
- insertionTime = insertionTime - streamStartTime;
1582
- }
1583
-
1584
- // Assume insertions are sorted by insertion time
1585
- errs = [];
1586
- currentTime = -1;
1587
- insertionDone = false;
1588
- newInsertion = {
1589
- insertion_time: insertionTime,
1590
- duration: duration,
1591
- audio_abr_duration: audioAbrDuration,
1592
- video_abr_duration: videoAbrDuration,
1593
- playout: "/qfab/" + targetHash + "/rep/playout" // TO FIX - should be a link
1594
- };
1595
- i = 0;
1596
- case 48:
1597
- if (!(i < insertions.length)) {
1598
- _context10.next = 63;
1599
- break;
1600
- }
1601
- if (insertions[i].insertion_time <= currentTime) {
1602
- // Bad insertion - must be later than current time
1603
- append(errs, "Bad insertion - time:", insertions[i].insertion_time);
1604
- }
1605
- if (!remove) {
1606
- _context10.next = 56;
1607
- break;
1608
- }
1609
- if (!(insertions[i].insertion_time === insertionTime)) {
1610
- _context10.next = 54;
1611
- break;
1612
- }
1613
- insertions.splice(i, 1);
1614
- return _context10.abrupt("break", 63);
1615
- case 54:
1616
- _context10.next = 60;
1617
- break;
1618
- case 56:
1619
- if (!(insertions[i].insertion_time > insertionTime)) {
1620
- _context10.next = 60;
1621
- break;
1622
- }
1623
- if (i > 0) {
1624
- insertions = [].concat(_toConsumableArray(insertions.splice(0, i)), [newInsertion], _toConsumableArray(insertions.splice(i)));
1625
- } else {
1626
- insertions = [newInsertion].concat(_toConsumableArray(insertions.splice(i)));
1627
- }
1628
- insertionDone = true;
1629
- return _context10.abrupt("break", 63);
1630
- case 60:
1631
- i++;
1632
- _context10.next = 48;
1633
- break;
1634
- case 63:
1635
- if (!remove && !insertionDone) {
1636
- // Add to the end of the insertions list
1637
- console.log("Add insertion at the end");
1638
- insertions = [].concat(_toConsumableArray(insertions), [newInsertion]);
1639
- }
1640
- playoutConfig.interleaves[sequence] = insertions;
1641
-
1642
- // Store the new insertions in the write token
1643
- _context10.next = 67;
1644
- return this.ReplaceMetadata({
1645
- libraryId: libraryId,
1646
- objectId: objectId,
1647
- writeToken: edgeWriteToken,
1648
- metadataSubtree: "/live_recording/playout_config",
1649
- metadata: edgeMeta.live_recording.playout_config
1650
- });
1651
- case 67:
1652
- res.errors = errs;
1653
- res.insertions = insertions;
1654
- return _context10.abrupt("return", res);
1655
- case 70:
1656
- case "end":
1657
- return _context10.stop();
1658
- }
1659
- }, _callee10, this);
1660
- }));
1661
- return function (_x10) {
1662
- return _ref20.apply(this, arguments);
1663
- };
1664
- }();
1665
-
1666
- /**
1667
- * Configure the stream based on built-in logic and optional custom settings.
1668
- *
1669
- * Custom settings format:
1670
- * {
1671
- * "audio" {
1672
- * "1" : { // This is the stream index
1673
- * "tags" : "language: english",
1674
- * "codec" : "aac",
1675
- * "bitrate": 204000,
1676
- * "record": true,
1677
- * "recording_bitrate" : 192000,
1678
- * "recording_channels" : 2,
1679
- * "playout": bool
1680
- * "playout_label": "English (Stereo)"
1681
- * },
1682
- * "3": {
1683
- * ...
1684
- * }
1685
- * }
1686
- * }
1687
- *
1688
- * @methodGroup Live Stream
1689
- * @namedParams
1690
- * @param {string} name - Object ID or name of the live stream object
1691
- * @param {Object=} customSettings - Additional options to customize configuration settings
1692
- * @param {Object=} probeMetadata - Metadata for the probe. If not specified, a new probe will be configured
1693
- * @return {Promise<Object>} - The status response for the stream
1694
- *
1695
- */
1696
- exports.StreamConfig = /*#__PURE__*/function () {
1697
- var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref21) {
1698
- var name, _ref21$customSettings, customSettings, probeMetadata, objectId, status, libraryId, probe, mainMeta, userConfig, parsedName, hostName, streamUrl, nodes, node, endpoint, probeUrl, lc, liveRecordingConfig, e, writeToken;
1699
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
1700
- while (1) switch (_context11.prev = _context11.next) {
1701
- case 0:
1702
- name = _ref21.name, _ref21$customSettings = _ref21.customSettings, customSettings = _ref21$customSettings === void 0 ? {} : _ref21$customSettings, probeMetadata = _ref21.probeMetadata;
1703
- objectId = name;
1704
- status = {
1705
- name: name
1706
- };
1707
- _context11.next = 5;
1708
- return this.ContentObjectLibraryId({
1709
- objectId: objectId
1710
- });
1711
- case 5:
1712
- libraryId = _context11.sent;
1713
- status.library_id = libraryId;
1714
- status.object_id = objectId;
1715
- probe = probeMetadata;
1716
- _context11.next = 11;
1717
- return this.ContentObjectMetadata({
1718
- libraryId: libraryId,
1719
- objectId: objectId
1720
- });
1721
- case 11:
1722
- mainMeta = _context11.sent;
1723
- userConfig = mainMeta.live_recording_config;
1724
- status.user_config = userConfig;
1725
-
1726
- // Get node URI from user config
1727
- parsedName = userConfig.url.replace("udp://", "https://").replace("rtmp://", "https://").replace("srt://", "https://");
1728
- hostName = new URL(parsedName).hostname;
1729
- streamUrl = new URL(userConfig.url);
1730
- this.Log("Retrieving nodes - matching: ".concat(hostName));
1731
- _context11.next = 20;
1732
- return this.SpaceNodes({
1733
- matchEndpoint: hostName
1734
- });
1735
- case 20:
1736
- nodes = _context11.sent;
1737
- if (!(nodes.length < 1)) {
1738
- _context11.next = 24;
1739
- break;
1740
- }
1741
- status.error = "No node matching stream URL " + streamUrl.href;
1742
- return _context11.abrupt("return", status);
1743
- case 24:
1744
- node = {
1745
- endpoints: nodes[0].services.fabric_api.urls,
1746
- id: nodes[0].id
1747
- };
1748
- status.node = node;
1749
- endpoint = node.endpoints[0];
1750
- if (probe) {
1751
- _context11.next = 53;
1752
- break;
1753
- }
1754
- this.SetNodes({
1755
- fabricURIs: [endpoint]
1756
- });
1757
-
1758
- // Probe the stream
1759
- probe = {};
1760
- _context11.prev = 30;
1761
- _context11.next = 33;
1762
- return this.Rep({
1763
- libraryId: libraryId,
1764
- objectId: objectId,
1765
- rep: "probe"
1766
- });
1767
- case 33:
1768
- probeUrl = _context11.sent;
1769
- _context11.t0 = this.utils;
1770
- _context11.next = 37;
1771
- return HttpClient.Fetch(probeUrl, {
1772
- body: JSON.stringify({
1773
- "filename": streamUrl.href,
1774
- "listen": true
1775
- }),
1776
- method: "POST"
1777
- });
1778
- case 37:
1779
- _context11.t1 = _context11.sent;
1780
- _context11.next = 40;
1781
- return _context11.t0.ResponseToJson.call(_context11.t0, _context11.t1);
1782
- case 40:
1783
- probe = _context11.sent;
1784
- if (!probe.errors) {
1785
- _context11.next = 43;
1786
- break;
1787
- }
1788
- throw probe.errors[0];
1789
- case 43:
1790
- _context11.next = 52;
1791
- break;
1792
- case 45:
1793
- _context11.prev = 45;
1794
- _context11.t2 = _context11["catch"](30);
1795
- if (!(_context11.t2.code === "ETIMEDOUT")) {
1796
- _context11.next = 51;
1797
- break;
1798
- }
1799
- throw "Stream probe time out - make sure the stream source is available";
1800
- case 51:
1801
- throw _context11.t2;
1802
- case 52:
1803
- probe.format.filename = streamUrl.href;
1804
- case 53:
1805
- // Create live recording config
1806
- lc = new LiveConf(probe, node.id, endpoint, false, false, true);
1807
- liveRecordingConfig = lc.generateLiveConf({
1808
- customSettings: customSettings
1809
- }); // Store live recording config into the stream object
1810
- _context11.next = 57;
1811
- return this.EditContentObject({
1812
- libraryId: libraryId,
1813
- objectId: objectId
1814
- });
1815
- case 57:
1816
- e = _context11.sent;
1817
- writeToken = e.write_token;
1818
- _context11.next = 61;
1819
- return this.ReplaceMetadata({
1820
- libraryId: libraryId,
1821
- objectId: objectId,
1822
- writeToken: writeToken,
1823
- metadataSubtree: "live_recording",
1824
- metadata: liveRecordingConfig.live_recording
1825
- });
1826
- case 61:
1827
- _context11.next = 63;
1828
- return this.ReplaceMetadata({
1829
- libraryId: libraryId,
1830
- objectId: objectId,
1831
- writeToken: writeToken,
1832
- metadataSubtree: "live_recording_config/probe_info",
1833
- metadata: probe
1834
- });
1835
- case 63:
1836
- _context11.next = 65;
1837
- return this.FinalizeContentObject({
1838
- libraryId: libraryId,
1839
- objectId: objectId,
1840
- writeToken: writeToken,
1841
- commitMessage: "Apply live stream configuration"
1842
- });
1843
- case 65:
1844
- status.fin = _context11.sent;
1845
- return _context11.abrupt("return", status);
1846
- case 67:
1847
- case "end":
1848
- return _context11.stop();
1849
- }
1850
- }, _callee11, this, [[30, 45]]);
1851
- }));
1852
- return function (_x11) {
1853
- return _ref22.apply(this, arguments);
1854
- };
1855
- }();
1856
-
1857
- /**
1858
- * List the pre-allocated URLs for a site
1859
- *
1860
- * @methodGroup Live Stream
1861
- * @namedParams
1862
- * @param {string=} siteId - ID of the live stream site object
1863
- *
1864
- * @return {Promise<Object>} - The list of stream URLs
1865
- */
1866
- exports.StreamListUrls = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
1867
- var _this2 = this;
1868
- var _ref24,
1869
- siteId,
1870
- STATUS_MAP,
1871
- tenantContractId,
1872
- streamMetadata,
1873
- activeUrlMap,
1874
- streamUrlStatus,
1875
- streamUrls,
1876
- _args13 = arguments;
1877
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1878
- while (1) switch (_context13.prev = _context13.next) {
1879
- case 0:
1880
- _ref24 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, siteId = _ref24.siteId;
1881
- _context13.prev = 1;
1882
- STATUS_MAP = {
1883
- UNCONFIGURED: "unconfigured",
1884
- UNINITIALIZED: "uninitialized",
1885
- INACTIVE: "inactive",
1886
- STOPPED: "stopped",
1887
- STARTING: "starting",
1888
- RUNNING: "running",
1889
- STALLED: "stalled"
1890
- };
1891
- if (siteId) {
1892
- _context13.next = 12;
1893
- break;
1894
- }
1895
- _context13.next = 6;
1896
- return this.userProfileClient.TenantContractId();
1897
- case 6:
1898
- tenantContractId = _context13.sent;
1899
- if (tenantContractId) {
1900
- _context13.next = 9;
1901
- break;
1902
- }
1903
- throw Error("No tenant contract ID configured");
1904
- case 9:
1905
- _context13.next = 11;
1906
- return this.ContentObjectMetadata({
1907
- libraryId: tenantContractId.replace("iten", "ilib"),
1908
- objectId: tenantContractId.replace("iten", "iq__"),
1909
- metadataSubtree: "public/sites/live_streams"
1910
- });
1911
- case 11:
1912
- siteId = _context13.sent;
1913
- case 12:
1914
- _context13.t0 = this;
1915
- _context13.next = 15;
1916
- return this.ContentObjectLibraryId({
1917
- objectId: siteId
1918
- });
1919
- case 15:
1920
- _context13.t1 = _context13.sent;
1921
- _context13.t2 = siteId;
1922
- _context13.t3 = {
1923
- libraryId: _context13.t1,
1924
- objectId: _context13.t2,
1925
- metadataSubtree: "public/asset_metadata/live_streams",
1926
- resolveLinks: true,
1927
- resolveIgnoreErrors: true,
1928
- resolveIncludeSource: true
1929
- };
1930
- _context13.next = 20;
1931
- return _context13.t0.ContentObjectMetadata.call(_context13.t0, _context13.t3);
1932
- case 20:
1933
- streamMetadata = _context13.sent;
1934
- activeUrlMap = {};
1935
- _context13.next = 24;
1936
- return this.utils.LimitedMap(10, Object.keys(streamMetadata || {}), /*#__PURE__*/function () {
1937
- var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(slug) {
1938
- var stream, versionHash, objectId, libraryId, status, streamMeta, url, isActive;
1939
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1940
- while (1) switch (_context12.prev = _context12.next) {
1941
- case 0:
1942
- stream = streamMetadata[slug];
1943
- if (stream && stream["."] && stream["."].source) {
1944
- versionHash = stream["."].source;
1945
- }
1946
- if (!versionHash) {
1947
- _context12.next = 16;
1948
- break;
1949
- }
1950
- objectId = _this2.utils.DecodeVersionHash(versionHash).objectId;
1951
- _context12.next = 6;
1952
- return _this2.ContentObjectLibraryId({
1953
- objectId: objectId
1954
- });
1955
- case 6:
1956
- libraryId = _context12.sent;
1957
- _context12.next = 9;
1958
- return _this2.StreamStatus({
1959
- name: objectId
1960
- });
1961
- case 9:
1962
- status = _context12.sent;
1963
- _context12.next = 12;
1964
- return _this2.ContentObjectMetadata({
1965
- objectId: objectId,
1966
- libraryId: libraryId,
1967
- select: ["live_recording_config/reference_url",
1968
- // live_recording_config/url is the old path
1969
- "live_recording_config/url"]
1970
- });
1971
- case 12:
1972
- streamMeta = _context12.sent;
1973
- url = streamMeta.live_recording_config.reference_url || streamMeta.live_recording_config.url;
1974
- isActive = [STATUS_MAP.STARTING, STATUS_MAP.RUNNING, STATUS_MAP.STALLED, STATUS_MAP.STOPPED].includes(status.state);
1975
- if (url && isActive) {
1976
- activeUrlMap[url] = true;
1977
- }
1978
- case 16:
1979
- case "end":
1980
- return _context12.stop();
1981
- }
1982
- }, _callee12);
1983
- }));
1984
- return function (_x12) {
1985
- return _ref25.apply(this, arguments);
1986
- };
1987
- }());
1988
- case 24:
1989
- streamUrlStatus = {};
1990
- _context13.t4 = this;
1991
- _context13.next = 28;
1992
- return this.ContentObjectLibraryId({
1993
- objectId: siteId
1994
- });
1995
- case 28:
1996
- _context13.t5 = _context13.sent;
1997
- _context13.t6 = siteId;
1998
- _context13.t7 = {
1999
- libraryId: _context13.t5,
2000
- objectId: _context13.t6,
2001
- metadataSubtree: "/live_stream_urls",
2002
- resolveLinks: true,
2003
- resolveIgnoreErrors: true
2004
- };
2005
- _context13.next = 33;
2006
- return _context13.t4.ContentObjectMetadata.call(_context13.t4, _context13.t7);
2007
- case 33:
2008
- streamUrls = _context13.sent;
2009
- if (streamUrls) {
2010
- _context13.next = 36;
2011
- break;
2012
- }
2013
- throw Error("No pre-allocated URLs configured");
2014
- case 36:
2015
- Object.keys(streamUrls || {}).forEach(function (protocol) {
2016
- streamUrlStatus[protocol] = streamUrls[protocol].map(function (url) {
2017
- return {
2018
- url: url,
2019
- active: activeUrlMap[url] || false
2020
- };
2021
- });
2022
- });
2023
- return _context13.abrupt("return", streamUrlStatus);
2024
- case 40:
2025
- _context13.prev = 40;
2026
- _context13.t8 = _context13["catch"](1);
2027
- console.error(_context13.t8);
2028
- case 43:
2029
- case "end":
2030
- return _context13.stop();
2031
- }
2032
- }, _callee13, this, [[1, 40]]);
2033
- }));
2034
-
2035
- /**
2036
- * Copy a portion of a live stream recording into a standard VoD object using the zero-copy content fabric API
2037
- *
2038
- * Limitations:
2039
- * - currently requires the target object to be pre-created and have content encryption keys (CAPS)
2040
- * - for audio and video to be sync'd, the live stream needs to have the beginning of the desired recording period
2041
- * - for an event stream, make sure the TTL is long enough to allow running the live-to-vod command before the beginning of the recording expires
2042
- * - for 24/7 streams, make sure to reset the stream before the desired recording (as to create a new recording period) and have the TTL long enough
2043
- * to allow running the live-to-vod command before the beginning of the recording expires.
2044
- * - startTime and endTime are not currently implemented by this method
2045
- *
2046
- *
2047
- * @methodGroup Live Stream
2048
- * @namedParams
2049
- * @param {string} name - Object ID or name of the live stream
2050
- * @param {string} targetObjectId - Object ID of the target VOD object
2051
- * @param {string=} eventId -
2052
- * @param {boolean=} finalize - If enabled, target object will be finalized after copy to vod operations
2053
- * @param {number=} recordingPeriod - Determines which recording period to copy, which are 0-based. -1 copies the current (or last) period
2054
- *
2055
- * @return {Promise<Object>} - The status response for the stream
2056
- */
2057
-
2058
- /*
2059
- Example fabric API flow:
2060
-
2061
- https://host-76-74-34-194.contentfabric.io/qlibs/ilib24CtWSJeVt9DiAzym8jB6THE9e7H/q/$QWT/call/media/live_to_vod/init -d @r1 -H "Authorization: Bearer $TOK"
2062
-
2063
- {
2064
- "live_qhash": "hq__5Zk1jSN8vNLUAXjQwMJV8F8J8ESXNvmVKkhaXySmGc1BXnJPG2FvvaXee4CXqvFHuGuU3fqLJc",
2065
- "start_time": "",
2066
- "end_time": "",
2067
- "recording_period": -1,
2068
- "streams": ["video", "audio"],
2069
- "variant_key": "default"
2070
- }
2071
-
2072
- https://host-76-74-34-194.contentfabric.io/qlibs/ilib24CtWSJeVt9DiAzym8jB6THE9e7H/q/$QWT/call/media/abr_mezzanine/init -H "Authorization: Bearer $TOK" -d @r2
2073
-
2074
- {
2075
-
2076
- "abr_profile": { ... },
2077
- "offering_key": "default",
2078
- "prod_master_hash": "tqw__HSQHBt7vYxWfCMPH5yXwKTfhdPcQ4Lcs9WUMUbTtnMbTZPTLo4BfJWPMGpoy1Dpv1wWQVtUtAtAr429TnVs",
2079
- "variant_key": "default",
2080
- "keep_other_streams": false
2081
- }
2082
-
2083
- https://host-76-74-34-194.contentfabric.io/qlibs/ilib24CtWSJeVt9DiAzym8jB6THE9e7H/q/$QWT/call/media/live_to_vod/copy -d '{"variant_key":"","offering_key":""}' -H "Authorization: Bearer $TOK"
2084
-
2085
-
2086
- https://host-76-74-34-194.contentfabric.io/qlibs/ilib24CtWSJeVt9DiAzym8jB6THE9e7H/q/$QWT/call/media/abr_mezzanine/offerings/default/finalize -d '{}' -H "Authorization: Bearer $TOK"
2087
-
2088
- */
2089
-
2090
- exports.StreamCopyToVod = /*#__PURE__*/function () {
2091
- var _ref27 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref26) {
2092
- var name, targetObjectId, eventId, _ref26$streams, streams, _ref26$finalize, finalize, _ref26$recordingPerio, recordingPeriod, _ref26$startTime, startTime, _ref26$endTime, endTime, objectId, abrProfile, status, libraryId, targetLibraryId, kmsAddress, kmsCapId, kmsCap, liveHash, event, _yield$this$EditConte2, writeToken, abrMezInitBody, finalizeResponse;
2093
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
2094
- while (1) switch (_context14.prev = _context14.next) {
2095
- case 0:
2096
- name = _ref26.name, targetObjectId = _ref26.targetObjectId, eventId = _ref26.eventId, _ref26$streams = _ref26.streams, streams = _ref26$streams === void 0 ? null : _ref26$streams, _ref26$finalize = _ref26.finalize, finalize = _ref26$finalize === void 0 ? true : _ref26$finalize, _ref26$recordingPerio = _ref26.recordingPeriod, recordingPeriod = _ref26$recordingPerio === void 0 ? -1 : _ref26$recordingPerio, _ref26$startTime = _ref26.startTime, startTime = _ref26$startTime === void 0 ? "" : _ref26$startTime, _ref26$endTime = _ref26.endTime, endTime = _ref26$endTime === void 0 ? "" : _ref26$endTime;
2097
- objectId = name;
2098
- abrProfile = require("../abr_profiles/abr_profile_live_to_vod.js");
2099
- _context14.next = 5;
2100
- return this.StreamStatus({
2101
- name: name
2102
- });
2103
- case 5:
2104
- status = _context14.sent;
2105
- libraryId = status.library_id;
2106
- this.Log("Copying stream ".concat(name, " to target ").concat(targetObjectId));
2107
- ValidateObject(targetObjectId);
2108
- _context14.next = 11;
2109
- return this.ContentObjectLibraryId({
2110
- objectId: targetObjectId
2111
- });
2112
- case 11:
2113
- targetLibraryId = _context14.sent;
2114
- _context14.next = 14;
2115
- return this.authClient.KMSAddress({
2116
- objectId: targetObjectId
2117
- });
2118
- case 14:
2119
- kmsAddress = _context14.sent;
2120
- kmsCapId = "eluv.caps.ikms".concat(this.utils.AddressToHash(kmsAddress));
2121
- _context14.next = 18;
2122
- return this.ContentObjectMetadata({
2123
- libraryId: targetLibraryId,
2124
- objectId: targetObjectId,
2125
- metadataSubtree: kmsCapId
2126
- });
2127
- case 18:
2128
- kmsCap = _context14.sent;
2129
- if (kmsCap) {
2130
- _context14.next = 21;
2131
- break;
2132
- }
2133
- throw Error("No content encryption key set for object ".concat(targetObjectId));
2134
- case 21:
2135
- _context14.prev = 21;
2136
- status.live_object_id = objectId;
2137
- _context14.next = 25;
2138
- return this.LatestVersionHash({
2139
- objectId: objectId,
2140
- libraryId: libraryId
2141
- });
2142
- case 25:
2143
- liveHash = _context14.sent;
2144
- status.live_hash = liveHash;
2145
- if (!eventId) {
2146
- _context14.next = 32;
2147
- break;
2148
- }
2149
- _context14.next = 30;
2150
- return this.CueInfo({
2151
- eventId: eventId,
2152
- status: status
2153
- });
2154
- case 30:
2155
- event = _context14.sent;
2156
- if (event.eventStart && event.eventEnd) {
2157
- startTime = event.eventStart;
2158
- endTime = event.eventEnd;
2159
- }
2160
- case 32:
2161
- _context14.next = 34;
2162
- return this.EditContentObject({
2163
- objectId: targetObjectId,
2164
- libraryId: targetLibraryId
2165
- });
2166
- case 34:
2167
- _yield$this$EditConte2 = _context14.sent;
2168
- writeToken = _yield$this$EditConte2.writeToken;
2169
- status.target_object_id = targetObjectId;
2170
- status.target_library_id = targetLibraryId;
2171
- status.target_write_token = writeToken;
2172
- this.Log("Process live source (takes around 20 sec per hour of content)");
2173
- _context14.next = 42;
2174
- return this.CallBitcodeMethod({
2175
- libraryId: targetLibraryId,
2176
- objectId: targetObjectId,
2177
- writeToken: writeToken,
2178
- method: "/media/live_to_vod/init",
2179
- body: {
2180
- "live_qhash": liveHash,
2181
- "start_time": startTime,
2182
- // eg. "2023-10-03T02:09:02.00Z",
2183
- "end_time": endTime,
2184
- // eg. "2023-10-03T02:15:00.00Z",
2185
- "streams": streams,
2186
- "recording_period": recordingPeriod,
2187
- "variant_key": "default"
2188
- },
2189
- constant: false,
2190
- format: "text"
2191
- });
2192
- case 42:
2193
- abrMezInitBody = {
2194
- abr_profile: abrProfile,
2195
- "offering_key": "default",
2196
- "prod_master_hash": writeToken,
2197
- "variant_key": "default",
2198
- "keep_other_streams": false
2199
- };
2200
- _context14.next = 45;
2201
- return this.CallBitcodeMethod({
2202
- libraryId: targetLibraryId,
2203
- objectId: targetObjectId,
2204
- writeToken: writeToken,
2205
- method: "/media/abr_mezzanine/init",
2206
- body: abrMezInitBody,
2207
- constant: false,
2208
- format: "text"
2209
- });
2210
- case 45:
2211
- _context14.prev = 45;
2212
- _context14.next = 48;
2213
- return this.CallBitcodeMethod({
2214
- libraryId: targetLibraryId,
2215
- objectId: targetObjectId,
2216
- writeToken: writeToken,
2217
- method: "/media/live_to_vod/copy",
2218
- body: {},
2219
- constant: false,
2220
- format: "text"
2221
- });
2222
- case 48:
2223
- _context14.next = 54;
2224
- break;
2225
- case 50:
2226
- _context14.prev = 50;
2227
- _context14.t0 = _context14["catch"](45);
2228
- console.error("Unable to call /media/live_to_vod/copy", _context14.t0);
2229
- throw _context14.t0;
2230
- case 54:
2231
- _context14.next = 56;
2232
- return this.CallBitcodeMethod({
2233
- libraryId: targetLibraryId,
2234
- objectId: targetObjectId,
2235
- writeToken: writeToken,
2236
- method: "/media/abr_mezzanine/offerings/default/finalize",
2237
- body: abrMezInitBody,
2238
- constant: false,
2239
- format: "text"
2240
- });
2241
- case 56:
2242
- if (!finalize) {
2243
- _context14.next = 61;
2244
- break;
2245
- }
2246
- _context14.next = 59;
2247
- return this.FinalizeContentObject({
2248
- libraryId: targetLibraryId,
2249
- objectId: targetObjectId,
2250
- writeToken: writeToken,
2251
- commitMessage: "Live Stream to VoD"
2252
- });
2253
- case 59:
2254
- finalizeResponse = _context14.sent;
2255
- status.target_hash = finalizeResponse.hash;
2256
- case 61:
2257
- // Clean up unnecessary status items
2258
- delete status.playout_urls;
2259
- delete status.lro_status_url;
2260
- delete status.recording_period;
2261
- delete status.recording_period_sequence;
2262
- delete status.edge_meta_size;
2263
- delete status.insertions;
2264
- return _context14.abrupt("return", status);
2265
- case 70:
2266
- _context14.prev = 70;
2267
- _context14.t1 = _context14["catch"](21);
2268
- this.Log(_context14.t1, true);
2269
- throw _context14.t1;
2270
- case 74:
2271
- case "end":
2272
- return _context14.stop();
2273
- }
2274
- }, _callee14, this, [[21, 70], [45, 50]]);
2275
- }));
2276
- return function (_x13) {
2277
- return _ref27.apply(this, arguments);
2278
- };
2279
- }();
2280
-
2281
- /**
2282
- * Remove a watermark for a live stream
2283
- *
2284
- * @methodGroup Live Stream
2285
- * @namedParams
2286
- * @param {string=} libraryId - Library ID of the live stream
2287
- * @param {string} objectId - Object ID of the live stream
2288
- * @param {string=} writeToken - Write token of the draft
2289
- * @param {Array<string>} types - Specify which type of watermark to remove. Possible values:
2290
- * - "image"
2291
- * - "text"
2292
- * - "forensic"
2293
- * @param {boolean=} finalize - If enabled, target object will be finalized after removing watermark
2294
- *
2295
- * @return {Promise<Object>} - The finalize response
2296
- */
2297
- exports.StreamRemoveWatermark = /*#__PURE__*/function () {
2298
- var _ref29 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref28) {
2299
- var libraryId, objectId, writeToken, types, _ref28$finalize, finalize, _yield$this$EditConte3, edgeWriteToken, metadataPath, objectMetadata, finalizeResponse;
2300
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
2301
- while (1) switch (_context15.prev = _context15.next) {
2302
- case 0:
2303
- libraryId = _ref28.libraryId, objectId = _ref28.objectId, writeToken = _ref28.writeToken, types = _ref28.types, _ref28$finalize = _ref28.finalize, finalize = _ref28$finalize === void 0 ? true : _ref28$finalize;
2304
- ValidateObject(objectId);
2305
- if (libraryId) {
2306
- _context15.next = 6;
2307
- break;
2308
- }
2309
- _context15.next = 5;
2310
- return this.ContentObjectLibraryId({
2311
- objectId: objectId
2312
- });
2313
- case 5:
2314
- libraryId = _context15.sent;
2315
- case 6:
2316
- if (writeToken) {
2317
- _context15.next = 11;
2318
- break;
2319
- }
2320
- _context15.next = 9;
2321
- return this.EditContentObject({
2322
- objectId: objectId,
2323
- libraryId: libraryId
2324
- });
2325
- case 9:
2326
- _yield$this$EditConte3 = _context15.sent;
2327
- writeToken = _yield$this$EditConte3.writeToken;
2328
- case 11:
2329
- this.Log("Removing watermark types: ".concat(types.join(", "), " ").concat(libraryId, " ").concat(objectId));
2330
- _context15.next = 14;
2331
- return this.ContentObjectMetadata({
2332
- objectId: objectId,
2333
- libraryId: libraryId,
2334
- metadataSubtree: "/live_recording/fabric_config/edge_write_token"
2335
- });
2336
- case 14:
2337
- edgeWriteToken = _context15.sent;
2338
- metadataPath = "live_recording/playout_config";
2339
- _context15.next = 18;
2340
- return this.ContentObjectMetadata({
2341
- libraryId: libraryId,
2342
- objectId: objectId,
2343
- writeToken: writeToken,
2344
- metadataSubtree: metadataPath,
2345
- resolveLinks: false
2346
- });
2347
- case 18:
2348
- objectMetadata = _context15.sent;
2349
- if (objectMetadata) {
2350
- _context15.next = 21;
2351
- break;
2352
- }
2353
- throw Error("Stream object must be configured before removing a watermark");
2354
- case 21:
2355
- types.forEach(function (type) {
2356
- if (type === "text") {
2357
- delete objectMetadata.simple_watermark;
2358
- } else if (type === "image") {
2359
- delete objectMetadata.image_watermark;
2360
- } else if (type === "forensic") {
2361
- delete objectMetadata.forensic_watermark;
2362
- }
2363
- });
2364
- _context15.next = 24;
2365
- return this.ReplaceMetadata({
2366
- libraryId: libraryId,
2367
- objectId: objectId,
2368
- writeToken: writeToken,
2369
- metadataSubtree: metadataPath,
2370
- metadata: objectMetadata
2371
- });
2372
- case 24:
2373
- if (!edgeWriteToken) {
2374
- _context15.next = 27;
2375
- break;
2376
- }
2377
- _context15.next = 27;
2378
- return this.ReplaceMetadata({
2379
- libraryId: libraryId,
2380
- objectId: objectId,
2381
- writeToken: edgeWriteToken,
2382
- metadataSubtree: metadataPath,
2383
- metadata: objectMetadata
2384
- });
2385
- case 27:
2386
- if (!finalize) {
2387
- _context15.next = 32;
2388
- break;
2389
- }
2390
- _context15.next = 30;
2391
- return this.FinalizeContentObject({
2392
- libraryId: libraryId,
2393
- objectId: objectId,
2394
- writeToken: writeToken,
2395
- commitMessage: "Watermark removed"
2396
- });
2397
- case 30:
2398
- finalizeResponse = _context15.sent;
2399
- return _context15.abrupt("return", finalizeResponse);
2400
- case 32:
2401
- case "end":
2402
- return _context15.stop();
2403
- }
2404
- }, _callee15, this);
2405
- }));
2406
- return function (_x14) {
2407
- return _ref29.apply(this, arguments);
2408
- };
2409
- }();
2410
-
2411
- /**
2412
- * Create a watermark for a live stream
2413
- *
2414
- * @methodGroup Live Stream
2415
- * @namedParams
2416
- * @param {string=} libraryId - Library ID of the live stream
2417
- * @param {string} objectId - Object ID of the live stream
2418
- * @param {string=} writeToken - Write token of the draft
2419
- * @param {Object} simpleWatermark - Text watermark
2420
- * @param {Object} imageWatermark - Image watermark
2421
- * @param {Object} forensicWatermark - Forensic watermark
2422
- * @param {boolean=} finalize - If enabled, target object will be finalized after adding watermark
2423
- * Watermark examples:
2424
- *
2425
- * Simple Watermark:
2426
- {
2427
- "font_color": "",
2428
- "font_relative_height": 0,
2429
- "shadow": false,
2430
- "template": "",
2431
- "timecode": "",
2432
- "timecode_rate": 0,
2433
- "x": "",
2434
- "y": ""
2435
- }
2436
- *
2437
- * Image watermark:
2438
- {
2439
- "image": "",
2440
- "align_h": "",
2441
- "align_v": "",
2442
- "target_video_height": 0,
2443
- "wm_enabled": false
2444
- }
2445
- *
2446
- * Forensic watermark:
2447
- {
2448
- "algo": 6,
2449
- "forensic_duration": 0,
2450
- "forensic_start": "",
2451
- "image_a": <path_to_image>,
2452
- "image_b": <path_to_image>,
2453
- "is_stub": true,
2454
- "payload_bit_nb": 23,
2455
- "wm_enabled": true
2456
- }
2457
- *
2458
- *
2459
- * @return {Promise<Object>} - The finalize response
2460
- */
2461
- exports.StreamAddWatermark = /*#__PURE__*/function () {
2462
- var _ref31 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref30) {
2463
- var libraryId, objectId, writeToken, simpleWatermark, imageWatermark, forensicWatermark, _ref30$finalize, finalize, _yield$this$EditConte4, edgeWriteToken, watermarkType, metadataPath, objectMetadata, watermarkArgCount, response, finalizeResponse;
2464
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
2465
- while (1) switch (_context16.prev = _context16.next) {
2466
- case 0:
2467
- libraryId = _ref30.libraryId, objectId = _ref30.objectId, writeToken = _ref30.writeToken, simpleWatermark = _ref30.simpleWatermark, imageWatermark = _ref30.imageWatermark, forensicWatermark = _ref30.forensicWatermark, _ref30$finalize = _ref30.finalize, finalize = _ref30$finalize === void 0 ? true : _ref30$finalize;
2468
- ValidateObject(objectId);
2469
- if (libraryId) {
2470
- _context16.next = 6;
2471
- break;
2472
- }
2473
- _context16.next = 5;
2474
- return this.ContentObjectLibraryId({
2475
- objectId: objectId
2476
- });
2477
- case 5:
2478
- libraryId = _context16.sent;
2479
- case 6:
2480
- if (writeToken) {
2481
- _context16.next = 11;
2482
- break;
2483
- }
2484
- _context16.next = 9;
2485
- return this.EditContentObject({
2486
- objectId: objectId,
2487
- libraryId: libraryId
2488
- });
2489
- case 9:
2490
- _yield$this$EditConte4 = _context16.sent;
2491
- writeToken = _yield$this$EditConte4.writeToken;
2492
- case 11:
2493
- _context16.next = 13;
2494
- return this.ContentObjectMetadata({
2495
- objectId: objectId,
2496
- libraryId: libraryId,
2497
- metadataSubtree: "/live_recording/fabric_config/edge_write_token"
2498
- });
2499
- case 13:
2500
- edgeWriteToken = _context16.sent;
2501
- watermarkType = imageWatermark ? "image" : forensicWatermark ? "forensic" : "text";
2502
- metadataPath = "live_recording/playout_config";
2503
- this.Log("Adding watermarking type: ".concat(watermarkType, " ").concat(libraryId, " ").concat(objectId));
2504
- _context16.next = 19;
2505
- return this.ContentObjectMetadata({
2506
- libraryId: libraryId,
2507
- objectId: objectId,
2508
- writeToken: writeToken,
2509
- metadataSubtree: metadataPath,
2510
- resolveLinks: false
2511
- });
2512
- case 19:
2513
- objectMetadata = _context16.sent;
2514
- if (objectMetadata) {
2515
- _context16.next = 22;
2516
- break;
2517
- }
2518
- throw Error("Stream object must be configured before adding a watermark");
2519
- case 22:
2520
- watermarkArgCount = [simpleWatermark, imageWatermark, forensicWatermark].filter(function (i) {
2521
- return !!i;
2522
- }).length;
2523
- console.log("watermark arg count", watermarkArgCount);
2524
- if (!(watermarkArgCount === 0)) {
2525
- _context16.next = 28;
2526
- break;
2527
- }
2528
- throw Error("No watermark was provided");
2529
- case 28:
2530
- if (!(watermarkArgCount > 1)) {
2531
- _context16.next = 30;
2532
- break;
2533
- }
2534
- throw Error("Only one watermark is allowed");
2535
- case 30:
2536
- if (simpleWatermark) {
2537
- objectMetadata.simple_watermark = simpleWatermark;
2538
- } else if (imageWatermark) {
2539
- objectMetadata.image_watermark = imageWatermark;
2540
- } else if (forensicWatermark) {
2541
- objectMetadata.forensic_watermark = forensicWatermark;
2542
- }
2543
- _context16.next = 33;
2544
- return this.ReplaceMetadata({
2545
- libraryId: libraryId,
2546
- objectId: objectId,
2547
- writeToken: writeToken,
2548
- metadataSubtree: metadataPath,
2549
- metadata: objectMetadata
2550
- });
2551
- case 33:
2552
- if (!edgeWriteToken) {
2553
- _context16.next = 36;
2554
- break;
2555
- }
2556
- _context16.next = 36;
2557
- return this.ReplaceMetadata({
2558
- libraryId: libraryId,
2559
- objectId: objectId,
2560
- writeToken: edgeWriteToken,
2561
- metadataSubtree: metadataPath,
2562
- metadata: objectMetadata
2563
- });
2564
- case 36:
2565
- response = {
2566
- "imageWatermark": objectMetadata.image_watermark,
2567
- "textWatermark": objectMetadata.simple_watermark,
2568
- "forensicWatermark": objectMetadata.forensic_watermark
2569
- };
2570
- if (!finalize) {
2571
- _context16.next = 42;
2572
- break;
2573
- }
2574
- _context16.next = 40;
2575
- return this.FinalizeContentObject({
2576
- libraryId: libraryId,
2577
- objectId: objectId,
2578
- writeToken: writeToken,
2579
- commitMessage: "Watermark set"
2580
- });
2581
- case 40:
2582
- finalizeResponse = _context16.sent;
2583
- response.hash = finalizeResponse.hash;
2584
- case 42:
2585
- return _context16.abrupt("return", response);
2586
- case 43:
2587
- case "end":
2588
- return _context16.stop();
2589
- }
2590
- }, _callee16, this);
2591
- }));
2592
- return function (_x15) {
2593
- return _ref31.apply(this, arguments);
2594
- };
2595
- }();
2596
-
2597
- /**
2598
- * Audit the specified live stream against several content fabric nodes
2599
- *
2600
- * @methodGroup Live Stream
2601
- * @namedParams
2602
- * @param {string=} objectId - Object ID of the live stream
2603
- * @param {string=} versionHash - Version hash of the live stream -- if not specified, latest version is returned
2604
- * @param {string=} salt - base64-encoded byte sequence for salting the audit hash
2605
- * @param {Array<number>=} samples - list of percentages (0.0 - <1.0) used for sampling the content part list, up to 3
2606
- * @param {string=} authorizationToken - Additional authorization token for this request
2607
- *
2608
- * @returns {Promise<Object>} - Response describing audit results
2609
- */
2610
- exports.AuditStream = /*#__PURE__*/function () {
2611
- var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref32) {
2612
- var objectId, versionHash, salt, samples, authorizationToken;
2613
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
2614
- while (1) switch (_context17.prev = _context17.next) {
2615
- case 0:
2616
- objectId = _ref32.objectId, versionHash = _ref32.versionHash, salt = _ref32.salt, samples = _ref32.samples, authorizationToken = _ref32.authorizationToken;
2617
- _context17.next = 3;
2618
- return ContentObjectAudit.AuditContentObject({
2619
- client: this,
2620
- objectId: objectId,
2621
- versionHash: versionHash,
2622
- salt: salt,
2623
- samples: samples,
2624
- live: true,
2625
- authorizationToken: authorizationToken
2626
- });
2627
- case 3:
2628
- return _context17.abrupt("return", _context17.sent);
2629
- case 4:
2630
- case "end":
2631
- return _context17.stop();
2632
- }
2633
- }, _callee17, this);
2634
- }));
2635
- return function (_x16) {
2636
- return _ref33.apply(this, arguments);
2637
- };
2638
- }();