@eluvio/elv-client-js 4.0.77 → 4.0.78

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.77",
3
+ "version": "4.0.78",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -476,6 +476,7 @@ class FrameClient {
476
476
  "StartABRMezzanineJobs",
477
477
  "StreamConfig",
478
478
  "StreamCreate",
479
+ "StreamDeactivate",
479
480
  "StreamInitialize",
480
481
  "StreamInsertion",
481
482
  "StreamStatus",
@@ -2176,6 +2176,11 @@ const EmbedMediaTypes = {
2176
2176
  - `showTitle` - Shows the video title, which is set from the title option (if set) or the metadata
2177
2177
  - `title` - Sets the page title
2178
2178
  - `viewRecordKey` - Contains record key
2179
+ - `useTicketCodes` - Use tickets authorization
2180
+ - `tenantId` - Tenant ID, required for tickets authorization
2181
+ - `ntpId` - NTP ID, required for tickets authorization
2182
+ - `ticketCode` - Ticket code, optional with tickets authorization
2183
+ - `ticketSubject` - Ticket subject, optional with tickets authorization
2179
2184
  *
2180
2185
  * @returns {Promise<string>} - Will return an embed URL
2181
2186
  */
@@ -2279,6 +2284,22 @@ exports.EmbedUrl = async function({
2279
2284
  case "viewRecordKey":
2280
2285
  embedUrl.searchParams.set("vrk", options.viewRecordKey);
2281
2286
  break;
2287
+ case "useTicketCodes":
2288
+ embedUrl.searchParams.set("ptk", "");
2289
+ if (options.tenantId) {
2290
+ embedUrl.searchParams.set("ten", options.tenantId);
2291
+ }
2292
+ if (options.ntpId) {
2293
+ embedUrl.searchParams.set("ntp", options.ntpId);
2294
+ }
2295
+ if (options.ticketCode) {
2296
+ embedUrl.searchParams.set("tk", Buffer.from(options.ticketCode).toString("base64"));
2297
+
2298
+ }
2299
+ if (options.ticketSubject) {
2300
+ embedUrl.searchParams.set("sbj", Buffer.from(options.ticketSubject).toString("base64"));
2301
+ }
2302
+ break;
2282
2303
  }
2283
2304
  }
2284
2305
 
@@ -107,6 +107,7 @@ const LiveconfTemplate = {
107
107
  sync_audio_to_stream_id: -1,
108
108
  video_bitrate: null,
109
109
  video_seg_duration_ts: null,
110
+ video_time_base: null,
110
111
  xc_type: 3
111
112
  }
112
113
  }
@@ -160,56 +161,156 @@ class LiveConf {
160
161
  }
161
162
  }
162
163
 
