@eluvio/elv-client-js 4.0.82 → 4.0.83

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