@eluvio/elv-client-js 4.0.77 → 4.0.79

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.
@@ -341,7 +341,7 @@ var StreamGenerateOffering = /*#__PURE__*/function () {
341
341
  */
342
342
  exports.StreamStatus = /*#__PURE__*/function () {
343
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;
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
345
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
346
346
  while (1) switch (_context3.prev = _context3.next) {
347
347
  case 0:
@@ -372,29 +372,30 @@ exports.StreamStatus = /*#__PURE__*/function () {
372
372
  });
373
373
  case 13:
374
374
  mainMeta = _context3.sent;
375
+ status.reference_url = mainMeta.live_recording_config.reference_url;
375
376
  if (!(mainMeta.live_recording_config == undefined || mainMeta.live_recording_config.url == undefined)) {
376
- _context3.next = 17;
377
+ _context3.next = 18;
377
378
  break;
378
379
  }
379
380
  status.state = "unconfigured";
380
381
  return _context3.abrupt("return", status);
381
- case 17:
382
+ case 18:
382
383
  if (!(mainMeta.live_recording == undefined || mainMeta.live_recording.fabric_config == undefined || mainMeta.live_recording.playout_config == undefined || mainMeta.live_recording.recording_config == undefined)) {
383
- _context3.next = 20;
384
+ _context3.next = 21;
384
385
  break;
385
386
  }
386
387
  status.state = "uninitialized";
387
388
  return _context3.abrupt("return", status);
388
- case 20:
389
+ case 21:
389
390
  fabURI = mainMeta.live_recording.fabric_config.ingress_node_api;
390
391
  if (!(fabURI === undefined)) {
391
- _context3.next = 25;
392
+ _context3.next = 26;
392
393
  break;
393
394
  }
394
395
  console.log("bad fabric config - missing ingress node API");
395
396
  status.state = "uninitialized";
396
397
  return _context3.abrupt("return", status);
397
- case 25:
398
+ case 26:
398
399
  // Support both hostname and URL ingress_node_api
399
400
  if (!fabURI.startsWith("http")) {
400
401
  // Assume https
@@ -402,39 +403,39 @@ exports.StreamStatus = /*#__PURE__*/function () {
402
403
  }
403
404
  status.fabric_api = fabURI;
404
405
  status.url = mainMeta.live_recording.recording_config.recording_params.origin_url;
405
- edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
406
- if (!(edgeWriteToken == undefined)) {
407
- _context3.next = 32;
406
+ _edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
407
+ if (_edgeWriteToken) {
408
+ _context3.next = 33;
408
409
  break;
409
410
  }
410
411
  status.state = "inactive";
411
412
  return _context3.abrupt("return", status);
412
- case 32:
413
+ case 33:
413
414
  this.RecordWriteToken({
414
- writeToken: edgeWriteToken,
415
+ writeToken: _edgeWriteToken,
415
416
  fabricNodeUrl: fabURI
416
417
  });
417
- status.edge_write_token = edgeWriteToken;
418
- status.stream_id = edgeWriteToken; // By convention the stream ID is its write token
419
- _context3.next = 37;
418
+ status.edge_write_token = _edgeWriteToken;
419
+ status.stream_id = _edgeWriteToken; // By convention the stream ID is its write token
420
+ _context3.next = 38;
420
421
  return this.ContentObjectMetadata({
421
422
  libraryId: libraryId,
422
423
  objectId: conf.objectId,
423
- writeToken: edgeWriteToken,
424
+ writeToken: _edgeWriteToken,
424
425
  select: ["live_recording"]
425
426
  });
426
- case 37:
427
+ case 38:
427
428
  edgeMeta = _context3.sent;
428
429
  status.edge_meta_size = JSON.stringify(edgeMeta).length;
429
430
 
430
431
  // If a stream has never been started return state 'inactive'
431
432
  if (!(edgeMeta.live_recording === undefined || edgeMeta.live_recording.recordings === undefined || edgeMeta.live_recording.recordings.recording_sequence === undefined)) {
432
- _context3.next = 42;
433
+ _context3.next = 43;
433
434
  break;
434
435
  }
435
436
  status.state = "stopped";
436
437
  return _context3.abrupt("return", status);
437
- case 42:
438
+ case 43:
438
439
  recordings = edgeMeta.live_recording.recordings;
439
440
  status.recording_period_sequence = recordings.recording_sequence;
440
441
  sequence = recordings.recording_sequence;
@@ -453,14 +454,14 @@ exports.StreamStatus = /*#__PURE__*/function () {
453
454
  video_since_last_finalize_sec: sinceLastFinalize
454
455
  };
455
456
  status.recording_period = recording_period;
456
- _context3.next = 53;
457
+ _context3.next = 54;
457
458
  return this.FabricUrl({
458
459
  libraryId: libraryId,
459
460
  objectId: conf.objectId,
460
- writeToken: edgeWriteToken,
461
+ writeToken: _edgeWriteToken,
461
462
  call: "live/status/" + tlro
462
463
  });
463
- case 53:
464
+ case 54:
464
465
  status.lro_status_url = _context3.sent;
465
466
  status.insertions = [];
466
467
  if (edgeMeta.live_recording.playout_config.interleaves != undefined && edgeMeta.live_recording.playout_config.interleaves[sequence] != undefined) {
@@ -480,27 +481,27 @@ exports.StreamStatus = /*#__PURE__*/function () {
480
481
  }
481
482
  state = "stopped";
482
483
  lroStatus = "";
483
- _context3.prev = 59;
484
+ _context3.prev = 60;
484
485
  _context3.t0 = this.utils;
485
- _context3.next = 63;
486
+ _context3.next = 64;
486
487
  return HttpClient.Fetch(status.lro_status_url);
487
- case 63:
488
+ case 64:
488
489
  _context3.t1 = _context3.sent;
489
- _context3.next = 66;
490
+ _context3.next = 67;
490
491
  return _context3.t0.ResponseToJson.call(_context3.t0, _context3.t1);
491
- case 66:
492
+ case 67:
492
493
  lroStatus = _context3.sent;
493
494
  state = lroStatus.state;
494
- _context3.next = 76;
495
+ _context3.next = 77;
495
496
  break;
496
- case 70:
497
- _context3.prev = 70;
498
- _context3.t2 = _context3["catch"](59);
497
+ case 71:
498
+ _context3.prev = 71;
499
+ _context3.t2 = _context3["catch"](60);
499
500
  console.log("LRO Status (failed): ", _context3.t2.response.statusCode);
500
501
  status.state = "stopped";
501
502
  status.error = _context3.t2.response;
502
503
  return _context3.abrupt("return", status);
503
- case 76:
504
+ case 77:
504
505
  // Convert LRO 'state' to desired 'state'
505
506
  if (state === "running" && period.video_finalized_parts_info.last_finalization_time === 0) {
506
507
  state = "starting";
@@ -511,98 +512,98 @@ exports.StreamStatus = /*#__PURE__*/function () {
511
512
  }
512
513
  status.state = state;
513
514
  if (!((state === "running" || state === "stalled" || state === "starting") && stopLro)) {
514
- _context3.next = 97;
515
+ _context3.next = 98;
515
516
  break;
516
517
  }
517
- _context3.next = 81;
518
+ _context3.next = 82;
518
519
  return this.FabricUrl({
519
520
  libraryId: libraryId,
520
521
  objectId: conf.objectId,
521
- writeToken: edgeWriteToken,
522
+ writeToken: _edgeWriteToken,
522
523
  call: "live/stop/" + tlro
523
524
  });
524
- case 81:
525
+ case 82:
525
526
  lroStopUrl = _context3.sent;
526
- _context3.prev = 82;
527
+ _context3.prev = 83;
527
528
  _context3.t3 = this.utils;
528
- _context3.next = 86;
529
+ _context3.next = 87;
529
530
  return HttpClient.Fetch(lroStopUrl);
530
- case 86:
531
+ case 87:
531
532
  _context3.t4 = _context3.sent;
532
- _context3.next = 89;
533
+ _context3.next = 90;
533
534
  return _context3.t3.ResponseToJson.call(_context3.t3, _context3.t4);
534
- case 89:
535
+ case 90:
535
536
  console.log("LRO Stop: ", lroStatus.body);
536
- _context3.next = 95;
537
+ _context3.next = 96;
537
538
  break;
538
- case 92:
539
- _context3.prev = 92;
540
- _context3.t5 = _context3["catch"](82);
539
+ case 93:
540
+ _context3.prev = 93;
541
+ _context3.t5 = _context3["catch"](83);
541
542
  console.log("LRO Stop (failed): ", _context3.t5.response.statusCode);
542
- case 95:
543
+ case 96:
543
544
  state = "stopped";
544
545
  status.state = state;
545
- case 97:
546
+ case 98:
546
547
  if (!(state === "running")) {
547
- _context3.next = 129;
548
+ _context3.next = 130;
548
549
  break;
549
550
  }
550
551
  playout_urls = {};
551
552
  objectId = conf.objectId;
552
- _context3.next = 102;
553
+ _context3.next = 103;
553
554
  return this.PlayoutOptions({
554
555
  objectId: objectId,
555
556
  linkPath: "public/asset_metadata/sources/default"
556
557
  });
557
- case 102:
558
+ case 103:
558
559
  playout_options = _context3.sent;
559
560
  hls_clear_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods.clear !== undefined;
560
561
  if (!hls_clear_enabled) {
561
- _context3.next = 108;
562
+ _context3.next = 109;
562
563
  break;
563
564
  }
564
- _context3.next = 107;
565
+ _context3.next = 108;
565
566
  return this.FabricUrl({
566
567
  libraryId: libraryId,
567
568
  objectId: objectId,
568
569
  rep: "playout/default/hls-clear/playlist.m3u8"
569
570
  });
570
- case 107:
571
- playout_urls.hls_clear = _context3.sent;
572
571
  case 108:
572
+ playout_urls.hls_clear = _context3.sent;
573
+ case 109:
573
574
  hls_aes128_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods["aes-128"] !== undefined;
574
575
  if (!hls_aes128_enabled) {
575
- _context3.next = 113;
576
+ _context3.next = 114;
576
577
  break;
577
578
  }
578
- _context3.next = 112;
579
+ _context3.next = 113;
579
580
  return this.FabricUrl({
580
581
  libraryId: libraryId,
581
582
  objectId: objectId,
582
583
  rep: "playout/default/hls-aes128/playlist.m3u8"
583
584
  });
584
- case 112:
585
- playout_urls.hls_aes128 = _context3.sent;
586
585
  case 113:
586
+ playout_urls.hls_aes128 = _context3.sent;
587
+ case 114:
587
588
  hls_sample_aes_enabled = playout_options && playout_options.hls && playout_options.hls.playoutMethods && playout_options.hls.playoutMethods["sample-aes"] !== undefined;
588
589
  if (!hls_sample_aes_enabled) {
589
- _context3.next = 118;
590
+ _context3.next = 119;
590
591
  break;
591
592
  }
592
- _context3.next = 117;
593
+ _context3.next = 118;
593
594
  return this.FabricUrl({
594
595
  libraryId: libraryId,
595
596
  objectId: objectId,
596
597
  rep: "playout/default/hls-sample-aes/playlist.m3u8"
597
598
  });
598
- case 117:
599
- playout_urls.hls_sample_aes = _context3.sent;
600
599
  case 118:
601
- _context3.next = 120;
600
+ playout_urls.hls_sample_aes = _context3.sent;
601
+ case 119:
602
+ _context3.next = 121;
602
603
  return this.NetworkInfo();
603
- case 120:
604
+ case 121:
604
605
  networkInfo = _context3.sent;
605
- _context3.next = 123;
606
+ _context3.next = 124;
606
607
  return this.authClient.AuthorizationToken({
607
608
  libraryId: libraryId,
608
609
  objectId: objectId,
@@ -610,7 +611,7 @@ exports.StreamStatus = /*#__PURE__*/function () {
610
611
  noCache: true,
611
612
  noAuth: true
612
613
  });
613
- case 123:
614
+ case 124:
614
615
  token = _context3.sent;
615
616
  embed_net = "main";
616
617
  if (networkInfo.name.includes("demo")) {
@@ -619,20 +620,20 @@ exports.StreamStatus = /*#__PURE__*/function () {
619
620
  embed_url = "https://embed.v3.contentfabric.io/?net=".concat(embed_net, "&p&ct=h&oid=").concat(conf.objectId, "&mt=lv&ath=").concat(token);
620
621
  playout_urls.embed_url = embed_url;
621
622
  status.playout_urls = playout_urls;
622
- case 129:
623
- _context3.next = 134;
623
+ case 130:
624
+ _context3.next = 135;
624
625
  break;
625
- case 131:
626
- _context3.prev = 131;
626
+ case 132:
627
+ _context3.prev = 132;
627
628
  _context3.t6 = _context3["catch"](5);
628
629
  console.error(_context3.t6);
629
- case 134:
630
- return _context3.abrupt("return", status);
631
630
  case 135:
631
+ return _context3.abrupt("return", status);
632
+ case 136:
632
633
  case "end":
633
634
  return _context3.stop();
634
635
  }
635
- }, _callee3, this, [[5, 131], [59, 70], [82, 92]]);
636
+ }, _callee3, this, [[5, 132], [60, 71], [83, 93]]);
636
637
  }));
637
638
  return function (_x3) {
638
639
  return _ref6.apply(this, arguments);
@@ -801,31 +802,29 @@ exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
801
802
  case 0:
802
803
  name = _ref9.name, op = _ref9.op;
803
804
  _context5.prev = 1;
804
- console.log("Stream ", op, ": ", name);
805
- _context5.next = 5;
805
+ _context5.next = 4;
806
806
  return this.StreamStatus({
807
807
  name: name
808
808
  });
809
- case 5:
809
+ case 4:
810
810
  status = _context5.sent;
811
811
  if (!(status.state != "stopped")) {
812
- _context5.next = 10;
812
+ _context5.next = 9;
813
813
  break;
814
814
  }
815
815
  if (!(op === "start")) {
816
- _context5.next = 10;
816
+ _context5.next = 9;
817
817
  break;
818
818
  }
819
819
  status.error = "Unable to start stream - state: " + status.state;
820
820
  return _context5.abrupt("return", status);
821
- case 10:
821
+ case 9:
822
822
  if (!(status.state == "running" || status.state == "starting" || status.state == "stalled")) {
823
- _context5.next = 33;
823
+ _context5.next = 31;
824
824
  break;
825
825
  }
826
- console.log("STOPPING");
827
- _context5.prev = 12;
828
- _context5.next = 15;
826
+ _context5.prev = 10;
827
+ _context5.next = 13;
829
828
  return this.CallBitcodeMethod({
830
829
  libraryId: status.library_id,
831
830
  objectId: status.object_id,
@@ -833,50 +832,50 @@ exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
833
832
  method: "/live/stop/" + status.tlro,
834
833
  constant: false
835
834
  });
836
- case 15:
837
- _context5.next = 19;
835
+ case 13:
836
+ _context5.next = 17;
838
837
  break;
838
+ case 15:
839
+ _context5.prev = 15;
840
+ _context5.t0 = _context5["catch"](10);
839
841
  case 17:
840
- _context5.prev = 17;
841
- _context5.t0 = _context5["catch"](12);
842
- case 19:
843
842
  // Wait until LRO is terminated
844
843
  _tries = 10;
845
- case 20:
844
+ case 18:
846
845
  if (!(status.state != "stopped" && _tries-- > 0)) {
847
- _context5.next = 29;
846
+ _context5.next = 27;
848
847
  break;
849
848
  }
850
849
  console.log("Wait to terminate - ", status.state);
851
- _context5.next = 24;
850
+ _context5.next = 22;
852
851
  return Sleep(1000);
853
- case 24:
854
- _context5.next = 26;
852
+ case 22:
853
+ _context5.next = 24;
855
854
  return this.StreamStatus({
856
855
  name: name
857
856
  });
858
- case 26:
857
+ case 24:
859
858
  status = _context5.sent;
860
- _context5.next = 20;
859
+ _context5.next = 18;
861
860
  break;
862
- case 29:
861
+ case 27:
863
862
  console.log("Status after stop - ", status.state);
864
863
  if (!(_tries <= 0)) {
865
- _context5.next = 33;
864
+ _context5.next = 31;
866
865
  break;
867
866
  }
868
867
  console.log("Failed to stop");
869
868
  return _context5.abrupt("return", status);
870
- case 33:
869
+ case 31:
871
870
  if (!(op === "stop")) {
872
- _context5.next = 35;
871
+ _context5.next = 33;
873
872
  break;
874
873
  }
875
874
  return _context5.abrupt("return", status);
876
- case 35:
875
+ case 33:
877
876
  console.log("STARTING", "edge_write_token", status.edge_write_token);
878
- _context5.prev = 36;
879
- _context5.next = 39;
877
+ _context5.prev = 34;
878
+ _context5.next = 37;
880
879
  return this.CallBitcodeMethod({
881
880
  libraryId: status.library_id,
882
881
  objectId: status.object_id,
@@ -884,49 +883,49 @@ exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
884
883
  method: "/live/start",
885
884
  constant: false
886
885
  });
887
- case 39:
888
- _context5.next = 45;
886
+ case 37:
887
+ _context5.next = 43;
889
888
  break;
890
- case 41:
891
- _context5.prev = 41;
892
- _context5.t1 = _context5["catch"](36);
889
+ case 39:
890
+ _context5.prev = 39;
891
+ _context5.t1 = _context5["catch"](34);
893
892
  console.log("LRO Start (failed): ", _context5.t1);
894
893
  return _context5.abrupt("return", {
895
894
  state: status.state,
896
895
  error: "LRO start failed - must create a stream first"
897
896
  });
898
- case 45:
897
+ case 43:
899
898
  // Wait until LRO is 'starting'
900
899
  tries = 10;
901
- case 46:
900
+ case 44:
902
901
  if (!(status.state != "starting" && tries-- > 0)) {
903
- _context5.next = 55;
902
+ _context5.next = 53;
904
903
  break;
905
904
  }
906
905
  console.log("Wait to start - ", status.state);
907
- _context5.next = 50;
906
+ _context5.next = 48;
908
907
  return Sleep(1000);
909
- case 50:
910
- _context5.next = 52;
908
+ case 48:
909
+ _context5.next = 50;
911
910
  return this.StreamStatus({
912
911
  name: name
913
912
  });
914
- case 52:
913
+ case 50:
915
914
  status = _context5.sent;
916
- _context5.next = 46;
915
+ _context5.next = 44;
917
916
  break;
918
- case 55:
917
+ case 53:
919
918
  console.log("Status after restart - ", status.state);
920
919
  return _context5.abrupt("return", status);
921
- case 59:
922
- _context5.prev = 59;
920
+ case 57:
921
+ _context5.prev = 57;
923
922
  _context5.t2 = _context5["catch"](1);
924
923
  console.error(_context5.t2);
925
- case 62:
924
+ case 60:
926
925
  case "end":
927
926
  return _context5.stop();
928
927
  }
929
- }, _callee5, this, [[1, 59], [12, 17], [36, 41]]);
928
+ }, _callee5, this, [[1, 57], [10, 15], [34, 39]]);
930
929
  }));
