rx-player 3.29.0-dev.2022091600 → 3.29.0-dev.2022103100
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/CHANGELOG.md +22 -10
- package/MAINTAINERS.md +2 -1
- package/VERSION +1 -1
- package/dist/_esm5.processed/compat/browser_detection.d.ts +4 -1
- package/dist/_esm5.processed/compat/browser_detection.js +7 -1
- package/dist/_esm5.processed/compat/can_reuse_media_keys.d.ts +12 -0
- package/dist/_esm5.processed/compat/can_reuse_media_keys.js +15 -0
- package/dist/_esm5.processed/compat/enable_audio_track.d.ts +11 -0
- package/dist/_esm5.processed/compat/enable_audio_track.js +26 -0
- package/dist/_esm5.processed/compat/index.d.ts +4 -2
- package/dist/_esm5.processed/compat/index.js +4 -2
- package/dist/_esm5.processed/compat/{should_renew_media_keys.d.ts → should_renew_media_key_system_access.d.ts} +3 -3
- package/dist/_esm5.processed/compat/{should_renew_media_keys.js → should_renew_media_key_system_access.js} +3 -3
- package/dist/_esm5.processed/config.d.ts +1 -0
- package/dist/_esm5.processed/core/api/playback_observer.d.ts +14 -5
- package/dist/_esm5.processed/core/api/playback_observer.js +54 -22
- package/dist/_esm5.processed/core/api/public_api.d.ts +7 -4
- package/dist/_esm5.processed/core/api/public_api.js +79 -61
- package/dist/_esm5.processed/core/api/tracks_management/media_element_track_choice_manager.js +9 -10
- package/dist/_esm5.processed/core/decrypt/__tests__/__global__/utils.js +1 -1
- package/dist/_esm5.processed/core/decrypt/find_key_system.js +3 -3
- package/dist/_esm5.processed/core/decrypt/get_media_keys.js +4 -1
- package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.d.ts +98 -0
- package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.js +173 -0
- package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +4 -4
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +2 -1
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +15 -16
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.d.ts +3 -1
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.js +5 -2
- package/dist/_esm5.processed/core/fetchers/utils/schedule_request.d.ts +103 -0
- package/dist/_esm5.processed/core/fetchers/utils/schedule_request.js +414 -0
- package/dist/_esm5.processed/core/init/content_time_boundaries_observer.d.ts +4 -3
- package/dist/_esm5.processed/core/init/content_time_boundaries_observer.js +21 -22
- package/dist/_esm5.processed/core/init/initialize_media_source.d.ts +18 -4
- package/dist/_esm5.processed/core/init/initialize_media_source.js +10 -2
- package/dist/_esm5.processed/core/init/load_on_media_source.js +7 -1
- package/dist/_esm5.processed/core/init/stall_avoider.js +3 -1
- package/dist/_esm5.processed/default_config.d.ts +11 -0
- package/dist/_esm5.processed/default_config.js +11 -0
- package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +1 -1
- package/dist/_esm5.processed/manifest/manifest.js +11 -2
- package/dist/_esm5.processed/manifest/representation.d.ts +12 -1
- package/dist/_esm5.processed/manifest/representation.js +1 -0
- package/dist/_esm5.processed/manifest/representation_index/static.d.ts +1 -1
- package/dist/_esm5.processed/manifest/representation_index/static.js +2 -2
- package/dist/_esm5.processed/manifest/representation_index/types.d.ts +32 -15
- package/dist/_esm5.processed/manifest/update_period_in_place.js +1 -0
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.d.ts +10 -9
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.js +11 -11
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/get_init_segment.d.ts +1 -1
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/get_init_segment.js +3 -3
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +1 -1
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +4 -4
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.d.ts +7 -7
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.js +12 -8
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.d.ts +5 -6
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.js +16 -16
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +11 -10
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +14 -13
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/tokens.d.ts +3 -4
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/tokens.js +4 -12
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.js +2 -4
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representation_index.js +1 -3
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representations.js +6 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/resolve_base_urls.d.ts +1 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/resolve_base_urls.js +3 -8
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/BaseURL.d.ts +1 -1
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/BaseURL.js +2 -20
- package/dist/_esm5.processed/parsers/manifest/dash/node_parser_types.d.ts +0 -6
- package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/generators/BaseURL.js +0 -11
- package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/types.d.ts +5 -1
- package/dist/_esm5.processed/parsers/manifest/local/parse_local_manifest.js +2 -1
- package/dist/_esm5.processed/parsers/manifest/local/representation_index.js +2 -2
- package/dist/_esm5.processed/parsers/manifest/metaplaylist/metaplaylist_parser.js +7 -1
- package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.js +17 -11
- package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.js +2 -2
- package/dist/_esm5.processed/parsers/manifest/types.d.ts +24 -0
- package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_extent.js +8 -1
- package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_origin.js +9 -1
- package/dist/_esm5.processed/parsers/texttracks/ttml/html/create_element.js +2 -1
- package/dist/_esm5.processed/transports/dash/construct_segment_url.d.ts +18 -0
- package/dist/_esm5.processed/transports/dash/construct_segment_url.js +21 -0
- package/dist/_esm5.processed/transports/dash/image_pipelines.d.ts +3 -2
- package/dist/_esm5.processed/transports/dash/image_pipelines.js +5 -3
- package/dist/_esm5.processed/transports/dash/segment_loader.js +4 -2
- package/dist/_esm5.processed/transports/dash/text_loader.js +4 -2
- package/dist/_esm5.processed/transports/dash/text_parser.js +3 -1
- package/dist/_esm5.processed/transports/local/segment_loader.d.ts +3 -2
- package/dist/_esm5.processed/transports/local/segment_loader.js +2 -2
- package/dist/_esm5.processed/transports/metaplaylist/pipelines.js +8 -8
- package/dist/_esm5.processed/transports/smooth/pipelines.js +11 -7
- package/dist/_esm5.processed/transports/smooth/utils.d.ts +4 -2
- package/dist/_esm5.processed/transports/smooth/utils.js +7 -1
- package/dist/_esm5.processed/transports/types.d.ts +5 -3
- package/dist/_esm5.processed/utils/event_emitter.d.ts +1 -2
- package/dist/_esm5.processed/utils/resolve_url.d.ts +7 -4
- package/dist/_esm5.processed/utils/resolve_url.js +11 -8
- package/dist/mpd-parser.wasm +0 -0
- package/dist/rx-player.js +5656 -13236
- package/dist/rx-player.min.js +1 -1
- package/jest.config.js +28 -23
- package/package.json +29 -29
- package/sonar-project.properties +1 -1
- package/src/compat/__tests__/can_reuse_media_keys.test.ts +54 -0
- package/src/compat/__tests__/enable_audio_track.test.ts +341 -0
- package/src/compat/__tests__/{should_renew_media_keys.test.ts → should_renew_media_key_system_access.test.ts} +7 -5
- package/src/compat/browser_detection.ts +10 -0
- package/src/compat/can_reuse_media_keys.ts +19 -0
- package/src/compat/enable_audio_track.ts +33 -0
- package/src/compat/index.ts +6 -2
- package/src/compat/{should_renew_media_keys.ts → should_renew_media_key_system_access.ts} +3 -3
- package/src/core/api/playback_observer.ts +97 -33
- package/src/core/api/public_api.ts +126 -74
- package/src/core/api/tracks_management/media_element_track_choice_manager.ts +3 -11
- package/src/core/decrypt/__tests__/__global__/media_keys.test.ts +182 -0
- package/src/core/decrypt/__tests__/__global__/utils.ts +2 -0
- package/src/core/decrypt/find_key_system.ts +3 -3
- package/src/core/decrypt/get_media_keys.ts +5 -1
- package/src/core/fetchers/cdn_prioritizer.ts +198 -0
- package/src/core/fetchers/manifest/manifest_fetcher.ts +7 -11
- package/src/core/fetchers/segment/segment_fetcher.ts +12 -10
- package/src/core/fetchers/segment/segment_fetcher_creator.ts +10 -1
- package/src/core/fetchers/utils/schedule_request.ts +482 -0
- package/src/core/init/content_time_boundaries_observer.ts +12 -12
- package/src/core/init/initialize_media_source.ts +31 -4
- package/src/core/init/load_on_media_source.ts +11 -2
- package/src/core/init/stall_avoider.ts +4 -1
- package/src/core/stream/orchestrator/stream_orchestrator.ts +0 -1
- package/src/default_config.ts +12 -0
- package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +1 -0
- package/src/manifest/manifest.ts +11 -2
- package/src/manifest/representation.ts +15 -0
- package/src/manifest/representation_index/__tests__/static.test.ts +1 -1
- package/src/manifest/representation_index/static.ts +3 -3
- package/src/manifest/representation_index/types.ts +33 -15
- package/src/manifest/update_period_in_place.ts +1 -0
- package/src/parsers/manifest/dash/common/indexes/base.ts +22 -23
- package/src/parsers/manifest/dash/common/indexes/get_init_segment.ts +6 -4
- package/src/parsers/manifest/dash/common/indexes/get_segments_from_timeline.ts +5 -5
- package/src/parsers/manifest/dash/common/indexes/list.ts +19 -20
- package/src/parsers/manifest/dash/common/indexes/template.ts +23 -27
- package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +25 -23
- package/src/parsers/manifest/dash/common/indexes/tokens.ts +7 -18
- package/src/parsers/manifest/dash/common/parse_mpd.ts +2 -4
- package/src/parsers/manifest/dash/common/parse_representation_index.ts +1 -6
- package/src/parsers/manifest/dash/common/parse_representations.ts +9 -0
- package/src/parsers/manifest/dash/common/resolve_base_urls.ts +5 -9
- package/src/parsers/manifest/dash/js-parser/node_parsers/BaseURL.ts +2 -29
- package/src/parsers/manifest/dash/js-parser/node_parsers/__tests__/AdaptationSet.test.ts +7 -11
- package/src/parsers/manifest/dash/node_parser_types.ts +0 -7
- package/src/parsers/manifest/dash/wasm-parser/rs/events.rs +3 -1
- package/src/parsers/manifest/dash/wasm-parser/rs/processor/attributes.rs +1 -8
- package/src/parsers/manifest/dash/wasm-parser/ts/generators/BaseURL.ts +0 -13
- package/src/parsers/manifest/dash/wasm-parser/ts/types.ts +8 -0
- package/src/parsers/manifest/local/parse_local_manifest.ts +1 -0
- package/src/parsers/manifest/local/representation_index.ts +2 -2
- package/src/parsers/manifest/metaplaylist/metaplaylist_parser.ts +7 -1
- package/src/parsers/manifest/smooth/create_parser.ts +17 -13
- package/src/parsers/manifest/smooth/representation_index.ts +2 -2
- package/src/parsers/manifest/types.ts +26 -1
- package/src/parsers/manifest/utils/__tests__/get_first_time_from_adaptations.test.ts +15 -0
- package/src/parsers/manifest/utils/__tests__/get_last_time_from_adaptation.test.ts +15 -0
- package/src/parsers/texttracks/ttml/html/apply_extent.ts +8 -1
- package/src/parsers/texttracks/ttml/html/apply_origin.ts +9 -1
- package/src/parsers/texttracks/ttml/html/create_element.ts +2 -2
- package/src/transports/dash/construct_segment_url.ts +28 -0
- package/src/transports/dash/image_pipelines.ts +5 -2
- package/src/transports/dash/segment_loader.ts +5 -2
- package/src/transports/dash/text_loader.ts +5 -2
- package/src/transports/dash/text_parser.ts +3 -1
- package/src/transports/local/segment_loader.ts +3 -2
- package/src/transports/metaplaylist/pipelines.ts +28 -9
- package/src/transports/smooth/pipelines.ts +12 -6
- package/src/transports/smooth/utils.ts +13 -1
- package/src/transports/types.ts +6 -3
- package/src/utils/__tests__/event_emitter.test.ts +72 -67
- package/src/utils/__tests__/initialization_segment_cache.test.ts +7 -7
- package/src/utils/__tests__/resolve_url.test.ts +27 -23
- package/src/utils/event_emitter.ts +1 -3
- package/src/utils/resolve_url.ts +11 -8
- package/dist/_esm5.processed/core/fetchers/utils/try_urls_with_backoff.d.ts +0 -85
- package/dist/_esm5.processed/core/fetchers/utils/try_urls_with_backoff.js +0 -264
- package/dummy +0 -1
- package/src/core/fetchers/utils/try_urls_with_backoff.ts +0 -287
|
@@ -19,6 +19,7 @@ import { ISegmentParserParsedInitChunk, ISegmentParserParsedMediaChunk, ISegment
|
|
|
19
19
|
import { CancellationSignal } from "../../../utils/task_canceller";
|
|
20
20
|
import { IMetricsCallbackPayload, IRequestBeginCallbackPayload, IRequestEndCallbackPayload, IRequestProgressCallbackPayload } from "../../adaptive";
|
|
21
21
|
import { IBufferType } from "../../segment_buffers";
|
|
22
|
+
import CdnPrioritizer from "../cdn_prioritizer";
|
|
22
23
|
/**
|
|
23
24
|
* Create an `ISegmentFetcher` object which will allow to easily fetch and parse
|
|
24
25
|
* segments.
|
|
@@ -31,7 +32,7 @@ import { IBufferType } from "../../segment_buffers";
|
|
|
31
32
|
* @param {Object} options
|
|
32
33
|
* @returns {Function}
|
|
33
34
|
*/
|
|
34
|
-
export default function createSegmentFetcher<TLoadedFormat, TSegmentDataType>(bufferType: IBufferType, pipeline: ISegmentPipeline<TLoadedFormat, TSegmentDataType>, lifecycleCallbacks: ISegmentFetcherLifecycleCallbacks, options: ISegmentFetcherOptions): ISegmentFetcher<TSegmentDataType>;
|
|
35
|
+
export default function createSegmentFetcher<TLoadedFormat, TSegmentDataType>(bufferType: IBufferType, pipeline: ISegmentPipeline<TLoadedFormat, TSegmentDataType>, cdnPrioritizer: CdnPrioritizer | null, lifecycleCallbacks: ISegmentFetcherLifecycleCallbacks, options: ISegmentFetcherOptions): ISegmentFetcher<TSegmentDataType>;
|
|
35
36
|
/**
|
|
36
37
|
* Defines the `ISegmentFetcher` function which allows to load a single segment.
|
|
37
38
|
*
|
|
@@ -60,7 +60,7 @@ import isNullOrUndefined from "../../../utils/is_null_or_undefined";
|
|
|
60
60
|
import objectAssign from "../../../utils/object_assign";
|
|
61
61
|
import { CancellationError, } from "../../../utils/task_canceller";
|
|
62
62
|
import errorSelector from "../utils/error_selector";
|
|
63
|
-
import {
|
|
63
|
+
import { scheduleRequestWithCdns } from "../utils/schedule_request";
|
|
64
64
|
/** Allows to generate a unique identifies for each request. */
|
|
65
65
|
var generateRequestID = idGenerator();
|
|
66
66
|
/**
|
|
@@ -75,7 +75,7 @@ var generateRequestID = idGenerator();
|
|
|
75
75
|
* @param {Object} options
|
|
76
76
|
* @returns {Function}
|
|
77
77
|
*/
|
|
78
|
-
export default function createSegmentFetcher(bufferType, pipeline, lifecycleCallbacks, options) {
|
|
78
|
+
export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritizer, lifecycleCallbacks, options) {
|
|
79
79
|
var requestOptions = {
|
|
80
80
|
timeout: options.requestTimeout < 0 ? undefined :
|
|
81
81
|
options.requestTimeout,
|
|
@@ -97,15 +97,15 @@ export default function createSegmentFetcher(bufferType, pipeline, lifecycleCall
|
|
|
97
97
|
* @returns {Promise}
|
|
98
98
|
*/
|
|
99
99
|
return function fetchSegment(content, fetcherCallbacks, cancellationSignal) {
|
|
100
|
-
var _a, _b
|
|
100
|
+
var _a, _b;
|
|
101
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
102
|
/**
|
|
103
103
|
* Call a segment loader for the given URL with the right arguments.
|
|
104
|
-
* @param {
|
|
104
|
+
* @param {Object|null} cdnMetadata
|
|
105
105
|
* @returns {Promise}
|
|
106
106
|
*/
|
|
107
|
-
function callLoaderWithUrl(
|
|
108
|
-
return loadSegment(
|
|
107
|
+
function callLoaderWithUrl(cdnMetadata) {
|
|
108
|
+
return loadSegment(cdnMetadata, content, requestOptions, cancellationSignal, loaderCallbacks);
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
111
|
* Generate function allowing to parse a loaded segment.
|
|
@@ -168,11 +168,10 @@ export default function createSegmentFetcher(bufferType, pipeline, lifecycleCall
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
var
|
|
172
|
-
return __generator(this, function (
|
|
173
|
-
switch (
|
|
171
|
+
var segmentIdString, requestId, requestInfo, parsedChunks, segmentDurationAcc, metricsSent, loaderCallbacks, cached, res, loadedData, err_1;
|
|
172
|
+
return __generator(this, function (_c) {
|
|
173
|
+
switch (_c.label) {
|
|
174
174
|
case 0:
|
|
175
|
-
segment = content.segment;
|
|
176
175
|
segmentIdString = getLoggableSegmentId(content);
|
|
177
176
|
requestId = generateRequestID();
|
|
178
177
|
parsedChunks = [];
|
|
@@ -226,12 +225,12 @@ export default function createSegmentFetcher(bufferType, pipeline, lifecycleCall
|
|
|
226
225
|
requestInfo = null;
|
|
227
226
|
(_a = lifecycleCallbacks.onRequestEnd) === null || _a === void 0 ? void 0 : _a.call(lifecycleCallbacks, { id: requestId });
|
|
228
227
|
});
|
|
229
|
-
|
|
228
|
+
_c.label = 1;
|
|
230
229
|
case 1:
|
|
231
|
-
|
|
232
|
-
return [4 /*yield*/,
|
|
230
|
+
_c.trys.push([1, 3, , 4]);
|
|
231
|
+
return [4 /*yield*/, scheduleRequestWithCdns(content.representation.cdnMetadata, cdnPrioritizer, callLoaderWithUrl, objectAssign({ onRetry: onRetry }, options), cancellationSignal)];
|
|
233
232
|
case 2:
|
|
234
|
-
res =
|
|
233
|
+
res = _c.sent();
|
|
235
234
|
if (res.resultType === "segment-loaded") {
|
|
236
235
|
loadedData = res.resultData.responseData;
|
|
237
236
|
if (cache !== undefined) {
|
|
@@ -255,11 +254,11 @@ export default function createSegmentFetcher(bufferType, pipeline, lifecycleCall
|
|
|
255
254
|
// The current task could have been canceled as a result of one
|
|
256
255
|
// of the previous callbacks call. In that case, we don't want to send
|
|
257
256
|
// a "requestEnd" again as it has already been sent on cancellation.
|
|
258
|
-
(
|
|
257
|
+
(_b = lifecycleCallbacks.onRequestEnd) === null || _b === void 0 ? void 0 : _b.call(lifecycleCallbacks, { id: requestId });
|
|
259
258
|
}
|
|
260
259
|
return [3 /*break*/, 4];
|
|
261
260
|
case 3:
|
|
262
|
-
err_1 =
|
|
261
|
+
err_1 = _c.sent();
|
|
263
262
|
requestInfo = null;
|
|
264
263
|
if (err_1 instanceof CancellationError) {
|
|
265
264
|
log.debug("SF: Segment request aborted", segmentIdString);
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ITransportPipelines } from "../../../transports";
|
|
17
|
+
import { CancellationSignal } from "../../../utils/task_canceller";
|
|
17
18
|
import { IBufferType } from "../../segment_buffers";
|
|
18
19
|
import { IPrioritizedSegmentFetcher } from "./prioritized_segment_fetcher";
|
|
19
20
|
import { ISegmentFetcherLifecycleCallbacks } from "./segment_fetcher";
|
|
@@ -67,10 +68,11 @@ export default class SegmentFetcherCreator {
|
|
|
67
68
|
* segment retries (number of retries maximum, default delay and so on).
|
|
68
69
|
*/
|
|
69
70
|
private readonly _backoffOptions;
|
|
71
|
+
private readonly _cdnPrioritizer;
|
|
70
72
|
/**
|
|
71
73
|
* @param {Object} transport
|
|
72
74
|
*/
|
|
73
|
-
constructor(transport: ITransportPipelines, options: ISegmentFetcherCreatorBackoffOptions);
|
|
75
|
+
constructor(transport: ITransportPipelines, options: ISegmentFetcherCreatorBackoffOptions, cancelSignal: CancellationSignal);
|
|
74
76
|
/**
|
|
75
77
|
* Create a segment fetcher, allowing to easily perform segment requests.
|
|
76
78
|
* @param {string} bufferType - The type of buffer concerned (e.g. "audio",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import config from "../../../config";
|
|
17
|
+
import CdnPrioritizer from "../cdn_prioritizer";
|
|
17
18
|
import applyPrioritizerToSegmentFetcher from "./prioritized_segment_fetcher";
|
|
18
19
|
import createSegmentFetcher, { getSegmentFetcherOptions, } from "./segment_fetcher";
|
|
19
20
|
import TaskPrioritizer from "./task_prioritizer";
|
|
@@ -51,13 +52,15 @@ var SegmentFetcherCreator = /** @class */ (function () {
|
|
|
51
52
|
/**
|
|
52
53
|
* @param {Object} transport
|
|
53
54
|
*/
|
|
54
|
-
function SegmentFetcherCreator(transport, options) {
|
|
55
|
+
function SegmentFetcherCreator(transport, options, cancelSignal) {
|
|
56
|
+
var cdnPrioritizer = new CdnPrioritizer(cancelSignal);
|
|
55
57
|
var _a = config.getCurrent(), MIN_CANCELABLE_PRIORITY = _a.MIN_CANCELABLE_PRIORITY, MAX_HIGH_PRIORITY_LEVEL = _a.MAX_HIGH_PRIORITY_LEVEL;
|
|
56
58
|
this._transport = transport;
|
|
57
59
|
this._prioritizer = new TaskPrioritizer({
|
|
58
60
|
prioritySteps: { high: MAX_HIGH_PRIORITY_LEVEL,
|
|
59
61
|
low: MIN_CANCELABLE_PRIORITY },
|
|
60
62
|
});
|
|
63
|
+
this._cdnPrioritizer = cdnPrioritizer;
|
|
61
64
|
this._backoffOptions = options;
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
@@ -71,7 +74,7 @@ var SegmentFetcherCreator = /** @class */ (function () {
|
|
|
71
74
|
var backoffOptions = getSegmentFetcherOptions(bufferType, this._backoffOptions);
|
|
72
75
|
var pipelines = this._transport[bufferType];
|
|
73
76
|
// Types are very complicated here as they are per-type of buffer.
|
|
74
|
-
var segmentFetcher = createSegmentFetcher(bufferType, pipelines, callbacks, backoffOptions);
|
|
77
|
+
var segmentFetcher = createSegmentFetcher(bufferType, pipelines, this._cdnPrioritizer, callbacks, backoffOptions);
|
|
75
78
|
return applyPrioritizerToSegmentFetcher(this._prioritizer, segmentFetcher);
|
|
76
79
|
};
|
|
77
80
|
return SegmentFetcherCreator;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2015 CANAL+ Group
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { ICdnMetadata } from "../../../parsers/manifest";
|
|
17
|
+
import { CancellationSignal } from "../../../utils/task_canceller";
|
|
18
|
+
import CdnPrioritizer from "../cdn_prioritizer";
|
|
19
|
+
/** Settings to give to the backoff functions to configure their behavior. */
|
|
20
|
+
export interface IBackoffSettings {
|
|
21
|
+
/**
|
|
22
|
+
* Initial delay to wait if a request fails before making a new request, in
|
|
23
|
+
* milliseconds.
|
|
24
|
+
*/
|
|
25
|
+
baseDelay: number;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum delay to wait if a request fails before making a new request, in
|
|
28
|
+
* milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
maxDelay: number;
|
|
31
|
+
/**
|
|
32
|
+
* Maximum number of retries to perform on "regular" errors (e.g. due to HTTP
|
|
33
|
+
* status, integrity errors, timeouts...).
|
|
34
|
+
*/
|
|
35
|
+
maxRetryRegular: number;
|
|
36
|
+
/**
|
|
37
|
+
* Maximum number of retries to perform when it appears that the user is
|
|
38
|
+
* currently offline.
|
|
39
|
+
*/
|
|
40
|
+
maxRetryOffline: number;
|
|
41
|
+
/** Callback called when a request is retried. */
|
|
42
|
+
onRetry: (err: unknown) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Specific algorithm used to perform segment and manifest requests.
|
|
46
|
+
*
|
|
47
|
+
* Here how it works:
|
|
48
|
+
*
|
|
49
|
+
* 1. You give it one or multiple of the CDN available for the resource you
|
|
50
|
+
* want to request (from the most important one to the least important),
|
|
51
|
+
* a callback doing the request with the chosen CDN in argument, and some
|
|
52
|
+
* options.
|
|
53
|
+
*
|
|
54
|
+
* 2. it tries to call the request callback with the most prioritized CDN
|
|
55
|
+
* first:
|
|
56
|
+
* - if it works as expected, it resolves the returned Promise with that
|
|
57
|
+
* request's response.
|
|
58
|
+
* - if it fails, it calls ther `onRetry` callback given with the
|
|
59
|
+
* corresponding error, un-prioritize that CDN and try with the new
|
|
60
|
+
* most prioritized CDN.
|
|
61
|
+
*
|
|
62
|
+
* Each CDN might be retried multiple times, depending on the nature of the
|
|
63
|
+
* error and the Configuration given.
|
|
64
|
+
*
|
|
65
|
+
* Multiple retries of the same CDN are done after a delay to avoid
|
|
66
|
+
* overwhelming it, this is what we call a "backoff". That delay raises
|
|
67
|
+
* exponentially as multiple consecutive errors are encountered on this
|
|
68
|
+
* CDN.
|
|
69
|
+
*
|
|
70
|
+
* @param {Array.<string>|null} cdns - The different CDN on which the
|
|
71
|
+
* wanted resource is available. `scheduleRequestWithCdns` will call the
|
|
72
|
+
* `performRequest` callback with the right element from that array if different
|
|
73
|
+
* from `null`.
|
|
74
|
+
*
|
|
75
|
+
* Can be set to `null` when that resource is not reachable through a CDN, in
|
|
76
|
+
* which case the `performRequest` callback may be called with `null`.
|
|
77
|
+
* @param {Object|null} cdnPrioritizer - Interface allowing to give the priority
|
|
78
|
+
* between multiple CDNs.
|
|
79
|
+
* @param {Function} performRequest - Callback implementing the request in
|
|
80
|
+
* itself. Resolving when the resource request succeed and rejecting with the
|
|
81
|
+
* corresponding error when the request failed.
|
|
82
|
+
* @param {Object} options - Configuration allowing to tweak the number on which
|
|
83
|
+
* the algorithm behind `scheduleRequestWithCdns` bases itself.
|
|
84
|
+
* @param {Object} cancellationSignal - CancellationSignal allowing to cancel
|
|
85
|
+
* the logic of `scheduleRequestWithCdns`.
|
|
86
|
+
* To trigger if the resource is not needed anymore.
|
|
87
|
+
* @returns {Promise} - Promise resolving, with the corresponding
|
|
88
|
+
* `performRequest`'s data, when the resource request succeed and rejecting in
|
|
89
|
+
* the following scenarios:
|
|
90
|
+
* - `scheduleRequestWithCdns` has been cancelled due to `cancellationSignal`
|
|
91
|
+
* being triggered. In that case a `CancellationError` is thrown.
|
|
92
|
+
*
|
|
93
|
+
* - The resource request(s) failed and will not be retried anymore.
|
|
94
|
+
*/
|
|
95
|
+
export declare function scheduleRequestWithCdns<T>(cdns: ICdnMetadata[] | null, cdnPrioritizer: CdnPrioritizer | null, performRequest: (cdn: ICdnMetadata | null, cancellationSignal: CancellationSignal) => Promise<T>, options: IBackoffSettings, cancellationSignal: CancellationSignal): Promise<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Lightweight version of the request algorithm, this time with only a simple
|
|
98
|
+
* Promise given.
|
|
99
|
+
* @param {Function} performRequest
|
|
100
|
+
* @param {Object} options
|
|
101
|
+
* @returns {Promise}
|
|
102
|
+
*/
|
|
103
|
+
export declare function scheduleRequestPromise<T>(performRequest: () => Promise<T>, options: IBackoffSettings, cancellationSignal: CancellationSignal): Promise<T>;
|