163
- calcSegDuration({sourceTimescale}) {
164
+ /*
165
+ * Calculates mez segment durations based on input stream parameters
166
+ *
167
+ * Live input formats have fixed timebase:
168
+ * - MPEG-TS/SRT input stream timebase is 90000
169
+ * - RTMP input stream timebase is 1000 and gets translated to 16000 if not otherwise specified
170
+ *
171
+ * This causes frame duration irregularities for certain frame rates.
172
+ * For example RTMP 60fps has frames of durations 16 and 17. MPEG-TS 59.94fps has frames of
173
+ * durations 1001 and 1002.
174
+ *
175
+ * Live mez segmentation requires that the segment be cut at the specific number of frames, and when
176
+ * the frame durations are irregular we adjust both the video timebase and the video frame duration
177
+ * to make the math possible. This adjustment is also required for live-to-vod conversion.
178
+ *
179
+ * For example for MPEG-TS 59.94fps, the mez segment timebase needs to be 60000
180
+ * (and resulting frame duration is 1001) and for RTMP 60fps the timebase needs to be 15360 (resulting frame
181
+ * duration is 256).
182
+ *
183
+ * @sourceTimescale - adjusted source video stream timescale (eg. MPEGTS 90000, RTMP 16000 )
184
+ * @sampleRate - audio sample rate (commonly 48000 but can be different)
185
+ * @audioCodec - audio codec as a string (eg. "aac")
186
+ * @return - segment encoding parameters
187
+ */
188
+ calcSegDuration({sourceTimescale, sampleRate, audioCodec}) {
189
+ let seg = {};
190
+
191
+ switch(this.probeKind()) {
192
+ case "rtmp":
193
+ seg = this.calcSegDurationRtmp({sourceTimescale, sampleRate, audioCodec});
194
+ break;
195
+ case "udp":
196
+ case "srt":
197
+ seg = this.calcSegDurationMpegts({sourceTimescale, sampleRate, audioCodec});
198
+ break;
199
+ default:
200
+ throw "protocol not supported - " + this.probeKind();
201
+ }
202
+
203
+ if(audioCodec == "aac") {
204
+ seg.audio = 29.76 * sampleRate;
205
+ } else {
206
+ seg.audio = 29.76 * 48000; // Other codecs are resampled @48000
207
+ }
208
+
209
+ return seg;
210
+ }
211
+
212
+ calcSegDurationMpegts({sourceTimescale}) {
164
213
  let videoStream = this.getStreamDataForCodecType("video");
165
214
  let frameRate = videoStream.frame_rate;
215
+ let seg = {};
216
+
217
+ switch(frameRate) {
218
+ case "24":
219
+ seg.video = sourceTimescale * 30;
220
+ seg.keyint = 48;
221
+ seg.duration = "30";
222
+ break;
223
+ case "25":
224
+ seg.video = sourceTimescale * 30;
225
+ seg.keyint = 50;
226
+ seg.duration = "30";
227
+ break;
228
+ case "30":
229
+ seg.video = sourceTimescale * 30;
230
+ seg.keyint = 60;
231
+ seg.duration = "30";
232
+ break;
233
+ case "30000/1001":
234
+ seg.video = sourceTimescale * 30;
235
+ seg.keyint = 60;
236
+ seg.duration = "30.03";
237
+ break;
238
+ case "48":
239
+ seg.video = sourceTimescale * 30;
240
+ seg.keyint = 96;
241
+ seg.duration = "30";
242
+ break;
243
+ case "50":
244
+ seg.video = sourceTimescale * 30;
245
+ seg.keyint = 100;
246
+ seg.duration = "30";
247
+ break;
248
+ case "60":
249
+ seg.video = sourceTimescale * 30;
250
+ seg.keyint = 120;
251
+ seg.duration = "30";
252
+ break;
253
+ case "60000/1001":
254
+ seg.videoTimeBase = 60000;
255
+ seg.video = seg.videoTimeBase * 30.03;
256
+ seg.keyint = 120;
257
+ seg.duration = "30.03";
258
+ break;
259
+ default:
260
+ throw "unsupported frame rate for MPEGTS - " + frameRate;
261
+ break;
262
+ }
263
+ return seg;
264
+ }
166
265
 
266
+ calcSegDurationRtmp({sourceTimescale}) {
267
+ let videoStream = this.getStreamDataForCodecType("video");
268
+ let frameRate = videoStream.frame_rate;
167
269
  let seg = {};
168
- seg.audio = 29.76 * 48000;
169
270
 
170
271
  switch(frameRate) {
171
272
  case "24":
172
- seg.video = 30 * sourceTimescale;
273
+ seg.video = sourceTimescale * 30;
173
274
  seg.keyint = 48;
174
275
  seg.duration = "30";
175
276
  break;
176
277
  case "25":
177
- seg.video = 30 * sourceTimescale;
278
+ seg.video = sourceTimescale * 30;
178
279
  seg.keyint = 50;
179
280
  seg.duration = "30";
180
281
  break;
181
282
  case "30":
182
- seg.video = 30 * sourceTimescale;
283
+ seg.video = sourceTimescale * 30;
183
284
  seg.keyint = 60;
184
285
  seg.duration = "30";
185
286
  break;
186
287
  case "30000/1001":
187
- seg.video = 30.03 * sourceTimescale;
288
+ seg.video = sourceTimescale * 30.03;
188
289
  seg.keyint = 60;
189
290
  seg.duration = "30.03";
190
291
  break;
191
292
  case "48":
192
- seg.video = 30 * sourceTimescale;
293
+ seg.video = sourceTimescale * 30;
193
294
  seg.keyint = 96;
194
295
  seg.duration = "30";
195
296
  break;
196
297
  case "50":
197
- seg.video = 30 * sourceTimescale;
298
+ seg.video = sourceTimescale * 30;
198
299
  seg.keyint = 100;
199
300
  seg.duration = "30";
200
301
  break;
201
302
  case "60":
202
- seg.video = 30 * sourceTimescale;
303
+ seg.video = sourceTimescale * 30;
203
304
  seg.keyint = 120;
204
305
  seg.duration = "30";
205
306
  break;
206
307
  case "60000/1001":
207
- seg.video = 30.03 * sourceTimescale;
308
+ seg.video = sourceTimescale * 30.03;
208
309
  seg.keyint = 120;
209
310
  seg.duration = "30.03";
210
311
  break;
211
312
  default:
212
- console.log("Unsupported frame rate", frameRate);
313
+ throw "unsupported frame rate for RTMP - " + frameRate;
213
314
  break;
214
315
  }
215
316
  return seg;
@@ -220,10 +321,11 @@ class LiveConf {
220
321
  let videoStream = this.getStreamDataForCodecType("video");
221
322
  switch(this.probeKind()) {
222
323
  case "udp":
324
+ case "srt":
223
325
  sync_id = videoStream.stream_id;
224
326
  break;
225
327
  case "rtmp":
226
- sync_id = -1; // Pending fabric API: videoStream.stream_index
328
+ sync_id = videoStream.stream_index;
227
329
  break;
228
330
  }
229
331
  return sync_id;
@@ -234,14 +336,14 @@ class LiveConf {
234
336
  const conf = JSON.parse(JSON.stringify(LiveconfTemplate));
235
337
  const fileName = this.overwriteOriginUrl || this.probeData.format.filename;
236
338
  const audioStream = this.getStreamDataForCodecType("audio");
339
+
237
340
  const sampleRate = parseInt(audioStream.sample_rate);
341
+ const audioCodec = audioStream.codec_name;
238
342
  const videoStream = this.getStreamDataForCodecType("video");
239
343
  let sourceTimescale;
240
344
 
241
- console.log("AUDIO", audioStream);
242
- console.log("VIDEO", videoStream);
243
-
244
345
  // Fill in liveconf all formats have in common
346
+ conf.live_recording.probe_info = this.probeData;
245
347
  conf.live_recording.fabric_config.ingress_node_api = this.nodeUrl || null;
246
348
  conf.live_recording.fabric_config.ingress_node_id = this.nodeId || null;
247
349
  conf.live_recording.recording_config.recording_params.description;
@@ -267,6 +369,11 @@ class LiveConf {
267
369
  sourceTimescale = 90000;
268
370
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
269
371
  break;
372
+ case "srt":
373
+ sourceTimescale = 90000;
374
+ conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
375
+ conf.live_recording.recording_config.recording_params.live_delay_nano = 4000000000;
376
+ break;
270
377
  case "rtmp":
271
378
  sourceTimescale = 16000;
272
379
  conf.live_recording.recording_config.recording_params.source_timescale = sourceTimescale;
@@ -279,7 +386,7 @@ class LiveConf {
279
386
  break;
280
387
  }
281
388
 
282
- const segDurations = this.calcSegDuration({sourceTimescale});
389
+ const segDurations = this.calcSegDuration({sourceTimescale, sampleRate, audioCodec});
283
390
 
284
391
  // Segment conditioning parameters
285
392
  conf.live_recording.recording_config.recording_params.xc_params.seg_duration = segDurations.duration;
@@ -287,6 +394,15 @@ class LiveConf {
287
394
  conf.live_recording.recording_config.recording_params.xc_params.video_seg_duration_ts = segDurations.video;
288
395
  conf.live_recording.recording_config.recording_params.xc_params.force_keyint = segDurations.keyint;
289
396
 
397
+ // Optional override output timebase and frame duration (ts)
398
+ if(segDurations.videoTimeBase) {
399
+ conf.live_recording.recording_config.recording_params.xc_params.video_time_base = segDurations.videoTimeBase;
400
+ conf.live_recording.recording_config.recording_params.source_timescale = segDurations.videoTimeBase;
401
+ }
402
+ if(segDurations.videoFrameDurationTs) {
403
+ conf.live_recording.recording_config.recording_params.xc_params.video_frame_duration_ts = segDurations.videoFrameDurationTs;
404
+ }
405
+
290
406
  switch(videoStream.height) {
291
407
  case 2160:
292
408
  conf.live_recording.recording_config.recording_params.ladder_specs.unshift(
@@ -136,9 +136,9 @@ const StreamGenerateOffering = async({
136
136
  const maxStreamIndex = Math.max(aStreamIndex, vStreamIndex);
137
137
 
138
138
  for(let i = 0; i <= maxStreamIndex; i++) {
139
- if (i === aStreamIndex) {
139
+ if(i === aStreamIndex) {
140
140
  sourceStreams.push(sourceAudioStream);
141
- } else if (i === vStreamIndex) {
141
+ } else if(i === vStreamIndex) {
142
142
  sourceStreams.push(sourceVideoStream);
143
143
  } else {
144
144
  sourceStreams.push(DUMMY_STREAM);
@@ -242,12 +242,12 @@ const StreamGenerateOffering = async({
242
242
  abrProfile
243
243
  });
244
244
 
245
- if (createResponse.warnings.length > 0) {
245
+ if(createResponse.warnings.length > 0) {
246
246
  console.log("WARNINGS:");
247
247
  console.log(JSON.stringify(createResponse.warnings, null, 2));
248
248
  }
249
249
 
250
- if (createResponse.errors.length > 0) {
250
+ if(createResponse.errors.length > 0) {
251
251
  console.log("ERRORS:");
252
252
  console.log(JSON.stringify(createResponse.errors, null, 2));
253
253
  }
@@ -339,6 +339,8 @@ exports.StreamStatus = async function({name, stopLro=false, showParams=false}) {
339
339
  ]
340
340
  });
341
341
 
342
+ status.reference_url = mainMeta.live_recording_config.reference_url;
343
+
342
344
  if(mainMeta.live_recording_config == undefined || mainMeta.live_recording_config.url == undefined) {
343
345
  status.state = "unconfigured";
344
346
  return status;
@@ -367,7 +369,7 @@ exports.StreamStatus = async function({name, stopLro=false, showParams=false}) {
367
369
  status.url = mainMeta.live_recording.recording_config.recording_params.origin_url;
368
370
 
369
371
  let edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
370
- if(edgeWriteToken == undefined) {
372
+ if(!edgeWriteToken) {
371
373
  status.state = "inactive";
372
374
  return status;
373
375
  }
@@ -688,8 +690,6 @@ exports.StreamCreate = async function({name, start=false}) {
688
690
  */
689
691
  exports.StreamStartOrStopOrReset = async function({name, op}) {
690
692
  try {
691
- console.log("Stream ", op, ": ", name);
692
-
693
693
  let status = await this.StreamStatus({name});
694
694
  if(status.state != "stopped") {
695
695
  if(op === "start") {
@@ -699,8 +699,6 @@ exports.StreamStartOrStopOrReset = async function({name, op}) {
699
699
  }
700
700
 
701
701
  if(status.state == "running" || status.state == "starting" || status.state == "stalled") {
702
- console.log("STOPPING");
703
-
704
702
  try {
705
703
  await this.CallBitcodeMethod({
706
704
  libraryId: status.library_id,
@@ -834,7 +832,7 @@ exports.StreamStopSession = async function({name}) {
834
832
 
835
833
  // Wait until LRO is terminated
836
834
  let tries = 10;
837
- while (status.state != "stopped" && tries-- > 0) {
835
+ while(status.state != "stopped" && tries-- > 0) {
838
836
  console.log("Wait to terminate - ", status.state);
839
837
  await Sleep(1000);
840
838
  status = await this.StreamStatus({name});
@@ -1202,7 +1200,7 @@ exports.StreamInsertion = async function({name, insertionTime, sinceStart=false,
1202
1200
  playout: "/qfab/" + targetHash + "/rep/playout" // TO FIX - should be a link
1203
1201
  };
1204
1202
 
1205
- for (let i = 0; i < insertions.length; i ++) {
1203
+ for(let i = 0; i < insertions.length; i ++) {
1206
1204
  if(insertions[i].insertion_time <= currentTime) {
1207
1205
  // Bad insertion - must be later than current time
1208
1206
  append(errs, "Bad insertion - time:", insertions[i].insertion_time);
@@ -1325,9 +1323,10 @@ exports.StreamConfig = async function({name, customSettings={}}) {
1325
1323
 
1326
1324
  let userConfig = mainMeta.live_recording_config;
1327
1325
  status.user_config = userConfig;
1326
+ console.log("userConfig", userConfig);
1328
1327
 
1329
1328
  // Get node URI from user config
1330
- const hostName = userConfig.url.replace("udp://", "").replace("rtmp://", "").split(":")[0];
1329
+ const hostName = userConfig.url.replace("udp://", "").replace("rtmp://", "").replace("srt://", "").split(":")[0];
1331
1330
  const streamUrl = new URL(userConfig.url);
1332
1331
 
1333
1332
  console.log("Retrieving nodes...");
@@ -1380,7 +1379,6 @@ exports.StreamConfig = async function({name, customSettings={}}) {
1380
1379
  }
1381
1380
  }
1382
1381
 
1383
- console.log("PROBE", probe);
1384
1382
  probe.format.filename = streamUrl.href;
1385
1383
 
1386
1384
  // Create live recording config
@@ -1410,14 +1408,6 @@ exports.StreamConfig = async function({name, customSettings={}}) {
1410
1408
  metadata: liveRecordingConfig.live_recording
1411
1409
  });
1412
1410
 
1413
- await this.ReplaceMetadata({
1414
- libraryId,
1415
- objectId: conf.objectId,
1416
- writeToken,
1417
- metadataSubtree: "probe",
1418
- metadata: probe
1419
- });
1420
-
1421
1411
  status.fin = await this.FinalizeContentObject({
1422
1412
  libraryId,
1423
1413
  objectId: conf.objectId,
@@ -1427,3 +1417,100 @@ exports.StreamConfig = async function({name, customSettings={}}) {
1427
1417
 
1428
1418
  return status;
1429
1419
  };
1420
+
1421
+ /**
1422
+ * Deactivate the stream
1423
+ *
1424
+ * @methodGroup Live Stream
1425
+ * @namedParams
1426
+ * @param {string} name - Object ID or name of the live stream object
1427
+ *
1428
+ * @return {Promise<Object>} - The status response for the stream
1429
+ */
1430
+ exports.StreamDeactivate = async function({name}) {
1431
+ try {
1432
+ let conf = await this.LoadConf({name});
1433
+
1434
+ let {objectId} = conf;
1435
+ let libraryId = await this.ContentObjectLibraryId({objectId});
1436
+
1437
+ let mainMeta = await this.ContentObjectMetadata({
1438
+ libraryId,
1439
+ objectId
1440
+ });
1441
+ let status = await this.StreamStatus({name});
1442
+
1443
+ if(!mainMeta.live_recording) {
1444
+ return {
1445
+ state: status.state,
1446
+ error: "Stream must be configured before deactivating"
1447
+ };
1448
+ }
1449
+
1450
+ // Return error if the LRO is running
1451
+ if(status.state !== "stopped") {
1452
+ return {
1453
+ state: status.state,
1454
+ error: "Stream must be stopped before deactivating"
1455
+ };
1456
+ }
1457
+
1458
+ let fabURI = mainMeta.live_recording.fabric_config.ingress_node_api;
1459
+ // Support both hostname and URL ingress_node_api
1460
+ if(!fabURI.startsWith("http")) {
1461
+ // Assume https
1462
+ fabURI = "https://" + fabURI;
1463
+ }
1464
+
1465
+ this.SetNodes({fabricURIs: [fabURI]});
1466
+
1467
+ let edgeWriteToken = mainMeta.live_recording.fabric_config.edge_write_token;
1468
+
1469
+ if(edgeWriteToken === undefined || edgeWriteToken === "") {
1470
+ return {
1471
+ state: "inactive",
1472
+ error: "stream is already inactive"
1473
+ };
1474
+ }
1475
+ let edgeMeta = await this.ContentObjectMetadata({
1476
+ libraryId,
1477
+ objectId,
1478
+ writeToken: edgeWriteToken
1479
+ });
1480
+
1481
+ // Set stop time
1482
+ edgeMeta.recording_stop_time = Math.floor(new Date().getTime() / 1000);
1483
+ const newState = "inactive";
1484
+
1485
+ edgeMeta.live_recording.status = {
1486
+ state: newState,
1487
+ recording_stop_time: edgeMeta.recording_stop_time
1488
+ };
1489
+
1490
+ edgeMeta.live_recording.fabric_config.edge_write_token = "";
1491
+
1492
+ await this.ReplaceMetadata({
1493
+ libraryId,
1494
+ objectId,
1495
+ writeToken: edgeWriteToken,
1496
+ metadata: edgeMeta
1497
+ });
1498
+
1499
+ let fin = await this.FinalizeContentObject({
1500
+ libraryId,
1501
+ objectId,
1502
+ writeToken: edgeWriteToken,
1503
+ commitMessage: "Deactivate stream"
1504
+ });
1505
+
1506
+ return {
1507
+ reference_url: status.reference_url,
1508
+ fin,
1509
+ name,
1510
+ edge_write_token: edgeWriteToken,
1511
+ state: newState
1512
+ };
1513
+ } catch(error) {
1514
+ console.error(error);
1515
+ }
1516
+ };
@@ -16,6 +16,13 @@ const Test = async () => {
16
16
  });
17
17
 
18
18
  client.SetSigner({signer});
19
+
20
+ const versionHash = "";
21
+
22
+ const url = await client.FabricUrl({
23
+ versionHash
24
+ });
25
+ console.log("url", url)
19
26
  } catch(error) {
20
27
  console.error(error);
21
28
  console.error(JSON.stringify(error, null, 2));