931
930
  return function (_x5) {
932
931
  return _ref10.apply(this, arguments);
@@ -934,8 +933,7 @@ exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
934
933
  }();
935
934
 
936
935
  /**
937
- * Stop the live stream session and close the edge write token.
938
- * Not implemented fully
936
+ * Close the edge write token and make the stream object inactive.
939
937
  *
940
938
  * @methodGroup Live Stream
941
939
  * @namedParams
@@ -945,13 +943,13 @@ exports.StreamStartOrStopOrReset = /*#__PURE__*/function () {
945
943
  */
946
944
  exports.StreamStopSession = /*#__PURE__*/function () {
947
945
  var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
948
- var name, conf, objectId, libraryId, mainMeta, fabURI, edgeWriteToken, edgeMeta, status, tries, fin;
946
+ var name, conf, objectId, libraryId, mainMeta, fabURI, metaEdgeWriteToken, streamMetadata, status, _yield$this$EditConte, writeToken, newState, stopTime, finalizeMetadata, fin;
949
947
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
950
948
  while (1) switch (_context6.prev = _context6.next) {
951
949
  case 0:
952
950
  name = _ref11.name;
953
951
  _context6.prev = 1;
954
- console.log("TERMINATE: ", name);
952
+ this.Log("Terminating stream session for: ".concat(name));
955
953
  _context6.next = 5;
956
954
  return this.LoadConf({
957
955
  name: name
@@ -980,121 +978,108 @@ exports.StreamStopSession = /*#__PURE__*/function () {
980
978
  this.SetNodes({
981
979
  fabricURIs: [fabURI]
982
980
  });
983
- edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
984
- if (!(edgeWriteToken === undefined || edgeWriteToken === "")) {
981
+ metaEdgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
982
+ if (metaEdgeWriteToken) {
985
983
  _context6.next = 19;
986
984
  break;
987
985
  }
988
986
  return _context6.abrupt("return", {
989
987
  state: "inactive",
990
- error: "no active streams - must create a stream first"
988
+ error: "The stream is not active"
991
989
  });
992
990
  case 19:
993
- _context6.next = 21;
991
+ _context6.prev = 19;
992
+ _context6.next = 22;
994
993
  return this.ContentObjectMetadata({
995
994
  libraryId: libraryId,
996
995
  objectId: objectId,
997
- writeToken: edgeWriteToken
996
+ writeToken: metaEdgeWriteToken
998
997
  });
999
- case 21:
1000
- edgeMeta = _context6.sent;
1001
- _context6.next = 24;
998
+ case 22:
999
+ streamMetadata = _context6.sent;
1000
+ _context6.next = 25;
1002
1001
  return this.StreamStatus({
1003
1002
  name: name
1004
1003
  });
1005
- case 24:
1004
+ case 25:
1006
1005
  status = _context6.sent;
1007
- if (!(status.state != "terminated")) {
1008
- _context6.next = 48;
1006
+ if (!(status.state !== "stopped")) {
1007
+ _context6.next = 28;
1009
1008
  break;
1010
1009
  }
1011
- console.log("STOPPING");
1012
- _context6.prev = 27;
1010
+ return _context6.abrupt("return", {
1011
+ state: status.state,
1012
+ error: "The stream must be stopped before terminating"
1013
+ });
1014
+ case 28:
1013
1015
  _context6.next = 30;
1014
- return this.CallBitcodeMethod({
1015
- libraryId: status.library_id,
1016
- objectId: status.object_id,
1017
- writeToken: status.edge_write_token,
1018
- method: "/live/stop/" + status.tlro,
1019
- constant: false
1016
+ return this.DeleteWriteToken({
1017
+ libraryId: libraryId,
1018
+ writeToken: metaEdgeWriteToken
1020
1019
  });
1021
1020
  case 30:
1022
- _context6.next = 34;
1021
+ _context6.next = 35;
1023
1022
  break;
1024
1023
  case 32:
1025
1024
  _context6.prev = 32;
1026
- _context6.t0 = _context6["catch"](27);
1027
- case 34:
1028
- // Wait until LRO is terminated
1029
- tries = 10;
1025
+ _context6.t0 = _context6["catch"](19);
1026
+ this.Log("Unable to retrieve metadata for edge write token ".concat(edgeWriteToken));
1030
1027
  case 35:
1031
- if (!(status.state != "stopped" && tries-- > 0)) {
1032
- _context6.next = 44;
1033
- break;
1034
- }
1035
- console.log("Wait to terminate - ", status.state);
1036
- _context6.next = 39;
1037
- return Sleep(1000);
1038
- case 39:
1039
- _context6.next = 41;
1040
- return this.StreamStatus({
1041
- name: name
1028
+ _context6.next = 37;
1029
+ return this.EditContentObject({
1030
+ libraryId: libraryId,
1031
+ objectId: objectId
1042
1032
  });
1043
- case 41:
1044
- status = _context6.sent;
1045
- _context6.next = 35;
1046
- break;
1047
- case 44:
1048
- console.log("Status after stop - ", status.state);
1049
- if (!(tries <= 0)) {
1050
- _context6.next = 48;
1051
- break;
1052
- }
1053
- console.log("Failed to stop");
1054
- return _context6.abrupt("return", status);
1055
- case 48:
1056
- // Set stop time
1057
- edgeMeta.recording_stop_time = Math.floor(new Date().getTime() / 1000);
1058
- console.log("recording_start_time: ", edgeMeta.recording_start_time);
1059
- console.log("recording_stop_time: ", edgeMeta.recording_stop_time);
1060
- edgeMeta.live_recording.status = {
1061
- state: "terminated",
1062
- recording_stop_time: edgeMeta.recording_stop_time
1033
+ case 37:
1034
+ _yield$this$EditConte = _context6.sent;
1035
+ writeToken = _yield$this$EditConte.writeToken;
1036
+ // Set stop time and inactive state
1037
+ newState = "inactive";
1038
+ stopTime = Math.floor(new Date().getTime() / 1000);
1039
+ finalizeMetadata = {
1040
+ live_recording: {
1041
+ status: {
1042
+ edge_write_token: "",
1043
+ state: newState,
1044
+ recording_stop_time: stopTime
1045
+ },
1046
+ fabric_config: {
1047
+ edge_write_token: ""
1048
+ }
1049
+ },
1050
+ recording_stop_time: stopTime
1063
1051
  };
1064
- edgeMeta.live_recording.fabric_config.edge_write_token = "";
1065
- _context6.next = 55;
1066
- return this.ReplaceMetadata({
1052
+ _context6.next = 44;
1053
+ return this.MergeMetadata({
1067
1054
  libraryId: libraryId,
1068
1055
  objectId: objectId,
1069
- writeToken: edgeWriteToken,
1070
- metadata: edgeMeta
1056
+ writeToken: writeToken,
1057
+ metadata: finalizeMetadata
1071
1058
  });
1072
- case 55:
1073
- _context6.next = 57;
1059
+ case 44:
1060
+ _context6.next = 46;
1074
1061
  return this.FinalizeContentObject({
1075
1062
  libraryId: libraryId,
1076
1063
  objectId: objectId,
1077
- writeToken: edgeWriteToken,
1078
- commitMessage: "Finalize live stream - stop time " + edgeMeta.recording_stop_time,
1079
- publish: false // Don't publish this version because it is not currently useful
1064
+ writeToken: writeToken,
1065
+ commitMessage: "Deactivate live stream - stop time ".concat(stopTime)
1080
1066
  });
1081
- case 57:
1067
+ case 46:
1082
1068
  fin = _context6.sent;
1083
1069
  return _context6.abrupt("return", {
1084
1070
  fin: fin,
1085
1071
  name: name,
1086
- edge_write_token: edgeWriteToken,
1087
- state: "terminated"
1072
+ state: newState
1088
1073
  });
1089
- case 61:
1090
- _context6.prev = 61;
1074
+ case 50:
1075
+ _context6.prev = 50;
1091
1076
  _context6.t1 = _context6["catch"](1);
1092
1077
  console.error(_context6.t1);
1093
- case 64:
1078
+ case 53:
1094
1079
  case "end":
1095
1080
  return _context6.stop();
1096
1081
  }
1097
- }, _callee6, this, [[1, 61], [27, 32]]);
1082
+ }, _callee6, this, [[1, 50], [19, 32]]);
1098
1083
  }));
1099
1084
  return function (_x6) {
1100
1085
  return _ref12.apply(this, arguments);
@@ -1662,24 +1647,25 @@ exports.StreamConfig = /*#__PURE__*/function () {
1662
1647
  mainMeta = _context11.sent;
1663
1648
  userConfig = mainMeta.live_recording_config;
1664
1649
  status.user_config = userConfig;
1650
+ console.log("userConfig", userConfig);
1665
1651
 
1666
1652
  // Get node URI from user config
1667
- hostName = userConfig.url.replace("udp://", "").replace("rtmp://", "").split(":")[0];
1653
+ hostName = userConfig.url.replace("udp://", "").replace("rtmp://", "").replace("srt://", "").split(":")[0];
1668
1654
  streamUrl = new URL(userConfig.url);
1669
1655
  console.log("Retrieving nodes...");
1670
- _context11.next = 20;
1656
+ _context11.next = 21;
1671
1657
  return this.SpaceNodes({
1672
1658
  matchEndpoint: hostName
1673
1659
  });
1674
- case 20:
1660
+ case 21:
1675
1661
  nodes = _context11.sent;
1676
1662
  if (!(nodes.length < 1)) {
1677
- _context11.next = 24;
1663
+ _context11.next = 25;
1678
1664
  break;
1679
1665
  }
1680
1666
  status.error = "No node matching stream URL " + streamUrl.href;
1681
1667
  return _context11.abrupt("return", status);
1682
- case 24:
1668
+ case 25:
1683
1669
  node = nodes[0];
1684
1670
  status.node = node;
1685
1671
  endpoint = node.endpoints[0];
@@ -1693,17 +1679,17 @@ exports.StreamConfig = /*#__PURE__*/function () {
1693
1679
  timeoutId = setTimeout(function () {
1694
1680
  controller.abort();
1695
1681
  }, 60 * 1000); // milliseconds
1696
- _context11.prev = 31;
1697
- _context11.next = 34;
1682
+ _context11.prev = 32;
1683
+ _context11.next = 35;
1698
1684
  return this.Rep({
1699
1685
  libraryId: libraryId,
1700
1686
  objectId: conf.objectId,
1701
1687
  rep: "probe"
1702
1688
  });
1703
- case 34:
1689
+ case 35:
1704
1690
  probeUrl = _context11.sent;
1705
1691
  _context11.t0 = this.utils;
1706
- _context11.next = 38;
1692
+ _context11.next = 39;
1707
1693
  return HttpClient.Fetch(probeUrl, {
1708
1694
  body: JSON.stringify({
1709
1695
  "filename": streamUrl.href,
@@ -1712,35 +1698,34 @@ exports.StreamConfig = /*#__PURE__*/function () {
1712
1698
  method: "POST",
1713
1699
  signal: controller.signal
1714
1700
  });
1715
- case 38:
1701
+ case 39:
1716
1702
  _context11.t1 = _context11.sent;
1717
- _context11.next = 41;
1703
+ _context11.next = 42;
1718
1704
  return _context11.t0.ResponseToJson.call(_context11.t0, _context11.t1);
1719
- case 41:
1705
+ case 42:
1720
1706
  probe = _context11.sent;
1721
1707
  if (probe) {
1722
1708
  clearTimeout(timeoutId);
1723
1709
  }
1724
1710
  if (!probe.errors) {
1725
- _context11.next = 45;
1711
+ _context11.next = 46;
1726
1712
  break;
1727
1713
  }
1728
1714
  throw probe.errors[0];
1729
- case 45:
1730
- _context11.next = 54;
1715
+ case 46:
1716
+ _context11.next = 55;
1731
1717
  break;
1732
- case 47:
1733
- _context11.prev = 47;
1734
- _context11.t2 = _context11["catch"](31);
1718
+ case 48:
1719
+ _context11.prev = 48;
1720
+ _context11.t2 = _context11["catch"](32);
1735
1721
  if (!(_context11.t2.code === "ETIMEDOUT")) {
1736
- _context11.next = 53;
1722
+ _context11.next = 54;
1737
1723
  break;
1738
1724
  }
1739
1725
  throw "Stream probe time out - make sure the stream source is available";
1740
- case 53:
1741
- throw _context11.t2;
1742
1726
  case 54:
1743
- console.log("PROBE", probe);
1727
+ throw _context11.t2;
1728
+ case 55:
1744
1729
  probe.format.filename = streamUrl.href;
1745
1730
 
1746
1731
  // Create live recording config
@@ -1773,31 +1758,199 @@ exports.StreamConfig = /*#__PURE__*/function () {
1773
1758
  });
1774
1759
  case 66:
1775
1760
  _context11.next = 68;
1776
- return this.ReplaceMetadata({
1777
- libraryId: libraryId,
1778
- objectId: conf.objectId,
1779
- writeToken: writeToken,
1780
- metadataSubtree: "probe",
1781
- metadata: probe
1782
- });
1783
- case 68:
1784
- _context11.next = 70;
1785
1761
  return this.FinalizeContentObject({
1786
1762
  libraryId: libraryId,
1787
1763
  objectId: conf.objectId,
1788
1764
  writeToken: writeToken,
1789
1765
  commitMessage: "Apply live stream configuration"
1790
1766
  });
1791
- case 70:
1767
+ case 68:
1792
1768
  status.fin = _context11.sent;
1793
1769
  return _context11.abrupt("return", status);
1794
- case 72:
1770
+ case 70:
1795
1771
  case "end":
1796
1772
  return _context11.stop();
1797
1773
  }
1798
- }, _callee11, this, [[31, 47]]);
1774
+ }, _callee11, this, [[32, 48]]);
1799
1775
  }));
1800
1776
  return function (_x11) {
1801
1777
  return _ref22.apply(this, arguments);
1802
1778
  };
1803
- }();
1779
+ }();
1780
+
1781
+ /**
1782
+ * List the pre-allocated URLs for a site
1783
+ *
1784
+ * @methodGroup Live Stream
1785
+ * @namedParams
1786
+ * @param {string=} - ID of the live stream site object
1787
+ *
1788
+ * @return {Promise<Object>} - The list of stream URLs
1789
+ */
1790
+ exports.StreamListUrls = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
1791
+ var _this = this;
1792
+ var _ref24,
1793
+ siteId,
1794
+ STATUS_MAP,
1795
+ tenantContractId,
1796
+ streamMetadata,
1797
+ activeUrlMap,
1798
+ streamUrlStatus,
1799
+ streamUrls,
1800
+ _args13 = arguments;
1801
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1802
+ while (1) switch (_context13.prev = _context13.next) {
1803
+ case 0:
1804
+ _ref24 = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {}, siteId = _ref24.siteId;
1805
+ _context13.prev = 1;
1806
+ STATUS_MAP = {
1807
+ UNCONFIGURED: "unconfigured",
1808
+ UNINITIALIZED: "uninitialized",
1809
+ INACTIVE: "inactive",
1810
+ STOPPED: "stopped",
1811
+ STARTING: "starting",
1812
+ RUNNING: "running",
1813
+ STALLED: "stalled"
1814
+ };
1815
+ if (siteId) {
1816
+ _context13.next = 12;
1817
+ break;
1818
+ }
1819
+ _context13.next = 6;
1820
+ return this.userProfileClient.TenantContractId();
1821
+ case 6:
1822
+ tenantContractId = _context13.sent;
1823
+ if (tenantContractId) {
1824
+ _context13.next = 9;
1825
+ break;
1826
+ }
1827
+ throw Error("No tenant contract ID configured");
1828
+ case 9:
1829
+ _context13.next = 11;
1830
+ return this.ContentObjectMetadata({
1831
+ libraryId: tenantContractId.replace("iten", "ilib"),
1832
+ objectId: tenantContractId.replace("iten", "iq__"),
1833
+ metadataSubtree: "public/sites/live_streams"
1834
+ });
1835
+ case 11:
1836
+ siteId = _context13.sent;
1837
+ case 12:
1838
+ _context13.t0 = this;
1839
+ _context13.next = 15;
1840
+ return this.ContentObjectLibraryId({
1841
+ objectId: siteId
1842
+ });
1843
+ case 15:
1844
+ _context13.t1 = _context13.sent;
1845
+ _context13.t2 = siteId;
1846
+ _context13.t3 = {
1847
+ libraryId: _context13.t1,
1848
+ objectId: _context13.t2,
1849
+ metadataSubtree: "public/asset_metadata/live_streams",
1850
+ resolveLinks: true,
1851
+ resolveIgnoreErrors: true
1852
+ };
1853
+ _context13.next = 20;
1854
+ return _context13.t0.ContentObjectMetadata.call(_context13.t0, _context13.t3);
1855
+ case 20:
1856
+ streamMetadata = _context13.sent;
1857
+ activeUrlMap = {};
1858
+ _context13.next = 24;
1859
+ return this.utils.LimitedMap(10, Object.keys(streamMetadata || {}), /*#__PURE__*/function () {
1860
+ var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(slug) {
1861
+ var stream, versionHash, objectId, libraryId, status, streamMeta, url, isActive;
1862
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1863
+ while (1) switch (_context12.prev = _context12.next) {
1864
+ case 0:
1865
+ stream = streamMetadata[slug];
1866
+ if (stream && stream.sources && stream.sources["default"] && stream.sources["default"]["."] && stream.sources["default"]["."].container || ((stream["/"] || "").match(/^\/?qfab\/([\w]+)\/?.+/) || [])[1]) {
1867
+ versionHash = stream.sources["default"]["."].container || ((stream["/"] || "").match(/^\/?qfab\/([\w]+)\/?.+/) || [])[1];
1868
+ }
1869
+ if (!versionHash) {
1870
+ _context12.next = 16;
1871
+ break;
1872
+ }
1873
+ objectId = _this.utils.DecodeVersionHash(versionHash).objectId;
1874
+ _context12.next = 6;
1875
+ return _this.ContentObjectLibraryId({
1876
+ objectId: objectId
1877
+ });
1878
+ case 6:
1879
+ libraryId = _context12.sent;
1880
+ _context12.next = 9;
1881
+ return _this.StreamStatus({
1882
+ name: objectId
1883
+ });
1884
+ case 9:
1885
+ status = _context12.sent;
1886
+ _context12.next = 12;
1887
+ return _this.ContentObjectMetadata({
1888
+ objectId: objectId,
1889
+ libraryId: libraryId,
1890
+ select: ["live_recording_config/reference_url",
1891
+ // live_recording_config/url is the old path
1892
+ "live_recording_config/url"]
1893
+ });
1894
+ case 12:
1895
+ streamMeta = _context12.sent;
1896
+ url = streamMeta.live_recording_config.reference_url || streamMeta.live_recording_config.url;
1897
+ isActive = [STATUS_MAP.STARTING, STATUS_MAP.RUNNING, STATUS_MAP.STALLED, STATUS_MAP.STOPPED].includes(status.state);
1898
+ if (url && isActive) {
1899
+ activeUrlMap[url] = true;
1900
+ }
1901
+ case 16:
1902
+ case "end":
1903
+ return _context12.stop();
1904
+ }
1905
+ }, _callee12);
1906
+ }));
1907
+ return function (_x12) {
1908
+ return _ref25.apply(this, arguments);
1909
+ };
1910
+ }());
1911
+ case 24:
1912
+ streamUrlStatus = {};
1913
+ _context13.t4 = this;
1914
+ _context13.next = 28;
1915
+ return this.ContentObjectLibraryId({
1916
+ objectId: siteId
1917
+ });
1918
+ case 28:
1919
+ _context13.t5 = _context13.sent;
1920
+ _context13.t6 = siteId;
1921
+ _context13.t7 = {
1922
+ libraryId: _context13.t5,
1923
+ objectId: _context13.t6,
1924
+ metadataSubtree: "/live_stream_urls",
1925
+ resolveLinks: true,
1926
+ resolveIgnoreErrors: true
1927
+ };
1928
+ _context13.next = 33;
1929
+ return _context13.t4.ContentObjectMetadata.call(_context13.t4, _context13.t7);
1930
+ case 33:
1931
+ streamUrls = _context13.sent;
1932
+ if (streamUrls) {
1933
+ _context13.next = 36;
1934
+ break;
1935
+ }
1936
+ throw Error("No pre-allocated URLs configured");
1937
+ case 36:
1938
+ Object.keys(streamUrls || {}).forEach(function (protocol) {
1939
+ streamUrlStatus[protocol] = streamUrls[protocol].map(function (url) {
1940
+ return {
1941
+ url: url,
1942
+ active: activeUrlMap[url] || false
1943
+ };
1944
+ });
1945
+ });
1946
+ return _context13.abrupt("return", streamUrlStatus);
1947
+ case 40:
1948
+ _context13.prev = 40;
1949
+ _context13.t8 = _context13["catch"](1);
1950
+ console.error(_context13.t8);
1951
+ case 43:
1952
+ case "end":
1953
+ return _context13.stop();
1954
+ }
1955
+ }, _callee13, this, [[1, 40]]);
1956
+ }));