@eluvio/elv-client-js 4.2.17 → 4.2.18

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.
@@ -1,13 +1,11 @@
1
+ var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
1
2
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
2
- var _objectWithoutProperties = require("@babel/runtime/helpers/objectWithoutProperties");
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
3
  var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
5
4
  var _createClass = require("@babel/runtime/helpers/createClass");
6
- var _excluded = ["recording_config", "recording_params"];
7
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
7
  /* eslint no-console: 0 */
10
- var R = require("ramda");
8
+
11
9
  var DefaultABRLadder = {
12
10
  "video": [{
13
11
  bit_rate: 14000000,
@@ -53,9 +51,8 @@ var LiveconfTemplate = {
53
51
  },
54
52
  playout_config: {
55
53
  dvr_enabled: true,
56
- dvr_max_duration: 14400,
54
+ dvr_max_duration: 0,
57
55
  rebroadcast_start_time_sec_epoch: 0,
58
- playout_sharding_level: 2,
59
56
  vod_enabled: false
60
57
  },
61
58
  recording_config: {
@@ -63,11 +60,11 @@ var LiveconfTemplate = {
63
60
  description: "",
64
61
  ladder_specs: [],
65
62
  listen: true,
66
- live_delay_nano: 6000000000,
63
+ live_delay_nano: 2000000000,
67
64
  max_duration_sec: -1,
68
65
  name: "",
69
66
  origin_url: "",
70
- part_ttl: 86400,
67
+ part_ttl: 3600,
71
68
  playout_type: "live",
72
69
  source_timescale: null,
73
70
  reconnect_timeout: 600,
@@ -104,52 +101,20 @@ var LiveconfTemplate = {
104
101
  var LiveConf = /*#__PURE__*/function () {
105
102
  "use strict";
106
103
 
107
- function LiveConf(_ref) {
108
- var url = _ref.url,
109
- probeData = _ref.probeData,
110
- nodeId = _ref.nodeId,
111
- nodeUrl = _ref.nodeUrl,
112
- includeAVSegDurations = _ref.includeAVSegDurations,
113
- overwriteOriginUrl = _ref.overwriteOriginUrl,
114
- syncAudioToVideo = _ref.syncAudioToVideo,
115
- liveRecordingMeta = _ref.liveRecordingMeta;
104
+ function LiveConf(probeData, nodeId, nodeUrl, includeAVSegDurations, overwriteOriginUrl, syncAudioToVideo) {
116
105
  _classCallCheck(this, LiveConf);
117
- this.url = url;
118
106
  this.probeData = probeData;
119
107
  this.nodeId = nodeId;
120
108
  this.nodeUrl = nodeUrl;
121
109
  this.includeAVSegDurations = includeAVSegDurations;
122
110
  this.overwriteOriginUrl = overwriteOriginUrl;
123
111
  this.syncAudioToVideo = syncAudioToVideo;
124
- this.currentLiveRecordingMeta = liveRecordingMeta;
125
112
  }
126
113
  _createClass(LiveConf, [{
127
- key: "getFormat",
128
- value: function getFormat() {
129
- var _this$probeData$forma;
130
- if (this.probeData.format.format_name) {
131
- return this.probeData.format.format_name;
132
- }
133
- var fileNameSplit = (_this$probeData$forma = this.probeData.format) === null || _this$probeData$forma === void 0 || (_this$probeData$forma = _this$probeData$forma.filename) === null || _this$probeData$forma === void 0 ? void 0 : _this$probeData$forma.split(":");
134
- if (fileNameSplit.length > 1) {
135
- var protoScheme = fileNameSplit[0];
136
- switch (protoScheme) {
137
- case "rtmp":
138
- return "flv";
139
- case "udp":
140
- case "rtp":
141
- case "srt":
142
- return "mpegts";
143
- default:
144
- return "format_unknown";
145
- }
146
- }
147
- }
148
- }, {
149
- key: "getProtocol",
150
- value: function getProtocol() {
151
- var protoScheme = this.url.split(":")[0];
152
- return protoScheme;
114
+ key: "probeKind",
115
+ value: function probeKind() {
116
+ var fileNameSplit = this.probeData.format.filename.split(":");
117
+ return fileNameSplit[0];
153
118
  }
154
119
  }, {
155
120
  key: "getStreamDataForCodecType",
@@ -167,27 +132,19 @@ var LiveConf = /*#__PURE__*/function () {
167
132
  // Used by generateAudioStreamsConfig()
168
133
  }, {
169
134
  key: "getAudioStreamsFromProbe",
170
- value: function getAudioStreamsFromProbe(_ref2) {
171
- var ladderProfile = _ref2.ladderProfile;
135
+ value: function getAudioStreamsFromProbe() {
172
136
  var audioStreams = {};
173
137
  var audioStreamData = this.probeData.streams.filter(function (value) {
174
138
  return value.codec_type === "audio";
175
139
  });
176
- var _loop = function _loop() {
177
- var _ladderProfile$audio, _profileAudioForType$, _currentStreamData$bi;
140
+ for (var index = 0; index < audioStreamData.length; index++) {
178
141
  var currentStreamIndex = audioStreamData[index].stream_index;
179
142
  var currentStreamData = audioStreamData[index];
180
- var profileAudioForType = ladderProfile === null || ladderProfile === void 0 || (_ladderProfile$audio = ladderProfile.audio) === null || _ladderProfile$audio === void 0 ? void 0 : _ladderProfile$audio.find(function (a) {
181
- return a.channels === currentStreamData.channels;
182
- });
183
143
  audioStreams[currentStreamIndex] = {
184
- recordingBitrate: (_profileAudioForType$ = profileAudioForType === null || profileAudioForType === void 0 ? void 0 : profileAudioForType.bit_rate) !== null && _profileAudioForType$ !== void 0 ? _profileAudioForType$ : Math.max((_currentStreamData$bi = currentStreamData.bit_rate) !== null && _currentStreamData$bi !== void 0 ? _currentStreamData$bi : 0, 12800),
144
+ recordingBitrate: Math.max(currentStreamData.bit_rate, 128000),
185
145
  recordingChannels: currentStreamData.channels,
186
146
  playoutLabel: "Audio ".concat(index + 1)
187
147
  };
188
- };
189
- for (var index = 0; index < audioStreamData.length; index++) {
190
- _loop();
191
148
  }
192
149
  return audioStreams;
193
150
  }
@@ -242,20 +199,21 @@ var LiveConf = /*#__PURE__*/function () {
242
199
  */
243
200
  }, {
244
201
  key: "calcSegDuration",
245
- value: function calcSegDuration(_ref3) {
246
- var sourceTimescale = _ref3.sourceTimescale,
247
- sampleRate = _ref3.sampleRate,
248
- audioCodec = _ref3.audioCodec;
202
+ value: function calcSegDuration(_ref) {
203
+ var sourceTimescale = _ref.sourceTimescale,
204
+ sampleRate = _ref.sampleRate,
205
+ audioCodec = _ref.audioCodec;
249
206
  var seg = {};
250
- switch (this.getFormat()) {
251
- case "flv":
207
+ switch (this.probeKind()) {
208
+ case "rtmp":
252
209
  seg = this.calcSegDurationRtmp({
253
210
  sourceTimescale: sourceTimescale,
254
211
  sampleRate: sampleRate,
255
212
  audioCodec: audioCodec
256
213
  });
257
214
  break;
258
- case "mpegts":
215
+ case "udp":
216
+ case "srt":
259
217
  seg = this.calcSegDurationMpegts({
260
218
  sourceTimescale: sourceTimescale,
261
219
  sampleRate: sampleRate,
@@ -263,7 +221,7 @@ var LiveConf = /*#__PURE__*/function () {
263
221
  });
264
222
  break;
265
223
  default:
266
- throw "protocol not supported - " + this.getFormat();
224
+ throw "protocol not supported - " + this.probeKind();
267
225
  }
268
226
  if (audioCodec == "aac") {
269
227
  seg.audio = 29.76 * sampleRate;
@@ -287,8 +245,8 @@ var LiveConf = /*#__PURE__*/function () {
287
245
  }
288
246
  }, {
289
247
  key: "calcSegDurationMpegts",
290
- value: function calcSegDurationMpegts(_ref4) {
291
- var sourceTimescale = _ref4.sourceTimescale;
248
+ value: function calcSegDurationMpegts(_ref2) {
249
+ var sourceTimescale = _ref2.sourceTimescale;
292
250
  var videoStream = this.getStreamDataForCodecType("video");
293
251
  var frameRate = videoStream.frame_rate;
294
252
 
@@ -350,8 +308,8 @@ var LiveConf = /*#__PURE__*/function () {
350
308
  }
351
309
  }, {
352
310
  key: "calcSegDurationRtmp",
353
- value: function calcSegDurationRtmp(_ref5) {
354
- var sourceTimescale = _ref5.sourceTimescale;
311
+ value: function calcSegDurationRtmp(_ref3) {
312
+ var sourceTimescale = _ref3.sourceTimescale;
355
313
  var videoStream = this.getStreamDataForCodecType("video");
356
314
  var frameRate = videoStream.frame_rate;
357
315
  var seg = {};
@@ -414,123 +372,60 @@ var LiveConf = /*#__PURE__*/function () {
414
372
  value: function syncAudioToStreamIdValue() {
415
373
  var sync_id = -1;
416
374
  var videoStream = this.getStreamDataForCodecType("video");
417
- switch (this.getFormat()) {
418
- case "mpegts":
375
+ switch (this.probeKind()) {
376
+ case "udp":
377
+ case "srt":
419
378
  sync_id = videoStream.stream_id;
420
379
  break;
421
- case "flv":
380
+ case "rtmp":
422
381
  sync_id = videoStream.stream_index;
423
382
  break;
424
383
  }
425
384
  return sync_id;
426
385
  }
427
386
 
428
- /**
429
- * Map custom live recording profile to the expected config structure
430
- * @param {Object} customProfile - User's custom recording profile
431
- * @return {Object} - Mapped config in live_recording format
432
- */
433
- }, {
434
- key: "MapCustomProfileToLiveConfig",
435
- value: function MapCustomProfileToLiveConfig(_ref6) {
436
- var customProfile = _ref6.customProfile;
437
- if (!customProfile) return {};
438
- var CompactDeep = function CompactDeep(obj) {
439
- if (obj === null || _typeof(obj) !== "object" || Array.isArray(obj)) {
440
- return obj;
441
- }
442
- return R.pipe(R.reject(R.isNil), R.map(function (val) {
443
- return _typeof(val) === "object" ? CompactDeep(val) : val;
444
- }))(obj);
445
- };
446
- var recording_config = customProfile.recording_config,
447
- recording_params = customProfile.recording_params,
448
- rest = _objectWithoutProperties(customProfile, _excluded);
449
- return CompactDeep({
450
- live_recording: _objectSpread(_objectSpread({}, rest), {}, {
451
- recording_config: {
452
- recording_params: _objectSpread(_objectSpread({}, recording_params), {}, {
453
- part_ttl: recording_config === null || recording_config === void 0 ? void 0 : recording_config.part_ttl,
454
- reconnect_timeout: recording_config === null || recording_config === void 0 ? void 0 : recording_config.reconnect_timeout,
455
- xc_params: _objectSpread(_objectSpread({}, (recording_params === null || recording_params === void 0 ? void 0 : recording_params.xc_params) || {}), {}, {
456
- connection_timeout: recording_config === null || recording_config === void 0 ? void 0 : recording_config.connection_timeout,
457
- copy_mpegts: recording_config === null || recording_config === void 0 ? void 0 : recording_config.copy_mpegts,
458
- input_cfg: recording_config === null || recording_config === void 0 ? void 0 : recording_config.input_cfg
459
- })
460
- })
461
- }
462
- })
463
- });
464
- }
465
-
466
387
  /*
467
388
  * Generate audio streams recording configuration based on the optional custom settings.
468
389
  * If no custom "audio" section is present, record all the acceptable audio streams found in the probe
469
390
  */
470
391
  }, {
471
392
  key: "generateAudioStreamsConfig",
472
- value: function generateAudioStreamsConfig(_ref7) {
473
- var _liveRecordingConfigP, _liveRecordingConfigP2;
474
- var liveRecordingConfigProfile = _ref7.liveRecordingConfigProfile;
475
- var ladderProfile = (liveRecordingConfigProfile === null || liveRecordingConfigProfile === void 0 || (_liveRecordingConfigP = liveRecordingConfigProfile.playout_config) === null || _liveRecordingConfigP === void 0 ? void 0 : _liveRecordingConfigP.ladder_specs) || DefaultABRLadder;
476
- var audioSettings = liveRecordingConfigProfile === null || liveRecordingConfigProfile === void 0 || (_liveRecordingConfigP2 = liveRecordingConfigProfile.recording_stream_config) === null || _liveRecordingConfigP2 === void 0 ? void 0 : _liveRecordingConfigP2.audio;
393
+ value: function generateAudioStreamsConfig(_ref4) {
394
+ var customSettings = _ref4.customSettings;
477
395
  var audioStreams = {};
478
- if (audioSettings && Object.keys(audioSettings).length > 0) {
479
- var _loop2 = function _loop2() {
480
- var _audio$recording_bitr;
481
- var audioIdx = Object.keys(audioSettings)[i];
482
- var audio = audioSettings[audioIdx];
483
- var profileAudioForType = ladderProfile === null || ladderProfile === void 0 ? void 0 : ladderProfile.audio.find(function (a) {
484
- var _audio$channels;
485
- return a.channels === ((_audio$channels = audio.channels) !== null && _audio$channels !== void 0 ? _audio$channels : 2);
486
- });
396
+ if (customSettings && customSettings.audio && Object.keys(customSettings.audio).length > 0) {
397
+ for (var i = 0; i < Object.keys(customSettings.audio).length; i++) {
398
+ var audioIdx = Object.keys(customSettings.audio)[i];
399
+ var audio = customSettings.audio[audioIdx];
487
400
  audioStreams[audioIdx] = {
488
- recordingBitrate: ladderProfile !== null && ladderProfile !== void 0 && ladderProfile.audio ? profileAudioForType.bit_rate : (_audio$recording_bitr = audio.recording_bitrate) !== null && _audio$recording_bitr !== void 0 ? _audio$recording_bitr : 192000,
489
- recordingChannels: audio.recording_channels || 2,
490
- lang: audio.lang,
491
- isDefault: audio["default"]
401
+ recordingBitrate: audio.recording_bitrate || 192000,
402
+ recordingChannels: audio.recording_channels || 2
492
403
  };
493
404
  if (audio.playout) {
494
405
  audioStreams[audioIdx].playoutLabel = audio.playout_label || "Audio ".concat(i + 1);
495
406
  }
496
- };
497
- for (var i = 0; i < Object.keys(audioSettings).length; i++) {
498
- _loop2();
499
407
  }
500
408
  }
501
409
 
502
410
  // If no audio streams specified in custom config, set up all the suitable audio streams in the probe
503
- if (!audioSettings || Object.keys(audioSettings).length === 0) {
504
- audioStreams = this.getAudioStreamsFromProbe({
505
- ladderProfile: ladderProfile
506
- });
411
+ if (!customSettings.audio || Object.keys(customSettings.audio).length == 0) {
412
+ audioStreams = this.getAudioStreamsFromProbe();
507
413
  }
508
414
  return audioStreams;
509
415
  }
510
416
 
511
417
  /*
512
- * Generate the live recording config as required by QFAB, based on defaults, existing settings and optional custom settings.
418
+ * Generate the live recording config as required by QFAB, based on defaults and optional custom settings.
513
419
  */
514
420
  }, {
515
421
  key: "generateLiveConf",
516
- value: function generateLiveConf(_ref8) {
517
- var _customSettings$liveR, _customSettings$liveR2, _ladder_specs$video;
518
- var customSettings = _ref8.customSettings;
519
- // Saved config overrides defaults and is preserved on reconfiguration
520
- var conf = R.clone(LiveconfTemplate);
521
- if (this.currentLiveRecordingMeta) {
522
- conf = R.mergeDeepRight(conf, {
523
- live_recording: this.currentLiveRecordingMeta
524
- });
525
- }
526
- if (customSettings.liveRecordingConfigProfile) {
527
- conf = R.mergeDeepRight(conf, this.MapCustomProfileToLiveConfig({
528
- customProfile: customSettings.liveRecordingConfigProfile
529
- }));
530
- }
531
- var fileName = this.url;
422
+ value: function generateLiveConf(_ref5) {
423
+ var customSettings = _ref5.customSettings;
424
+ // gather required data
425
+ var conf = JSON.parse(JSON.stringify(LiveconfTemplate));
426
+ var fileName = this.overwriteOriginUrl || this.probeData.format.filename;
532
427
  var audioStreams = this.generateAudioStreamsConfig({
533
- liveRecordingConfigProfile: customSettings.liveRecordingConfigProfile
428
+ customSettings: customSettings
534
429
  });
535
430
 
536
431
  // Retrieve one audio stream from the probe to read the sample rate and codec name
@@ -558,11 +453,16 @@ var LiveConf = /*#__PURE__*/function () {
558
453
  }
559
454
 
560
455
  // Fill in specifics for protocol
561
- switch (this.getFormat()) {
562
- case "mpegts":
456
+ switch (this.probeKind()) {
457
+ case "udp":
563
458
  sourceTimescale = 90000;
564
459
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
565
460
  break;
461
+ case "srt":
462
+ sourceTimescale = 90000;
463
+ conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
464
+ conf.live_recording.recording_config.recording_params.live_delay_nano = 4000000000;
465
+ break;
566
466
  case "rtmp":
567
467
  sourceTimescale = 16000;
568
468
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
@@ -571,14 +471,7 @@ var LiveConf = /*#__PURE__*/function () {
571
471
  console.log("HLS detected. Not yet implemented");
572
472
  break;
573
473
  default:
574
- console.log("Unsupported media", this.getFormat());
575
- break;
576
- }
577
- switch (this.getProtocol()) {
578
- case "srt":
579
- if (!((_customSettings$liveR = customSettings.liveRecordingConfigProfile) !== null && _customSettings$liveR !== void 0 && (_customSettings$liveR = _customSettings$liveR.recording_params) !== null && _customSettings$liveR !== void 0 && _customSettings$liveR.live_delay_nano)) {
580
- conf.live_recording.recording_config.recording_params.live_delay_nano = 6000000000;
581
- }
474
+ console.log("Unsupported media", this.probeKind());
582
475
  break;
583
476
  }
584
477
  var segDurations = this.calcSegDuration({
@@ -603,14 +496,10 @@ var LiveConf = /*#__PURE__*/function () {
603
496
  if (segDurations.videoFrameDurationTs) {
604
497
  conf.live_recording.recording_config.recording_params.xc_params.video_frame_duration_ts = segDurations.videoFrameDurationTs;
605
498
  }
606
- var ladder_specs = (_customSettings$liveR2 = customSettings.liveRecordingConfigProfile) === null || _customSettings$liveR2 === void 0 || (_customSettings$liveR2 = _customSettings$liveR2.playout_config) === null || _customSettings$liveR2 === void 0 ? void 0 : _customSettings$liveR2.ladder_specs;
607
- var ladderProfile = (ladder_specs === null || ladder_specs === void 0 || (_ladder_specs$video = ladder_specs.video) === null || _ladder_specs$video === void 0 ? void 0 : _ladder_specs$video.length) > 0 ? ladder_specs : DefaultABRLadder;
499
+ var ladderProfile = customSettings.ladder_profile || DefaultABRLadder;
608
500
  conf.live_recording.recording_config.recording_params.xc_params.enc_height = videoStream.height;
609
501
  conf.live_recording.recording_config.recording_params.xc_params.enc_width = videoStream.width;
610
502
 
611
- // Reset ladder specs (updating existing stream will carry over old specs
612
- conf.live_recording.recording_config.recording_params.ladder_specs = [];
613
-
614
503
  // Determine video recording bitrate and ABR ladder
615
504
  var topLadderRate = 0;
616
505
  for (var _i = 0; _i < ladderProfile.video.length; _i++) {
@@ -632,7 +521,6 @@ var LiveConf = /*#__PURE__*/function () {
632
521
  var globalAudioBitrate = 0;
633
522
  var nAudio = 0;
634
523
  for (var _i2 = 0; _i2 < Object.keys(audioStreams).length; _i2++) {
635
- var _audio$lang;
636
524
  var audioLadderSpec = {};
637
525
  var audioIndex = Object.keys(audioStreams)[_i2];
638
526
  var audio = audioStreams[audioIndex];
@@ -655,8 +543,7 @@ var LiveConf = /*#__PURE__*/function () {
655
543
  audioLadderSpec.stream_name = "audio_".concat(audioIndex);
656
544
  audioLadderSpec.stream_label = audio.playoutLabel ? audio.playoutLabel : null;
657
545
  audioLadderSpec.media_type = 2;
658
- audioLadderSpec.lang = (_audio$lang = audio.lang) !== null && _audio$lang !== void 0 ? _audio$lang : "";
659
- if (Object.keys(audioStreams).length === 1 || audio.isDefault) {
546
+ if (Object.keys(audioStreams).length === 1) {
660
547
  audioLadderSpec["default"] = true;
661
548
  }
662
549
  conf.live_recording.recording_config.recording_params.ladder_specs.push(audioLadderSpec);
@@ -669,6 +556,33 @@ var LiveConf = /*#__PURE__*/function () {
669
556
  // Global recording bitrate for all audio streams
670
557
  conf.live_recording.recording_config.recording_params.xc_params.audio_bitrate = globalAudioBitrate;
671
558
  conf.live_recording.recording_config.recording_params.xc_params.n_audio = nAudio;
559
+
560
+ // Iterate through custom settings (which will override any existing setting)
561
+ function SetByPath(_ref6) {
562
+ var obj = _ref6.obj,
563
+ path = _ref6.path,
564
+ value = _ref6.value;
565
+ var keys = path.split(".");
566
+ var temp = obj;
567
+ for (var _i3 = 0; _i3 < keys.length - 1; _i3++) {
568
+ if (!temp[keys[_i3]]) {
569
+ temp[keys[_i3]] = {};
570
+ }
571
+ temp = temp[keys[_i3]];
572
+ }
573
+ temp[keys[keys.length - 1]] = value;
574
+ }
575
+ var metaPathValues = customSettings.metaPathValues;
576
+ for (var _i4 = 0, _Object$entries = Object.entries(metaPathValues || {}); _i4 < _Object$entries.length; _i4++) {
577
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i4], 2),
578
+ path = _Object$entries$_i[0],
579
+ value = _Object$entries$_i[1];
580
+ SetByPath({
581
+ obj: conf,
582
+ path: path,
583
+ value: value
584
+ });
585
+ }
672
586
  return conf;
673
587
  }
674
588
  }]);