rx-player 3.28.0 → 3.28.1-dev.2022083000

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.
Files changed (104) hide show
  1. package/.github/workflows/checks.yml +20 -18
  2. package/CHANGELOG.md +11 -0
  3. package/VERSION +1 -1
  4. package/dist/_esm5.processed/compat/eme/load_session.d.ts +5 -6
  5. package/dist/_esm5.processed/compat/eme/load_session.js +5 -6
  6. package/dist/_esm5.processed/core/api/public_api.js +2 -2
  7. package/dist/_esm5.processed/core/decrypt/create_session.js +33 -4
  8. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.d.ts +14 -0
  9. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +25 -0
  10. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +1 -1
  11. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +1 -1
  12. package/dist/_esm5.processed/core/init/content_time_boundaries_observer.js +110 -38
  13. package/dist/_esm5.processed/core/stream/representation/check_for_discontinuity.js +21 -9
  14. package/dist/_esm5.processed/core/stream/representation/get_buffer_status.js +21 -29
  15. package/dist/_esm5.processed/errors/encrypted_media_error.d.ts +1 -2
  16. package/dist/_esm5.processed/errors/encrypted_media_error.js +0 -1
  17. package/dist/_esm5.processed/errors/error_codes.d.ts +6 -1
  18. package/dist/_esm5.processed/errors/media_error.d.ts +1 -2
  19. package/dist/_esm5.processed/errors/media_error.js +0 -1
  20. package/dist/_esm5.processed/errors/network_error.d.ts +1 -2
  21. package/dist/_esm5.processed/errors/network_error.js +0 -1
  22. package/dist/_esm5.processed/errors/other_error.d.ts +1 -2
  23. package/dist/_esm5.processed/errors/other_error.js +0 -1
  24. package/dist/_esm5.processed/manifest/manifest.d.ts +1 -1
  25. package/dist/_esm5.processed/manifest/manifest.js +1 -1
  26. package/dist/_esm5.processed/manifest/representation_index/static.d.ts +21 -6
  27. package/dist/_esm5.processed/manifest/representation_index/static.js +26 -8
  28. package/dist/_esm5.processed/manifest/representation_index/types.d.ts +55 -44
  29. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.d.ts +21 -8
  30. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.js +25 -10
  31. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.d.ts +26 -12
  32. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.js +26 -13
  33. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.d.ts +23 -7
  34. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.js +65 -22
  35. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +20 -3
  36. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +57 -7
  37. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/{is_period_fulfilled.d.ts → utils.d.ts} +3 -6
  38. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/{is_period_fulfilled.js → utils.js} +4 -8
  39. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_periods.js +1 -1
  40. package/dist/_esm5.processed/parsers/manifest/local/parse_local_manifest.js +5 -8
  41. package/dist/_esm5.processed/parsers/manifest/local/representation_index.d.ts +21 -8
  42. package/dist/_esm5.processed/parsers/manifest/local/representation_index.js +49 -14
  43. package/dist/_esm5.processed/parsers/manifest/local/types.d.ts +16 -0
  44. package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.d.ts +20 -6
  45. package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.js +28 -10
  46. package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.js +4 -4
  47. package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.d.ts +21 -12
  48. package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.js +39 -14
  49. package/dist/_esm5.processed/parsers/manifest/utils/get_first_time_from_adaptation.js +1 -1
  50. package/dist/_esm5.processed/parsers/manifest/utils/get_last_time_from_adaptation.js +1 -1
  51. package/dist/_esm5.processed/transports/metaplaylist/pipelines.js +0 -2
  52. package/dist/_esm5.processed/transports/smooth/segment_loader.js +1 -1
  53. package/dist/_esm5.processed/transports/types.d.ts +1 -1
  54. package/dist/_esm5.processed/utils/deep_merge.d.ts +1 -1
  55. package/dist/_esm5.processed/utils/deep_merge.js +6 -5
  56. package/dist/_esm5.processed/utils/task_canceller.d.ts +0 -3
  57. package/dist/_esm5.processed/utils/task_canceller.js +0 -3
  58. package/dist/mpd-parser.wasm +0 -0
  59. package/dist/rx-player.js +1382 -1058
  60. package/dist/rx-player.min.js +1 -1
  61. package/jest.config.js +5 -0
  62. package/package.json +31 -30
  63. package/sonar-project.properties +1 -1
  64. package/src/compat/eme/load_session.ts +5 -6
  65. package/src/core/api/public_api.ts +2 -2
  66. package/src/core/decrypt/create_session.ts +28 -2
  67. package/src/core/decrypt/utils/loaded_sessions_store.ts +29 -0
  68. package/src/core/fetchers/segment/segment_fetcher.ts +1 -1
  69. package/src/core/init/content_time_boundaries_observer.ts +116 -42
  70. package/src/core/stream/representation/check_for_discontinuity.ts +28 -10
  71. package/src/core/stream/representation/get_buffer_status.ts +27 -34
  72. package/src/errors/encrypted_media_error.ts +1 -2
  73. package/src/errors/error_codes.ts +2 -2
  74. package/src/errors/media_error.ts +1 -2
  75. package/src/errors/network_error.ts +1 -2
  76. package/src/errors/other_error.ts +1 -2
  77. package/src/manifest/__tests__/adaptation.test.ts +4 -3
  78. package/src/manifest/__tests__/representation.test.ts +4 -3
  79. package/src/manifest/manifest.ts +1 -1
  80. package/src/manifest/representation_index/__tests__/static.test.ts +5 -4
  81. package/src/manifest/representation_index/static.ts +28 -9
  82. package/src/manifest/representation_index/types.ts +62 -46
  83. package/src/parsers/manifest/dash/common/indexes/base.ts +27 -11
  84. package/src/parsers/manifest/dash/common/indexes/list.ts +32 -15
  85. package/src/parsers/manifest/dash/common/indexes/template.ts +73 -27
  86. package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +60 -8
  87. package/src/parsers/manifest/dash/common/indexes/{is_period_fulfilled.ts → utils.ts} +4 -13
  88. package/src/parsers/manifest/dash/common/parse_periods.ts +1 -1
  89. package/src/parsers/manifest/local/parse_local_manifest.ts +8 -20
  90. package/src/parsers/manifest/local/representation_index.ts +51 -16
  91. package/src/parsers/manifest/local/types.ts +13 -0
  92. package/src/parsers/manifest/metaplaylist/representation_index.ts +31 -11
  93. package/src/parsers/manifest/smooth/create_parser.ts +4 -4
  94. package/src/parsers/manifest/smooth/representation_index.ts +40 -15
  95. package/src/parsers/manifest/utils/__tests__/get_first_time_from_adaptations.test.ts +4 -3
  96. package/src/parsers/manifest/utils/__tests__/get_last_time_from_adaptation.test.ts +4 -3
  97. package/src/parsers/manifest/utils/get_first_time_from_adaptation.ts +1 -1
  98. package/src/parsers/manifest/utils/get_last_time_from_adaptation.ts +1 -1
  99. package/src/transports/metaplaylist/pipelines.ts +0 -2
  100. package/src/transports/smooth/segment_loader.ts +1 -1
  101. package/src/transports/types.ts +1 -1
  102. package/src/utils/__tests__/initialization_segment_cache.test.ts +7 -0
  103. package/src/utils/deep_merge.ts +7 -4
  104. package/src/utils/task_canceller.ts +0 -3
