@eluvio/elv-client-js 4.0.82 → 4.0.84

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