@eluvio/elv-client-js 4.0.87 → 4.0.88

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