@@ -562,9 +562,9 @@ function createSmoothStreamingParser(
562
562
  const firstVideoRepresentation = firstVideoAdaptation.representations[0];
563
563
  if (firstVideoRepresentation !== undefined) {
564
564
  const firstVideoTimeReference =
565
- firstVideoRepresentation.index.getFirstPosition();
565
+ firstVideoRepresentation.index.getFirstAvailablePosition();
566
566
  const lastVideoTimeReference =
567
- firstVideoRepresentation.index.getLastPosition();
567
+ firstVideoRepresentation.index.getLastAvailablePosition();
568
568
 
569
569
  if (firstVideoTimeReference != null) {
570
570
  firstTimeReferences.push(firstVideoTimeReference);
@@ -580,9 +580,9 @@ function createSmoothStreamingParser(
580
580
  const firstAudioRepresentation = firstAudioAdaptation.representations[0];
581
581
  if (firstAudioRepresentation !== undefined) {
582
582
  const firstAudioTimeReference =
583
- firstAudioRepresentation.index.getFirstPosition();
583
+ firstAudioRepresentation.index.getFirstAvailablePosition();
584
584
  const lastAudioTimeReference =
585
- firstAudioRepresentation.index.getLastPosition();
585
+ firstAudioRepresentation.index.getLastAvailablePosition();
586
586
 
587
587
  if (firstAudioTimeReference != null) {
588
588
  firstTimeReferences.push(firstAudioTimeReference);
@@ -21,6 +21,7 @@ import {
21
21
  ISegment,
22
22
  } from "../../../manifest";
23
23
  import { IPlayerError } from "../../../public_types";
24
+ import assert from "../../../utils/assert";
24
25
  import clearTimelineFromPosition from "../utils/clear_timeline_from_position";
25
26
  import {
26
27
  checkDiscontinuity,
@@ -318,7 +319,7 @@ export default class SmoothRepresentationIndex implements IRepresentationIndex {
318
319
  * Generate a list of Segments for a particular period of time.
319
320
  *
320
321
  * @param {Number} from
321
- * @param {Number} duration
322
+ * @param {Number} dur
322
323
  * @returns {Array.<Object>}
323
324
  */
324
325
  getSegments(from : number, dur : number) : ISegment[] {
@@ -427,11 +428,9 @@ export default class SmoothRepresentationIndex implements IRepresentationIndex {
427
428
 
428
429
  /**
429
430
  * Returns first position available in the index.
430
- *
431
- * @param {Object} index
432
431
  * @returns {Number|null}
433
432
  */
434
- getFirstPosition() : number|null {
433
+ getFirstAvailablePosition() : number|null {
435
434
  this._refreshTimeline();
436
435
  const index = this._index;
437
436
  if (index.timeline.length === 0) {
@@ -442,10 +441,9 @@ export default class SmoothRepresentationIndex implements IRepresentationIndex {
442
441
 
443
442
  /**
444
443
  * Returns last position available in the index.
445
- * @param {Object} index
446
444
  * @returns {Number}
447
445
  */
448
- getLastPosition() : number|undefined {
446
+ getLastAvailablePosition() : number|undefined {
449
447
  this._refreshTimeline();
450
448
  const index = this._index;
451
449
 
@@ -470,6 +468,42 @@ export default class SmoothRepresentationIndex implements IRepresentationIndex {
470
468
  return undefined;
471
469
  }
472
470
 
471
+ /**
472
+ * Returns the absolute end in seconds this RepresentationIndex can reach once
473
+ * all segments are available.
474
+ * @returns {number|null|undefined}
475
+ */
476
+ getEnd() : number | null | undefined {
477
+ if (!this._isLive) {
478
+ return this.getLastAvailablePosition();
479
+ }
480
+ return undefined;
481
+ }
482
+
483
+ /**
484
+ * Returns:
485
+ * - `true` if in the given time interval, at least one new segment is
486
+ * expected to be available in the future.
487
+ * - `false` either if all segments in that time interval are already
488
+ * available for download or if none will ever be available for it.
489
+ * - `undefined` when it is not possible to tell.
490
+ * @param {number} start
491
+ * @param {number} end
492
+ * @returns {boolean|undefined}
493
+ */
494
+ awaitSegmentBetween(start: number, end: number): boolean | undefined {
495
+ assert(start <= end);
496
+ if (this.isFinished()) {
497
+ return false;
498
+ }
499
+ const lastAvailablePosition = this.getLastAvailablePosition();
500
+ if (lastAvailablePosition !== undefined && end < lastAvailablePosition) {
501
+ return false;
502
+ }
503
+ return end > (this.getFirstAvailablePosition() ?? 0) ? undefined :
504
+ false;
505
+ }
506
+
473
507
  /**
474
508
  * Checks if `timeSec` is in a discontinuity.
475
509
  * That is, if there's no segment available for the `timeSec` position.
@@ -484,15 +518,6 @@ export default class SmoothRepresentationIndex implements IRepresentationIndex {
484
518
  return checkDiscontinuity(this._index, timeSec, undefined);
485
519
  }
486
520
 
487
- /**
488
- * Returns `true` as Smooth segments should always be generated in
489
- * chronological order.
490
- * @returns {boolean}
491
- */
492
- areSegmentsChronologicallyGenerated() : true {
493
- return true;
494
- }
495
-
496
521
  /**
497
522
  * Returns `true` if a Segment returned by this index is still considered
498
523
  * available.
@@ -24,10 +24,11 @@ function generateRepresentationIndex(
24
24
  getInitSegment() { return null; },
25
25
  getSegments() { return []; },
26
26
  shouldRefresh() { return false; },
27
- getFirstPosition() : number|undefined|null { return firstPosition; },
28
- getLastPosition() : undefined { return ; },
27
+ getFirstAvailablePosition() : number|undefined|null { return firstPosition; },
28
+ getLastAvailablePosition() : undefined { return ; },
29
+ getEnd() : undefined { return ; },
30
+ awaitSegmentBetween() : undefined { return ; },
29
31
  checkDiscontinuity() : number | null { return null; },
30
- areSegmentsChronologicallyGenerated() { return true; },
31
32
  isSegmentStillAvailable() : undefined { return ; },
32
33
  isFinished() { return false; },
33
34
  canBeOutOfSyncError() : true { return true; },
@@ -24,10 +24,11 @@ function generateRepresentationIndex(
24
24
  getInitSegment() { return null; },
25
25
  getSegments() { return []; },
26
26
  shouldRefresh() { return false; },
27
- getFirstPosition() : undefined { return ; },
28
- getLastPosition() : number|undefined|null { return lastPosition; },
27
+ getFirstAvailablePosition() : undefined { return ; },
28
+ getLastAvailablePosition() : number | undefined | null { return lastPosition; },
29
+ getEnd() : undefined { return ; },
30
+ awaitSegmentBetween() : undefined { return ; },
29
31
  checkDiscontinuity() : number | null { return null; },
30
- areSegmentsChronologicallyGenerated() { return true; },
31
32
  isSegmentStillAvailable() : undefined { return ; },
32
33
  isFinished() { return false; },
33
34
  isInitialized() : true { return true; },
@@ -32,7 +32,7 @@ export default function getFirstPositionFromAdaptation(
32
32
  const { representations } = adaptation;
33
33
  let max : null | number = null;
34
34
  for (let i = 0; i < representations.length; i++) {
35
- const firstPosition = representations[i].index.getFirstPosition();
35
+ const firstPosition = representations[i].index.getFirstAvailablePosition();
36
36
  if (firstPosition === undefined) { // we cannot tell
37
37
  return undefined;
38
38
  }
@@ -34,7 +34,7 @@ export default function getLastPositionFromAdaptation(
34
34
  const { representations } = adaptation;
35
35
  let min : null | number = null;
36
36
  for (let i = 0; i < representations.length; i++) {
37
- const lastPosition = representations[i].index.getLastPosition();
37
+ const lastPosition = representations[i].index.getLastAvailablePosition();
38
38
  if (lastPosition === undefined) { // we cannot tell
39
39
  return undefined;
40
40
  }
@@ -55,7 +55,6 @@ import generateManifestLoader from "./manifest_loader";
55
55
  /**
56
56
  * Get base - real - content from an offseted metaplaylist content.
57
57
  * @param {Object} segment
58
- * @param {number} offset
59
58
  * @returns {Object}
60
59
  */
61
60
  function getOriginalContent(segment : ISegment) : { manifest : Manifest;
@@ -198,7 +197,6 @@ export default function(options : ITransportOptions): ITransportPipelines {
198
197
 
199
198
  /**
200
199
  * @param {number} contentOffset
201
- * @param {number} scaledContentOffset
202
200
  * @param {number|undefined} contentEnd
203
201
  * @param {Object} segmentResponse
204
202
  * @returns {Object}
@@ -38,7 +38,7 @@ import { isMP4EmbeddedTrack } from "./utils";
38
38
 
39
39
  /**
40
40
  * Segment loader triggered if there was no custom-defined one in the API.
41
- * @param {string} uri
41
+ * @param {string} url
42
42
  * @param {Object} content
43
43
  * @param {Object} callbacks
44
44
  * @param {Object} cancelSignal
@@ -207,7 +207,7 @@ export interface ISegmentPipeline<
207
207
 
208
208
  /**
209
209
  * Segment loader function, allowing to load a segment of any type.
210
- * @param {stop|null} url - URL at which the segment should be downloaded.
210
+ * @param {string|null} url - URL at which the segment should be downloaded.
211
211
  * `null` if we do not have an URL (in which case the segment should be loaded
212
212
  * through other means, such as information taken from the segment's content).
213
213
  * @param {Object} content - Content linked to the wanted segment.
@@ -46,6 +46,7 @@ const initSegment1 = {
46
46
  timescale: 1 as const,
47
47
  mediaURLs: ["http://www.example.com/some.URLinit1"],
48
48
  complete: true,
49
+ privateInfos: {},
49
50
  };
50
51
 
51
52
  const initSegment2 = {
@@ -57,6 +58,7 @@ const initSegment2 = {
57
58
  timescale: 1 as const,
58
59
  mediaURLs: ["http://www.example.com/some.URLinit2"],
59
60
  complete: true,
61
+ privateInfos: {},
60
62
  };
61
63
 
62
64
  const initSegment3 = {
@@ -68,6 +70,7 @@ const initSegment3 = {
68
70
  timescale: 1 as const,
69
71
  mediaURLs: ["http://www.example.com/some.URLinit3"],
70
72
  complete: true,
73
+ privateInfos: {},
71
74
  };
72
75
 
73
76
  const segment1 = {
@@ -79,6 +82,7 @@ const segment1 = {
79
82
  timescale: 1 as const,
80
83
  mediaURLs: ["http://www.example.com/some.URL2"],
81
84
  complete: true,
85
+ privateInfos: {},
82
86
  };
83
87
 
84
88
  const segment2 = {
@@ -90,6 +94,7 @@ const segment2 = {
90
94
  timescale: 1 as const,
91
95
  mediaURLs: ["http://www.example.com/some.URL2"],
92
96
  complete: true,
97
+ privateInfos: {},
93
98
  };
94
99
 
95
100
  const segment3 = {
@@ -101,6 +106,7 @@ const segment3 = {
101
106
  timescale: 1 as const,
102
107
  mediaURLs: ["http://www.example.com/some.URL3"],
103
108
  complete: true,
109
+ privateInfos: {},
104
110
  };
105
111
 
106
112
  const segment4 = {
@@ -112,6 +118,7 @@ const segment4 = {
112
118
  timescale: 1 as const,
113
119
  mediaURLs: ["http://www.example.com/some.URL4"],
114
120
  complete: true,
121
+ privateInfos: {},
115
122
  };
116
123
 
117
124
  const data1 = new Uint8Array([0]);
@@ -24,7 +24,9 @@ type ISourcesArgument<T> = Array<IDeepPartial<T>|unknown>;
24
24
  * @param sources
25
25
  * @returns output : merged object
26
26
  */
27
- export default function deepMerge<T>(target: T, ...sources: ISourcesArgument<T>): T {
27
+ export default function deepMerge<
28
+ T extends Record<string | number | symbol, unknown>
29
+ >(target: T, ...sources: ISourcesArgument<T>): T {
28
30
  if (sources.length === 0) {
29
31
  return target;
30
32
  }
@@ -32,10 +34,11 @@ export default function deepMerge<T>(target: T, ...sources: ISourcesArgument<T>)
32
34
  if (isObject(target) && isObject(source)) {
33
35
  for (const key in source) {
34
36
  if (isObject(source[key])) {
35
- if (target[key] === undefined) {
36
- objectAssign(target, { [key]: {} });
37
+ let newTarget = target[key] as Record<string | number | symbol, unknown>;
38
+ if (newTarget === undefined) {
39
+ newTarget = {};
40
+ (target[key] as Record<string | number | symbol, unknown>) = newTarget;
37
41
  }
38
- const newTarget = target[key];
39
42
  deepMerge(newTarget, source[key] as IDeepPartial<typeof newTarget>);
40
43
  } else {
41
44
  objectAssign(target, { [key]: source[key] });
@@ -308,9 +308,6 @@ export class CancellationError extends Error {
308
308
  public readonly name : "CancellationError";
309
309
  public readonly message : string;
310
310
 
311
- /**
312
- * @param {string} message
313
- */
314
311
  constructor() {
315
312
  super();
316
313
  // @see https://stackoverflow.com/questions/41102060/typescript-extending-error-class