rx-player 4.0.0-dev.202402213 → 4.0.0-dev.2024022300
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/VERSION +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/commonjs/core/main/worker/worker_main.js +8 -9
- package/dist/commonjs/features/features_object.js +1 -1
- package/dist/commonjs/features/list/dash.js +2 -2
- package/dist/commonjs/features/types.d.ts +8 -3
- package/dist/commonjs/main_thread/api/public_api.js +2 -7
- package/dist/commonjs/multithread_types.d.ts +1 -1
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_elements.d.ts +4 -3
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_elements.js +11 -4
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_previous_timeline.d.ts +2 -1
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_previous_timeline.js +12 -3
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/find_first_common_start_time.d.ts +3 -2
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/find_first_common_start_time.js +22 -11
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/parse_s_element.d.ts +11 -2
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/parse_s_element.js +74 -3
- package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +2 -1
- package/dist/commonjs/parsers/manifest/dash/common/parse_periods.js +3 -1
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/index.d.ts +17 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/index.js +19 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/AdaptationSet.d.ts +24 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/AdaptationSet.js +400 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/BaseURL.d.ts +24 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/BaseURL.js +33 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/ContentComponent.d.ts +23 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/ContentComponent.js +70 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/ContentProtection.d.ts +22 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/ContentProtection.js +118 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/EventStream.d.ts +23 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/EventStream.js +154 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Initialization.d.ts +22 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Initialization.js +70 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/MPD.d.ts +23 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/MPD.js +221 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Period.d.ts +23 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Period.js +179 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Representation.d.ts +22 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/Representation.js +256 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentBase.d.ts +23 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentBase.js +152 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentList.d.ts +22 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentList.js +60 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTemplate.d.ts +24 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTemplate.js +125 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTimeline.d.ts +22 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTimeline.js +36 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentURL.d.ts +24 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentURL.js +82 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/utils.d.ts +176 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/node_parsers/utils.js +382 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/parse_from_xml_string.d.ts +24 -0
- package/dist/commonjs/parsers/manifest/dash/fast-js-parser/parse_from_xml_string.js +142 -0
- package/dist/commonjs/parsers/manifest/dash/node_parser_types.d.ts +5 -3
- package/dist/commonjs/public_types.d.ts +1 -1
- package/dist/commonjs/transports/dash/manifest_parser.js +33 -4
- package/dist/commonjs/utils/xml-parser.d.ts +70 -0
- package/dist/commonjs/utils/xml-parser.js +357 -0
- package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
- package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
- package/dist/es2017/core/main/worker/worker_main.js +8 -9
- package/dist/es2017/features/features_object.js +1 -1
- package/dist/es2017/features/list/dash.js +2 -2
- package/dist/es2017/features/types.d.ts +8 -3
- package/dist/es2017/main_thread/api/public_api.js +2 -7
- package/dist/es2017/multithread_types.d.ts +1 -1
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_elements.d.ts +4 -3
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_elements.js +12 -5
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_previous_timeline.d.ts +2 -1
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/construct_timeline_from_previous_timeline.js +13 -4
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/find_first_common_start_time.d.ts +3 -2
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/find_first_common_start_time.js +22 -11
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/parse_s_element.d.ts +11 -2
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/parse_s_element.js +49 -2
- package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +2 -1
- package/dist/es2017/parsers/manifest/dash/common/parse_periods.js +3 -1
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/index.d.ts +17 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/index.js +17 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/AdaptationSet.d.ts +24 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/AdaptationSet.js +358 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/BaseURL.d.ts +24 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/BaseURL.js +30 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/ContentComponent.d.ts +23 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/ContentComponent.js +45 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/ContentProtection.d.ts +22 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/ContentProtection.js +77 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/EventStream.d.ts +23 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/EventStream.js +101 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Initialization.d.ts +22 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Initialization.js +45 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/MPD.d.ts +23 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/MPD.js +179 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Period.d.ts +23 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Period.js +137 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Representation.d.ts +22 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/Representation.js +214 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentBase.d.ts +23 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentBase.js +111 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentList.d.ts +22 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentList.js +41 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTemplate.d.ts +24 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTemplate.js +84 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTimeline.d.ts +22 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentTimeline.js +33 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentURL.d.ts +24 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/SegmentURL.js +57 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/utils.d.ts +176 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/node_parsers/utils.js +310 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/parse_from_xml_string.d.ts +24 -0
- package/dist/es2017/parsers/manifest/dash/fast-js-parser/parse_from_xml_string.js +114 -0
- package/dist/es2017/parsers/manifest/dash/node_parser_types.d.ts +5 -3
- package/dist/es2017/public_types.d.ts +1 -1
- package/dist/es2017/transports/dash/manifest_parser.js +33 -4
- package/dist/es2017/utils/xml-parser.d.ts +70 -0
- package/dist/es2017/utils/xml-parser.js +322 -0
- package/dist/mpd-parser.wasm +0 -0
- package/dist/rx-player.js +141 -65
- package/dist/rx-player.min.js +1 -1
- package/dist/worker.js +8 -3
- package/package.json +1 -1
- package/.vscode/settings.json +0 -9
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/index.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/index.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/AdaptationSet.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/AdaptationSet.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/BaseURL.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/BaseURL.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentComponent.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentComponent.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentProtection.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentProtection.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/EventStream.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/EventStream.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Initialization.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Initialization.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/MPD.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/MPD.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Period.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Period.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Representation.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Representation.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentBase.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentBase.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentList.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentList.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTemplate.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTemplate.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTimeline.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTimeline.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentURL.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentURL.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/utils.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/utils.js +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/parse_from_document.d.ts +0 -0
- /package/dist/commonjs/parsers/manifest/dash/{js-parser → native-parser}/parse_from_document.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/index.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/index.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/AdaptationSet.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/AdaptationSet.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/BaseURL.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/BaseURL.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentComponent.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentComponent.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentProtection.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/ContentProtection.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/EventStream.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/EventStream.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Initialization.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Initialization.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/MPD.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/MPD.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Period.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Period.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Representation.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/Representation.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentBase.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentBase.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentList.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentList.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTemplate.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTemplate.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTimeline.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentTimeline.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentURL.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/SegmentURL.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/utils.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/node_parsers/utils.js +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/parse_from_document.d.ts +0 -0
- /package/dist/es2017/parsers/manifest/dash/{js-parser → native-parser}/parse_from_document.js +0 -0
|
@@ -84,12 +84,19 @@ export default function generateManifestParser(options) {
|
|
|
84
84
|
* @returns {Object|Promise.<Object>}
|
|
85
85
|
*/
|
|
86
86
|
function runDefaultJsParser() {
|
|
87
|
-
if (parsers.
|
|
87
|
+
if (parsers.fastJs !== null) {
|
|
88
|
+
const manifestStr = getManifestAsString(responseData);
|
|
89
|
+
const parsedManifest = parsers.fastJs(manifestStr, dashParserOpts);
|
|
90
|
+
return processMpdParserResponse(parsedManifest);
|
|
91
|
+
}
|
|
92
|
+
else if (parsers.native !== null) {
|
|
93
|
+
const manifestDocument = getManifestAsDocument(responseData);
|
|
94
|
+
const parsedManifest = parsers.native(manifestDocument, dashParserOpts);
|
|
95
|
+
return processMpdParserResponse(parsedManifest);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
88
98
|
throw new Error("No MPD parser is imported");
|
|
89
99
|
}
|
|
90
|
-
const manifestDoc = getManifestAsDocument(responseData);
|
|
91
|
-
const parsedManifest = parsers.js(manifestDoc, dashParserOpts);
|
|
92
|
-
return processMpdParserResponse(parsedManifest);
|
|
93
100
|
}
|
|
94
101
|
/**
|
|
95
102
|
* Process return of one of the MPD parser.
|
|
@@ -226,6 +233,28 @@ function assertLoadedResourcesFormatArrayBuffer(loadedResources) {
|
|
|
226
233
|
throw new Error("Invalid data given to the LoadedRessource");
|
|
227
234
|
});
|
|
228
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Try to convert a Manifest from an unknown format to an array of nodes as
|
|
238
|
+
* parsed by our XML DOM parser.
|
|
239
|
+
*
|
|
240
|
+
* Throws if the format cannot be converted.
|
|
241
|
+
* @param {*} manifestSrc
|
|
242
|
+
* @returns {Array.<Object | string>}
|
|
243
|
+
*/
|
|
244
|
+
function getManifestAsString(manifestSrc) {
|
|
245
|
+
if (manifestSrc instanceof ArrayBuffer) {
|
|
246
|
+
return utf8ToStr(new Uint8Array(manifestSrc));
|
|
247
|
+
}
|
|
248
|
+
else if (typeof manifestSrc === "string") {
|
|
249
|
+
return manifestSrc;
|
|
250
|
+
}
|
|
251
|
+
else if (manifestSrc instanceof Document) {
|
|
252
|
+
return manifestSrc.documentElement.outerHTML;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
throw new Error("DASH Manifest Parser: Unrecognized Manifest format");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
229
258
|
/**
|
|
230
259
|
* Try to convert a Manifest from an unknown format to a `Document` format.
|
|
231
260
|
* Useful to exploit DOM-parsing APIs to quickly parse an XML Manifest.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is mainly a modified version of the tXml library.
|
|
3
|
+
*
|
|
4
|
+
* @author: Tobias Nickel
|
|
5
|
+
* created: 06.04.2015
|
|
6
|
+
* https://github.com/TobiasNickel/tXml
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 Tobias Nickel
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
export interface ITNode {
|
|
32
|
+
tagName: string;
|
|
33
|
+
attributes: Partial<Record<string, string | null>>;
|
|
34
|
+
children: Array<ITNode | string>;
|
|
35
|
+
posStart: number;
|
|
36
|
+
posEnd: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ITParseOptions {
|
|
39
|
+
pos?: number;
|
|
40
|
+
noChildNodes?: string[];
|
|
41
|
+
keepComments?: boolean;
|
|
42
|
+
keepWhitespace?: boolean;
|
|
43
|
+
simplify?: boolean;
|
|
44
|
+
filter?: (a: ITNode, i: number) => boolean;
|
|
45
|
+
attrName?: string;
|
|
46
|
+
attrValue?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* parseXML / html into a DOM Object. with no validation and some failur tolerance
|
|
50
|
+
* @param {string} src - Your XML to parse
|
|
51
|
+
* @param {Object} [options = {}] - all other options:
|
|
52
|
+
* @return {Array.<Object | string>}
|
|
53
|
+
*/
|
|
54
|
+
declare function parseXml(src: string, options?: ITParseOptions): Array<ITNode | string>;
|
|
55
|
+
/**
|
|
56
|
+
* behaves the same way as Array.filter, if the filter method return true, the element is in the resultList
|
|
57
|
+
* @params {Array} children - the children of a node
|
|
58
|
+
* @param {function} f - the filter method
|
|
59
|
+
*/
|
|
60
|
+
declare function filter(children: Array<ITNode | string>, f: (a: ITNode, i: number, dept: number, path: string) => boolean, dept?: number, path?: string): Array<ITNode | string>;
|
|
61
|
+
/**
|
|
62
|
+
* use this method to read the text content, of some node.
|
|
63
|
+
* It is great if you have mixed content like:
|
|
64
|
+
* this text has some <b>big</b> text and a <a href=''>link</a>
|
|
65
|
+
* @return {string}
|
|
66
|
+
*/
|
|
67
|
+
declare function toContentString(tDom: ITNode | string | Array<ITNode | string>): string;
|
|
68
|
+
declare function getElementById(src: string, id: string): ITNode | string | undefined;
|
|
69
|
+
declare function getElementsByClassName(src: string, classname: string): Array<ITNode | string>;
|
|
70
|
+
export { filter, getElementById, getElementsByClassName, parseXml, toContentString };
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is mainly a modified version of the tXml library.
|
|
3
|
+
*
|
|
4
|
+
* @author: Tobias Nickel
|
|
5
|
+
* created: 06.04.2015
|
|
6
|
+
* https://github.com/TobiasNickel/tXml
|
|
7
|
+
*/
|
|
8
|
+
const openBracket = "<";
|
|
9
|
+
const openBracketCC = "<".charCodeAt(0);
|
|
10
|
+
const closeBracket = ">";
|
|
11
|
+
const closeBracketCC = ">".charCodeAt(0);
|
|
12
|
+
const minusCC = "-".charCodeAt(0);
|
|
13
|
+
const slashCC = "/".charCodeAt(0);
|
|
14
|
+
const exclamationCC = "!".charCodeAt(0);
|
|
15
|
+
const singleQuoteCC = "'".charCodeAt(0);
|
|
16
|
+
const doubleQuoteCC = '"'.charCodeAt(0);
|
|
17
|
+
const openCornerBracketCC = "[".charCodeAt(0);
|
|
18
|
+
const closeCornerBracketCC = "]".charCodeAt(0);
|
|
19
|
+
/** Character marking end of attribute and node name. */
|
|
20
|
+
const nameSpacer = "\r\n\t>/= ";
|
|
21
|
+
/**
|
|
22
|
+
* parseXML / html into a DOM Object. with no validation and some failur tolerance
|
|
23
|
+
* @param {string} src - Your XML to parse
|
|
24
|
+
* @param {Object} [options = {}] - all other options:
|
|
25
|
+
* @return {Array.<Object | string>}
|
|
26
|
+
*/
|
|
27
|
+
function parseXml(src, options = {}) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
let pos = (_a = options.pos) !== null && _a !== void 0 ? _a : 0;
|
|
30
|
+
const keepComments = options.keepComments === true;
|
|
31
|
+
const keepWhitespace = options.keepWhitespace === true;
|
|
32
|
+
let out;
|
|
33
|
+
if (options.attrValue !== undefined) {
|
|
34
|
+
options.attrName = (_b = options.attrName) !== null && _b !== void 0 ? _b : "id";
|
|
35
|
+
out = [];
|
|
36
|
+
while ((pos = findElements()) !== -1) {
|
|
37
|
+
pos = src.lastIndexOf("<", pos);
|
|
38
|
+
if (pos !== -1) {
|
|
39
|
+
out.push(parseNode());
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
42
|
+
src = src.substring(pos);
|
|
43
|
+
pos = 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
out = parseChildren("");
|
|
48
|
+
}
|
|
49
|
+
if (options.filter) {
|
|
50
|
+
out = filter(out, options.filter);
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
/**
|
|
54
|
+
* parsing a list of entries
|
|
55
|
+
* @param {string} tagName
|
|
56
|
+
* @returns {Array.<ITNode | string>}
|
|
57
|
+
*/
|
|
58
|
+
function parseChildren(tagName) {
|
|
59
|
+
const children = [];
|
|
60
|
+
while (src[pos]) {
|
|
61
|
+
if (src.charCodeAt(pos) === openBracketCC) {
|
|
62
|
+
if (src.charCodeAt(pos + 1) === slashCC) {
|
|
63
|
+
const closeStart = pos + 2;
|
|
64
|
+
pos = src.indexOf(closeBracket, pos);
|
|
65
|
+
const closeTag = src.substring(closeStart, pos);
|
|
66
|
+
if (closeTag.indexOf(tagName) === -1) {
|
|
67
|
+
const parsedText = src.substring(0, pos).split("\n");
|
|
68
|
+
throw new Error("Unexpected close tag\nLine: " +
|
|
69
|
+
(parsedText.length - 1) +
|
|
70
|
+
"\nColumn: " +
|
|
71
|
+
(parsedText[parsedText.length - 1].length + 1) +
|
|
72
|
+
"\nChar: " +
|
|
73
|
+
src[pos]);
|
|
74
|
+
}
|
|
75
|
+
if (pos !== -1) {
|
|
76
|
+
pos += 1;
|
|
77
|
+
}
|
|
78
|
+
return children;
|
|
79
|
+
}
|
|
80
|
+
else if (src.charCodeAt(pos + 1) === exclamationCC) {
|
|
81
|
+
if (src.charCodeAt(pos + 2) === minusCC) {
|
|
82
|
+
// comment support
|
|
83
|
+
const startCommentPos = pos;
|
|
84
|
+
while (pos !== -1 &&
|
|
85
|
+
!(src.charCodeAt(pos) === closeBracketCC &&
|
|
86
|
+
src.charCodeAt(pos - 1) === minusCC &&
|
|
87
|
+
src.charCodeAt(pos - 2) === minusCC)) {
|
|
88
|
+
pos = src.indexOf(closeBracket, pos + 1);
|
|
89
|
+
}
|
|
90
|
+
if (pos === -1) {
|
|
91
|
+
pos = src.length;
|
|
92
|
+
}
|
|
93
|
+
if (keepComments) {
|
|
94
|
+
children.push(src.substring(startCommentPos, pos + 1));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (src.charCodeAt(pos + 2) === openCornerBracketCC &&
|
|
98
|
+
src.charCodeAt(pos + 8) === openCornerBracketCC &&
|
|
99
|
+
src.substring(pos + 3, pos + 8).toLowerCase() === "cdata") {
|
|
100
|
+
// cdata
|
|
101
|
+
const cdataEndIndex = src.indexOf("]]>", pos);
|
|
102
|
+
if (cdataEndIndex === -1) {
|
|
103
|
+
children.push(src.substring(pos + 9));
|
|
104
|
+
pos = src.length;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
children.push(src.substring(pos + 9, cdataEndIndex));
|
|
108
|
+
pos = cdataEndIndex + 3;
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// doctypesupport
|
|
114
|
+
const startDoctype = pos + 1;
|
|
115
|
+
pos += 2;
|
|
116
|
+
let encapsuled = false;
|
|
117
|
+
while ((src.charCodeAt(pos) !== closeBracketCC || encapsuled) && src[pos]) {
|
|
118
|
+
if (src.charCodeAt(pos) === openCornerBracketCC) {
|
|
119
|
+
encapsuled = true;
|
|
120
|
+
}
|
|
121
|
+
else if (encapsuled && src.charCodeAt(pos) === closeCornerBracketCC) {
|
|
122
|
+
encapsuled = false;
|
|
123
|
+
}
|
|
124
|
+
pos++;
|
|
125
|
+
}
|
|
126
|
+
children.push(src.substring(startDoctype, pos));
|
|
127
|
+
}
|
|
128
|
+
pos++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const node = parseNode();
|
|
132
|
+
children.push(node);
|
|
133
|
+
if (node.tagName[0] === "?") {
|
|
134
|
+
children.push(...node.children);
|
|
135
|
+
node.children = [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const text = parseText();
|
|
140
|
+
if (keepWhitespace) {
|
|
141
|
+
if (text.length > 0) {
|
|
142
|
+
children.push(text);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const trimmed = text.trim();
|
|
147
|
+
if (trimmed.length > 0) {
|
|
148
|
+
children.push(trimmed);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
pos++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return children;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* returns the text outside of texts until the first '<'
|
|
158
|
+
*/
|
|
159
|
+
function parseText() {
|
|
160
|
+
const start = pos;
|
|
161
|
+
pos = src.indexOf(openBracket, pos) - 1;
|
|
162
|
+
if (pos === -2) {
|
|
163
|
+
pos = src.length;
|
|
164
|
+
}
|
|
165
|
+
return src.slice(start, pos + 1);
|
|
166
|
+
}
|
|
167
|
+
function parseName() {
|
|
168
|
+
const start = pos;
|
|
169
|
+
while (nameSpacer.indexOf(src[pos]) === -1 && src[pos]) {
|
|
170
|
+
pos++;
|
|
171
|
+
}
|
|
172
|
+
return src.slice(start, pos);
|
|
173
|
+
}
|
|
174
|
+
function parseNode() {
|
|
175
|
+
const posStart = pos;
|
|
176
|
+
pos++;
|
|
177
|
+
const tagName = parseName();
|
|
178
|
+
const attributes = {};
|
|
179
|
+
let children = [];
|
|
180
|
+
// parsing attributes
|
|
181
|
+
while (src.charCodeAt(pos) !== closeBracketCC && src[pos]) {
|
|
182
|
+
const c = src.charCodeAt(pos);
|
|
183
|
+
if ((c > 64 && c < 91) || (c > 96 && c < 123)) {
|
|
184
|
+
// if('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.indexOf(src[pos])!==-1 ){
|
|
185
|
+
const name = parseName();
|
|
186
|
+
// search beginning of the string
|
|
187
|
+
let code = src.charCodeAt(pos);
|
|
188
|
+
while (code &&
|
|
189
|
+
code !== singleQuoteCC &&
|
|
190
|
+
code !== doubleQuoteCC &&
|
|
191
|
+
!((code > 64 && code < 91) || (code > 96 && code < 123)) &&
|
|
192
|
+
code !== closeBracketCC) {
|
|
193
|
+
pos++;
|
|
194
|
+
code = src.charCodeAt(pos);
|
|
195
|
+
}
|
|
196
|
+
let value;
|
|
197
|
+
if (code === singleQuoteCC || code === doubleQuoteCC) {
|
|
198
|
+
value = parseString();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
value = null;
|
|
202
|
+
pos--;
|
|
203
|
+
}
|
|
204
|
+
attributes[name] = value === null ? null : translateEntities(value);
|
|
205
|
+
}
|
|
206
|
+
pos++;
|
|
207
|
+
}
|
|
208
|
+
// optional parsing of children
|
|
209
|
+
if (src.charCodeAt(pos - 1) !== slashCC) {
|
|
210
|
+
pos++;
|
|
211
|
+
children = parseChildren(tagName);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
pos++;
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
tagName,
|
|
218
|
+
attributes,
|
|
219
|
+
children,
|
|
220
|
+
posStart,
|
|
221
|
+
posEnd: pos,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Parses a string, that starts with a char and with the same usually ' or "
|
|
226
|
+
* character starting at `pos`.
|
|
227
|
+
* @returns {string}
|
|
228
|
+
*/
|
|
229
|
+
function parseString() {
|
|
230
|
+
const startChar = src[pos];
|
|
231
|
+
const startpos = pos + 1;
|
|
232
|
+
pos = src.indexOf(startChar, startpos);
|
|
233
|
+
return src.slice(startpos, pos);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
*/
|
|
238
|
+
function findElements() {
|
|
239
|
+
const r = new RegExp("\\s" + options.attrName + "\\s*=['\"]" + options.attrValue + "['\"]").exec(src);
|
|
240
|
+
if (r) {
|
|
241
|
+
return r.index;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return -1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* behaves the same way as Array.filter, if the filter method return true, the element is in the resultList
|
|
250
|
+
* @params {Array} children - the children of a node
|
|
251
|
+
* @param {function} f - the filter method
|
|
252
|
+
*/
|
|
253
|
+
function filter(children, f, dept = 0, path = "") {
|
|
254
|
+
let out = [];
|
|
255
|
+
children.forEach(function (child, i) {
|
|
256
|
+
if (typeof child === "object") {
|
|
257
|
+
if (f(child, i, dept, path)) {
|
|
258
|
+
out.push(child);
|
|
259
|
+
}
|
|
260
|
+
if (child.children.length > 0) {
|
|
261
|
+
const kids = filter(child.children, f, dept + 1, (path ? path + "." : "") + i + "." + child.tagName);
|
|
262
|
+
out = out.concat(kids);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* use this method to read the text content, of some node.
|
|
270
|
+
* It is great if you have mixed content like:
|
|
271
|
+
* this text has some <b>big</b> text and a <a href=''>link</a>
|
|
272
|
+
* @return {string}
|
|
273
|
+
*/
|
|
274
|
+
function toContentString(tDom) {
|
|
275
|
+
if (Array.isArray(tDom)) {
|
|
276
|
+
let out = "";
|
|
277
|
+
tDom.forEach(function (e) {
|
|
278
|
+
out += " " + toContentString(e);
|
|
279
|
+
out = out.trim();
|
|
280
|
+
});
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
else if (typeof tDom === "object") {
|
|
284
|
+
return toContentString(tDom.children);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
return " " + translateEntities(tDom);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} str
|
|
292
|
+
* @returns {string}
|
|
293
|
+
*/
|
|
294
|
+
function translateEntities(str) {
|
|
295
|
+
if (str.indexOf("&") < 0) {
|
|
296
|
+
// Fast path for when there's no entity
|
|
297
|
+
return str;
|
|
298
|
+
}
|
|
299
|
+
return str
|
|
300
|
+
.replace(/</g, "<")
|
|
301
|
+
.replace(/>/g, ">")
|
|
302
|
+
.replace(/"/g, '"')
|
|
303
|
+
.replace(/'/g, "'")
|
|
304
|
+
.replace(/&#x([A-Fa-f0-9]+);/g, (_, code) => {
|
|
305
|
+
return String.fromCharCode(parseInt(code, 16));
|
|
306
|
+
})
|
|
307
|
+
.replace(/&/g, "&");
|
|
308
|
+
}
|
|
309
|
+
function getElementById(src, id) {
|
|
310
|
+
const out = parseXml(src, {
|
|
311
|
+
attrValue: id,
|
|
312
|
+
});
|
|
313
|
+
return out[0];
|
|
314
|
+
}
|
|
315
|
+
function getElementsByClassName(src, classname) {
|
|
316
|
+
const out = parseXml(src, {
|
|
317
|
+
attrName: "class",
|
|
318
|
+
attrValue: "[a-zA-Z0-9- ]*" + classname + "[a-zA-Z0-9- ]*",
|
|
319
|
+
});
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
322
|
+
export { filter, getElementById, getElementsByClassName, parseXml, toContentString };
|
package/dist/mpd-parser.wasm
CHANGED
|
Binary file
|