rx-player 4.0.0-beta.1 → 4.0.0-beta.2

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 (169) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/CONTRIBUTING.md +48 -168
  3. package/FILES.md +40 -92
  4. package/VERSION +1 -1
  5. package/dist/_esm5.processed/compat/browser_detection.d.ts +3 -1
  6. package/dist/_esm5.processed/compat/browser_detection.js +7 -2
  7. package/dist/_esm5.processed/compat/eme/load_session.js +1 -1
  8. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.d.ts +21 -0
  9. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.js +26 -0
  10. package/dist/_esm5.processed/config.d.ts +2 -0
  11. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +5 -4
  12. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.d.ts +18 -1
  13. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.js +106 -25
  14. package/dist/_esm5.processed/core/adaptive/guess_based_chooser.js +6 -6
  15. package/dist/_esm5.processed/core/adaptive/network_analyzer.js +8 -5
  16. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.d.ts +19 -1
  17. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.js +1 -1
  18. package/dist/_esm5.processed/core/api/debug/render.js +1 -1
  19. package/dist/_esm5.processed/core/api/playback_observer.js +1 -0
  20. package/dist/_esm5.processed/core/api/public_api.d.ts +54 -1
  21. package/dist/_esm5.processed/core/api/public_api.js +232 -35
  22. package/dist/_esm5.processed/core/api/track_management/media_element_tracks_store.js +10 -1
  23. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +13 -1
  24. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +30 -15
  25. package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +3 -1
  26. package/dist/_esm5.processed/core/api/track_management/tracks_store.js +67 -152
  27. package/dist/_esm5.processed/core/api/utils.d.ts +10 -0
  28. package/dist/_esm5.processed/core/api/utils.js +20 -0
  29. package/dist/_esm5.processed/core/decrypt/session_events_listener.js +7 -1
  30. package/dist/_esm5.processed/core/decrypt/utils/clean_old_loaded_sessions.js +2 -0
  31. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +5 -1
  32. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +1 -1
  33. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +47 -10
  34. package/dist/_esm5.processed/core/init/types.d.ts +9 -1
  35. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.d.ts +28 -1
  36. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.js +22 -9
  37. package/dist/_esm5.processed/core/init/utils/media_source_duration_updater.d.ts +58 -0
  38. package/dist/_esm5.processed/core/init/utils/{media_duration_updater.js → media_source_duration_updater.js} +84 -87
  39. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +36 -2
  40. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +82 -2
  41. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.d.ts +18 -7
  42. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +31 -40
  43. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.d.ts +8 -0
  44. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +12 -0
  45. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +8 -0
  46. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +12 -0
  47. package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +11 -4
  48. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  49. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.d.ts +47 -0
  50. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.js +70 -0
  51. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +15 -8
  52. package/dist/_esm5.processed/core/stream/period/period_stream.js +1 -1
  53. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +22 -13
  54. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.d.ts +4 -2
  55. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.js +2 -2
  56. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.d.ts +3 -2
  57. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.js +8 -8
  58. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.d.ts +2 -2
  59. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.js +2 -3
  60. package/dist/_esm5.processed/default_config.d.ts +25 -0
  61. package/dist/_esm5.processed/default_config.js +27 -2
  62. package/dist/_esm5.processed/errors/index.d.ts +2 -2
  63. package/dist/_esm5.processed/errors/media_error.d.ts +23 -1
  64. package/dist/_esm5.processed/errors/media_error.js +18 -5
  65. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.d.ts +1 -1
  66. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.js +8 -7
  67. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +17 -9
  68. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/index.js +0 -2
  69. package/dist/_esm5.processed/manifest/adaptation.d.ts +21 -2
  70. package/dist/_esm5.processed/manifest/adaptation.js +76 -1
  71. package/dist/_esm5.processed/manifest/manifest.js +1 -1
  72. package/dist/_esm5.processed/manifest/period.js +2 -2
  73. package/dist/_esm5.processed/manifest/representation.d.ts +33 -2
  74. package/dist/_esm5.processed/manifest/representation.js +21 -0
  75. package/dist/_esm5.processed/manifest/utils.js +1 -3
  76. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.d.ts +1 -1
  77. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.js +1 -1
  78. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.js +1 -0
  79. package/dist/_esm5.processed/public_types.d.ts +13 -3
  80. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +1 -1
  81. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.d.ts +4 -6
  82. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.js +4 -6
  83. package/dist/_esm5.processed/utils/is_null_or_undefined.d.ts +1 -1
  84. package/dist/_esm5.processed/utils/is_null_or_undefined.js +1 -1
  85. package/dist/mpd-parser.wasm +0 -0
  86. package/dist/rx-player.js +4709 -4218
  87. package/dist/rx-player.min.js +1 -1
  88. package/package.json +42 -36
  89. package/scripts/build/generate_build.js +1 -1
  90. package/scripts/fast_demo_build.js +4 -3
  91. package/scripts/generate_full_demo.js +1 -1
  92. package/sonar-project.properties +1 -1
  93. package/src/compat/browser_detection.ts +7 -1
  94. package/src/compat/eme/load_session.ts +1 -1
  95. package/src/compat/has_issues_with_high_media_source_duration.ts +27 -0
  96. package/src/core/adaptive/__tests__/buffer_based_chooser.test.ts +147 -48
  97. package/src/core/adaptive/adaptive_representation_selector.ts +7 -4
  98. package/src/core/adaptive/buffer_based_chooser.ts +144 -26
  99. package/src/core/adaptive/guess_based_chooser.ts +9 -8
  100. package/src/core/adaptive/network_analyzer.ts +9 -4
  101. package/src/core/adaptive/utils/representation_score_calculator.ts +22 -2
  102. package/src/core/api/debug/render.ts +1 -1
  103. package/src/core/api/playback_observer.ts +1 -0
  104. package/src/core/api/public_api.ts +277 -44
  105. package/src/core/api/track_management/media_element_tracks_store.ts +17 -8
  106. package/src/core/api/track_management/track_dispatcher.ts +37 -14
  107. package/src/core/api/track_management/tracks_store.ts +77 -167
  108. package/src/core/api/utils.ts +26 -0
  109. package/src/core/decrypt/session_events_listener.ts +6 -1
  110. package/src/core/decrypt/utils/clean_old_loaded_sessions.ts +2 -1
  111. package/src/core/decrypt/utils/loaded_sessions_store.ts +8 -1
  112. package/src/core/init/directfile_content_initializer.ts +1 -0
  113. package/src/core/init/media_source_content_initializer.ts +52 -9
  114. package/src/core/init/types.ts +9 -1
  115. package/src/core/init/utils/content_time_boundaries_observer.ts +46 -10
  116. package/src/core/init/utils/{media_duration_updater.ts → media_source_duration_updater.ts} +100 -112
  117. package/src/core/init/utils/rebuffering_controller.ts +114 -3
  118. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +56 -55
  119. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +16 -0
  120. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +16 -0
  121. package/src/core/segment_buffers/implementations/types.ts +16 -4
  122. package/src/core/segment_buffers/index.ts +2 -0
  123. package/src/core/stream/adaptation/utils/create_representation_estimator.ts +114 -0
  124. package/src/core/stream/orchestrator/stream_orchestrator.ts +16 -8
  125. package/src/core/stream/period/period_stream.ts +2 -1
  126. package/src/core/stream/representation/representation_stream.ts +34 -22
  127. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +8 -3
  128. package/src/core/stream/representation/utils/push_init_segment.ts +11 -6
  129. package/src/core/stream/representation/utils/push_media_segment.ts +3 -3
  130. package/src/default_config.ts +29 -2
  131. package/src/errors/__tests__/media_error.test.ts +6 -6
  132. package/src/errors/index.ts +4 -1
  133. package/src/errors/media_error.ts +67 -1
  134. package/src/experimental/tools/VideoThumbnailLoader/load_and_push_segment.ts +10 -7
  135. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +17 -6
  136. package/src/experimental/tools/mediaCapabilitiesProber/index.ts +0 -4
  137. package/src/manifest/__tests__/manifest.test.ts +7 -7
  138. package/src/manifest/__tests__/period.test.ts +90 -45
  139. package/src/manifest/adaptation.ts +89 -1
  140. package/src/manifest/manifest.ts +1 -1
  141. package/src/manifest/period.ts +4 -2
  142. package/src/manifest/representation.ts +67 -1
  143. package/src/manifest/utils.ts +1 -3
  144. package/src/parsers/manifest/dash/js-parser/parse_from_document.ts +1 -1
  145. package/src/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.ts +1 -0
  146. package/src/parsers/texttracks/ttml/parse_ttml.ts +1 -1
  147. package/src/public_types.ts +16 -1
  148. package/src/tools/TextTrackRenderer/text_track_renderer.ts +1 -1
  149. package/src/transports/smooth/isobmff/create_boxes.ts +4 -6
  150. package/src/typings/globals.d.ts +20 -20
  151. package/src/utils/is_null_or_undefined.ts +1 -1
  152. package/dist/_esm5.processed/core/init/utils/media_duration_updater.d.ts +0 -56
  153. package/scripts/doc-generator/construct_table_of_contents.js +0 -76
  154. package/scripts/doc-generator/convert_MD_to_HMTL.js +0 -26
  155. package/scripts/doc-generator/create_documentation.js +0 -331
  156. package/scripts/doc-generator/create_documentation_page.js +0 -209
  157. package/scripts/doc-generator/create_page.js +0 -210
  158. package/scripts/doc-generator/generate_header_html.js +0 -147
  159. package/scripts/doc-generator/generate_page_html.js +0 -115
  160. package/scripts/doc-generator/generate_page_list_html.js +0 -92
  161. package/scripts/doc-generator/generate_sidebar_html.js +0 -85
  162. package/scripts/doc-generator/get_search_data_for_content.js +0 -137
  163. package/scripts/doc-generator/index.js +0 -34
  164. package/scripts/doc-generator/parse_doc_configs.js +0 -327
  165. package/scripts/doc-generator/scripts/lunr.js +0 -10
  166. package/scripts/doc-generator/scripts/script.js +0 -451
  167. package/scripts/doc-generator/styles/code.css +0 -99
  168. package/scripts/doc-generator/styles/style.css +0 -835
  169. package/scripts/doc-generator/utils.js +0 -74
@@ -1,92 +0,0 @@
1
- const { encode } = require("html-entities");
2
- const path = require("path");
3
- const {
4
- getGithubSvg,
5
- toUriCompatibleRelativePath,
6
- } = require("./utils");
7
-
8
- /**
9
- * Construct exhaustive list of documentation links as an HTML string.
10
- * @param {Array.<Object>} links
11
- * @param {number} currentLinkIdx
12
- * @param {Array.<number>} currentPageIndexes
13
- * @param {string} currentPath
14
- * @returns {string}
15
- */
16
- function generatePageListHtml(
17
- links,
18
- currentLinkIdx,
19
- currentPageIndexes,
20
- currentPath
21
- ) {
22
- const currentDir = path.dirname(currentPath);
23
- const linksHtml = links.map((l, linkIdx) => {
24
- switch (l.type) {
25
- case "local-doc": {
26
- const isActiveCat = linkIdx === currentLinkIdx;
27
- const catActiveClasses = isActiveCat ? " opened active" : "";
28
-
29
- const catHtml = `<li class="page-list-item">` +
30
- `<div class="page-list-group${catActiveClasses}">` +
31
- encode(l.displayName) +
32
- `</div><ul class="page-list-cat-group">`;
33
-
34
- return catHtml + l.pages.map((currentPage, pageidx) => {
35
- const isPageActive = isActiveCat && pageidx === currentPageIndexes[0];
36
- const { displayName, outputFile } = currentPage;
37
- if (!currentPage.isPageGroup) {
38
- const pageActiveClasses = isPageActive ? " active" : "";
39
- const relativeUri = toUriCompatibleRelativePath(outputFile, currentDir);
40
- return `<li class="page-list-item${pageActiveClasses}">` +
41
- `<a href="${encode(relativeUri)}">` +
42
- encode(displayName) +
43
- `</a></li>`;
44
- }
45
- const pageActiveClasses = isPageActive ? " opened active" : "";
46
- const pageGroupHtml = `<li>` +
47
- `<div class="page-list-item page-list-group${pageActiveClasses}">` +
48
- encode(displayName) +
49
- `</div><ul class="page-list-group-group">`;
50
- return pageGroupHtml + currentPage.pages.map((currentSubPage, spIdx) => {
51
- const spActiveClasses = isPageActive && spIdx === currentPageIndexes[1] ?
52
- " active" : "";
53
- const { displayName, outputFile } = currentSubPage;
54
- const relativeUri = toUriCompatibleRelativePath(outputFile, currentDir);
55
- return `<li class="page-list-item${spActiveClasses}">` +
56
- `<a href="${encode(relativeUri)}">` +
57
- encode(displayName) +
58
- `</a></li>`;
59
- }).join("\n") + "</ul></li>";
60
- }).join("\n") + "</ul></li>";
61
- }
62
-
63
- case "external-link": {
64
- const cleanedHref = encode(l.link);
65
- return `<li class="page-list-item">` +
66
- `<a href="${cleanedHref}">` +
67
- encode(l.displayName) +
68
- "</a></li>";
69
- }
70
-
71
- case "github-link":
72
- const cleanedHref = encode(l.link);
73
- return `<li class="page-list-item">` +
74
- `<a aria-label="Link to repository" href="${cleanedHref}">` +
75
- getGithubSvg() +
76
- "</a></li>";
77
-
78
- case "search":
79
- return "";
80
-
81
- case "version":
82
- // TODO?
83
- return "";
84
- }
85
- }).join("\n");
86
-
87
- return `<ul class="page-list-wrapper">` +
88
- linksHtml +
89
- "</ul>";
90
- };
91
-
92
- module.exports = generatePageListHtml;
@@ -1,85 +0,0 @@
1
- const path = require("path");
2
- const { encode } = require("html-entities");
3
- const { toUriCompatibleRelativePath } = require("./utils");
4
-
5
- /**
6
- * Construct HTML element, as a string, which corresponds to the sidebar for
7
- * the chosen documentation page.
8
- * @param {Array.<Object>} pages
9
- * @param {Array.<number>} currentPageIndexes
10
- * @param {string} currentPath
11
- * @param {Object} logoInfo
12
- * @returns {string}
13
- */
14
- function generateSidebarHtml(
15
- pages,
16
- currentPageIndexes,
17
- currentPath,
18
- logoInfo
19
- ) {
20
- const sidebarHeaderHtml = constructSidebarHeaderHtml(logoInfo);
21
- const links = pages.map((p, i) => {
22
- const isActive = i === currentPageIndexes[0];
23
- if (!p.isPageGroup) {
24
- return generateLiForPage(p, isActive);
25
- } else {
26
- const lis = p.pages.map((sp, j) => {
27
- const isActiveSubPage = isActive && j === currentPageIndexes[1];
28
- return generateLiForPage(sp, isActiveSubPage);
29
- }).join("");
30
- return `<li class="sidebar-item">` +
31
- `<div class="sidebar-item sidebar-item-group${isActive ? " active opened" : ""}">` +
32
- encode(p.displayName) +
33
- "</div>" +
34
- `<ul>${lis}</ul>` +
35
- "</li>";
36
-
37
- }
38
- }).join("");
39
- return `<aside class="sidebar-parent">` +
40
- sidebarHeaderHtml +
41
- `<div class="sidebar-wrapper">` +
42
- `<div class="sidebar-items">${links}</div>` +
43
- "</div>" +
44
- "</aside>";
45
-
46
- function generateLiForPage(p, isActive) {
47
- const relativeUri = toUriCompatibleRelativePath(
48
- p.outputFile,
49
- path.dirname(currentPath)
50
- );
51
- const activeClass = isActive ? " active" : "";
52
- const cleanedHref = encode(relativeUri);
53
- return "<li class=\"sidebar-item\">" +
54
- `<a class="sidebar-link${activeClass}" href="` +
55
- cleanedHref +
56
- `">${encode(p.displayName)}</a>` +
57
- "</li>";
58
- }
59
- }
60
-
61
- /**
62
- * @param {Object} logoInfo
63
- * @returns {string}
64
- */
65
- function constructSidebarHeaderHtml(logoInfo) {
66
- let sidebarHeaderHtml = `<div class="sidebar-header">`;
67
- if (logoInfo !== undefined) {
68
- let hasLink = false;
69
- if (typeof logoInfo.link === "string") {
70
- hasLink = true;
71
- sidebarHeaderHtml += `<a href="${encode(logoInfo.link)}">`;
72
- }
73
- if (typeof logoInfo.url === "string") {
74
- sidebarHeaderHtml += `<img alt="logo" class="sidebar-header-logo"` +
75
- ` src="${encode(logoInfo.url)}" />`;
76
- }
77
- if (hasLink) {
78
- sidebarHeaderHtml += "</a>";
79
- }
80
- }
81
- sidebarHeaderHtml += `</div>`;
82
- return sidebarHeaderHtml;
83
- }
84
-
85
- module.exports = generateSidebarHtml;
@@ -1,137 +0,0 @@
1
- const cheerio = require("cheerio");
2
-
3
- /**
4
- * Generate search data linked to the given content.
5
- * @param {string} contentHtml
6
- * @returns {Array.<Object>}
7
- */
8
- function getSearchDataForContent(contentHtml) {
9
- const indexForFile = [];
10
- const $ = cheerio.load(contentHtml);
11
- const children = $("body").children().toArray();
12
-
13
- let currentH1;
14
- let currentH2;
15
- let currentH3;
16
- let currentH1Anchor;
17
- let currentH2Anchor;
18
- let currentH3Anchor;
19
- let currentBody = [];
20
- let currentLevel;
21
- for (var i = 0; i < children.length; i++) {
22
- const child = children[i];
23
- switch (child.name.toLowerCase()) {
24
- case "h1":
25
- anounceLastElement();
26
- currentH1 = $(child).text();
27
-
28
- // TODO We know that's the anchor's link is in the previous element.
29
- // That's pretty ugly but it works for now.
30
- // Find better solution
31
- currentH1Anchor = getAnchorName(children[i - 1]);
32
- currentH2 = undefined;
33
- currentH2Anchor = undefined;
34
- currentH3 = undefined;
35
- currentH3Anchor = undefined;
36
- currentLevel = "h1";
37
- break;
38
- case "h2":
39
- anounceLastElement();
40
- currentH2 = $(child).text();
41
-
42
- // TODO We know that's the anchor's link is in the previous element.
43
- // That's pretty ugly but it works for now.
44
- // Find better solution
45
- currentH2Anchor = getAnchorName(children[i - 1]);
46
- currentH3 = undefined;
47
- currentH3Anchor = undefined;
48
- currentLevel = "h2";
49
- break;
50
- case "h3":
51
- anounceLastElement();
52
-
53
- // TODO We know that's the anchor's link is in the previous element.
54
- // That's pretty ugly but it works for now.
55
- // Find better solution
56
- getAnchorName(children[i - 1]);
57
- currentH3 = $(child).text();
58
- currentH3Anchor = getAnchorName(children[i - 1]);
59
- currentLevel = "h3";
60
- break;
61
-
62
- // case "pre":
63
- // // code - do nothing?
64
- // break;
65
-
66
- default:
67
- const text = $(child).text().replace(/\n/g, " ");
68
- if (text !== undefined && text.length > 0) {
69
- currentBody.push(text);
70
- }
71
- break;
72
- }
73
- }
74
- anounceLastElement();
75
- return indexForFile;
76
-
77
- function anounceLastElement() {
78
- if (currentLevel === "h3") {
79
- const body = currentBody.length > 0 ?
80
- currentBody.join(" ") :
81
- "";
82
- indexForFile.push({
83
- h1: currentH1,
84
- h2: currentH2,
85
- h3: currentH3,
86
- body,
87
- anchorH1: currentH1Anchor,
88
- anchorH2: currentH2Anchor,
89
- anchorH3: currentH3Anchor,
90
- });
91
- } else if (currentLevel === "h2") {
92
- const body = currentBody.length > 0 ?
93
- currentBody.join(" ") :
94
- "";
95
- indexForFile.push({
96
- h1: currentH1,
97
- h2: currentH2,
98
- body,
99
- anchorH1: currentH1Anchor,
100
- anchorH2: currentH2Anchor,
101
- });
102
- } else if (currentLevel === "h1") {
103
- const body = currentBody.length > 0 ?
104
- currentBody.join(" ") :
105
- "";
106
- indexForFile.push({
107
- h1: currentH1,
108
- body,
109
- anchorH1: currentH1Anchor,
110
- });
111
- }
112
- currentBody.length = 0;
113
- }
114
-
115
- function getAnchorName(elt) {
116
- if (elt === undefined) {
117
- return;
118
- }
119
-
120
- const children = $(elt).children();
121
- if (children.length !== 1) {
122
- return;
123
- }
124
-
125
- const child = children.toArray()[0];
126
- if (child.name !== "a") {
127
- return;
128
- }
129
-
130
- const name = $(child).attr("name");
131
- if (name !== undefined && name.length > 0) {
132
- return name;
133
- }
134
- }
135
- }
136
-
137
- module.exports = getSearchDataForContent;
@@ -1,34 +0,0 @@
1
- const process = require("process");
2
- const path = require("path");
3
- const createDocumentation = require("./create_documentation.js");
4
-
5
- if (process.argv.length < 4) {
6
- /* eslint-disable no-console */
7
- console.error(
8
- "Error: The documentation generator needs at least two arguments: " +
9
- "the input directory and the output directory"
10
- );
11
- /* eslint-enable no-console */
12
- process.exit(1);
13
- }
14
-
15
- // TODO better args
16
- const inDir = process.argv[2];
17
- const outDir = process.argv[3];
18
- const version = process.argv[4];
19
-
20
- async function main() {
21
- createDocumentation(inDir, outDir, {
22
- css: [
23
- path.join(__dirname, "styles/style.css"),
24
- path.join(__dirname, "styles/code.css")
25
- ],
26
-
27
- // Add suffix to each page title
28
- getPageTitle: originalTitle => originalTitle + " - RxPlayer Documentation",
29
-
30
- version,
31
- });
32
- }
33
-
34
- main();
@@ -1,327 +0,0 @@
1
- const process = require("process");
2
- const { promisify } = require("util");
3
- const fs = require("fs");
4
- const path = require("path");
5
-
6
- module.exports = async function parseDocConfigs(
7
- baseInDir,
8
- baseOutDir,
9
- version
10
- ) {
11
- const rootConfigFileName = path.join(baseInDir, ".docConfig.json");
12
- const rootConfig = await parseAndCheckRootConfigFile(rootConfigFileName);
13
- const ret = {
14
- versionInfo: undefined,
15
- logo: undefined,
16
- favicon: undefined,
17
- links: [],
18
- linksRightIndex: -1,
19
- };
20
-
21
- if (typeof version === "string") {
22
- ret.versionInfo = { version };
23
- if (typeof rootConfig.otherVersionsLink === "string") {
24
- ret.versionInfo.link = rootConfig.otherVersionsLink;
25
- }
26
- }
27
-
28
- if (typeof rootConfig.logo === "object") {
29
- ret.logo = rootConfig.logo;
30
- }
31
-
32
- if (typeof rootConfig.favicon === "object") {
33
- ret.favicon = rootConfig.favicon;
34
- }
35
-
36
- const linksLeft = rootConfig.linksLeft ?? [];
37
- const linksRight = rootConfig.linksRight ?? [];
38
- const categoryLinks = linksLeft.concat(linksRight);
39
- if (linksRight.length > 0) {
40
- ret.linksRightIndex = linksLeft.length;
41
- }
42
-
43
- for (let i = 0; i < categoryLinks.length; i++) {
44
- const category = categoryLinks[i];
45
-
46
- let parsedCategory;
47
- switch (category.type) {
48
- case "local-doc":
49
- parsedCategory = await parseLocalDocCategory(category, baseInDir, baseOutDir);
50
- break;
51
- case "version":
52
- parsedCategory = { type: "version" };
53
- break;
54
- case "link":
55
- parsedCategory = {
56
- type: "external-link",
57
- link: category.link,
58
- displayName: category.displayName
59
- };
60
- break;
61
- case "github-link":
62
- parsedCategory = {
63
- type: "github-link",
64
- link: category.link,
65
- };
66
- break;
67
- case "search":
68
- parsedCategory = { type: "search" };
69
- break;
70
- }
71
- ret.links.push(parsedCategory);
72
- }
73
- return ret;
74
- };
75
-
76
- async function parseLocalDocCategory(
77
- category,
78
- baseInDir,
79
- baseOutDir
80
- ) {
81
- const categoryPath = path.join(baseInDir, category.path);
82
- const categoryOutPath = path.join(baseOutDir, category.path);
83
- const parsedCategory = {
84
- type: "local-doc",
85
- displayName: category.displayName,
86
- description: category.description,
87
- firstPage: "",
88
- pages: [],
89
- };
90
- const catCfgFileName = path.join(categoryPath, ".docConfig.json");
91
- const categoryConfig = await parseAndCheckSubConfigFile(catCfgFileName);
92
- for (const page of categoryConfig.pages) {
93
- const pagePath = path.join(categoryPath, page.path);
94
- let pageStat;
95
- try {
96
- pageStat = await promisify(fs.stat)(pagePath);
97
- } catch (err) {
98
- const srcMessage = (err ?? {}).message ?? "Unknown error";
99
- console.error(`Error: Cannot run stat on "${pagePath}": ${srcMessage}`);
100
- process.exit(1);
101
- }
102
-
103
- if (pageStat.isDirectory()) {
104
- const parsedPage = {
105
- isPageGroup: true,
106
- displayName: page.displayName,
107
- description: path.description,
108
- pages: [],
109
- };
110
- parsedCategory.pages.push(parsedPage);
111
- const pageCfgFileName = path.join(pagePath, ".docConfig.json");
112
- const pageGroupConfig = await parseAndCheckSubConfigFile(pageCfgFileName);
113
- for (const subPage of pageGroupConfig.pages) {
114
- const subPagePath = path.join(pagePath, subPage.path);
115
- const subPageOutPath = path.join(categoryOutPath, page.path, subPage.path);
116
- let subPageState;
117
- try {
118
- subPageState = await promisify(fs.stat)(subPagePath);
119
- } catch (err) {
120
- const srcMessage = (err ?? {}).message ?? "Unknown error";
121
- console.error(`Error: Cannot run stat on "${subPagePath}": ${srcMessage}`);
122
- process.exit(1);
123
- }
124
-
125
- if (subPageState.isDirectory()) {
126
- console.error(
127
- "Error: Category page depth cannot exceed 2 yet \"" +
128
- subPagePath + "\" is a directory."
129
- );
130
- process.exit(1);
131
- }
132
- const outputFile = path.join(path.dirname(subPageOutPath),
133
- path.basename(subPagePath, ".md") + ".html");
134
- parsedPage.pages.push({
135
- isPageGroup: false,
136
- displayName: subPage.displayName,
137
- description: subPage.description,
138
- inputFile: path.normalize(path.resolve(subPagePath)),
139
- outputFile: path.normalize(path.resolve(outputFile)),
140
- });
141
- }
142
- } else if(pageStat.isFile()) {
143
- const outputFile =
144
- path.join(categoryOutPath, path.basename(pagePath, ".md") + ".html");
145
- parsedCategory.pages.push({
146
- isPageGroup: false,
147
- displayName: page.displayName,
148
- description: page.description,
149
- inputFile: path.normalize(path.resolve(pagePath)),
150
- outputFile: path.normalize(path.resolve(outputFile)),
151
- });
152
- }
153
- }
154
-
155
- // Retrieve landing page for category == first page available
156
- if (parsedCategory.pages.length > 0) {
157
- if (!parsedCategory.pages[0].isPageGroup) {
158
- parsedCategory.firstPage = parsedCategory.pages[0].outputFile;
159
- } else if (parsedCategory.pages[0].pages.length > 0) {
160
- parsedCategory.firstPage = parsedCategory.pages[0].pages[0].outputFile;
161
- }
162
- }
163
- return parsedCategory;
164
- }
165
-
166
- /**
167
- * Parse root config file into a JS object and check that all properties are in
168
- * the right format.
169
- * Exit with a meaningful error if that's not the case.
170
- * @param {string} rootConfigFileName
171
- * @returns {Promise.<Object>}
172
- */
173
- async function parseAndCheckRootConfigFile(rootConfigFileName) {
174
- let configStr;
175
- try {
176
- configStr = await promisify(fs.readFile)(rootConfigFileName, "utf8");
177
- } catch (err) {
178
- const srcMessage = (err ?? {}).message ?? "Unknown error";
179
- console.error(
180
- "Error: Impossible to read Root .docConfig.json file (\"" +
181
- rootConfigFileName +
182
- "\"): " +
183
- srcMessage
184
- );
185
- process.exit(1);
186
- }
187
-
188
- let config;
189
- try {
190
- config = JSON.parse(configStr);
191
- } catch (err) {
192
- const srcMessage = (err ?? {}).message ?? "Unknown error";
193
- exitWithInvalidRootConfig(srcMessage);
194
- }
195
-
196
- if (typeof config !== "object" || config === null) {
197
- exitWithInvalidRootConfig("Should be under an object form.");
198
- }
199
-
200
- if (config.logo !== undefined) {
201
- if (typeof config.logo !== "object" || config.logo === null) {
202
- exitWithInvalidRootConfig(
203
- `The "logo" property, if defined, should contain an object.`
204
- );
205
- }
206
-
207
- if (typeof config.logo.srcPath !== "string") {
208
- exitWithInvalidRootConfig(
209
- `The "logo" property, if defined, should contain a "srcPath" ` +
210
- "property set as a string."
211
- );
212
- }
213
-
214
- if (config.logo.link !== undefined && typeof config.logo.link !== "string") {
215
- exitWithInvalidRootConfig(
216
- `The "logo.link" property, if defined, should be set as a string.`
217
- );
218
- }
219
- }
220
-
221
- if (config.favicon !== undefined) {
222
- if (typeof config.favicon.srcPath !== "string") {
223
- exitWithInvalidRootConfig(
224
- `The "favicon" property, if defined, should contain a "srcPath" `+
225
- "property set as a string."
226
- );
227
- }
228
- }
229
-
230
- if (
231
- config.otherVersionsLink !== undefined &&
232
- typeof config.otherVersionsLink !== "string"
233
- ) {
234
- exitWithInvalidRootConfig(
235
- `The "otherVersionsLink" property, if defined, should be set as a string.`
236
- );
237
- }
238
-
239
- if (
240
- typeof config.linksLeft !== undefined &&
241
- !Array.isArray(config.linksLeft)
242
- ) {
243
- exitWithInvalidRootConfig(
244
- `The "linksLeft" property, if defined, should be set as an Array.`
245
- );
246
- }
247
-
248
- if (
249
- typeof config.linksRight !== undefined &&
250
- !Array.isArray(config.linksRight)
251
- ) {
252
- exitWithInvalidRootConfig(
253
- `The "linksRight" property, if defined, should be set as an Array.`
254
- );
255
- }
256
-
257
- return config;
258
-
259
- function exitWithInvalidRootConfig(reason) {
260
- console.error(
261
- `Error: Root .docConfig.json file ("${rootConfigFileName}") is invalid: ${reason}`
262
- );
263
- process.exit(1);
264
- }
265
- }
266
-
267
- /**
268
- * @param {string} filename
269
- * @returns {Promise.<Object>}
270
- */
271
- async function parseAndCheckSubConfigFile(filename) {
272
- let configStr;
273
- try {
274
- configStr = await promisify(fs.readFile)(filename, "utf8");
275
- } catch (err) {
276
- const srcMessage = (err ?? {}).message ?? "Unknown error";
277
- console.error(`Error: Impossible to read "${filename}" config file: ${srcMessage}`);
278
- process.exit(1);
279
- }
280
-
281
- let config;
282
- try {
283
- config = JSON.parse(configStr);
284
- } catch (err) {
285
- const srcMessage = (err ?? {}).message ?? "Unknown error";
286
- console.error(`Error: "${filename}" config file is invalid: ${srcMessage}`);
287
- process.exit(1);
288
- }
289
-
290
- if (typeof config !== "object" || config === null) {
291
- console.error(
292
- `Error: "${filename}" config file is invalid: ` +
293
- `Should be under an object form.`
294
- );
295
- process.exit(1);
296
- }
297
-
298
- if (
299
- !Array.isArray(config.pages) ||
300
- config.pages.length === 0
301
- ) {
302
- console.error(
303
- `Error: "${filename}" config file is invalid: ` +
304
- `Should have a "pages" property with at least one entry.`
305
- );
306
- process.exit(1);
307
- }
308
-
309
- for (const page of config.pages) {
310
- if (typeof page.path !== "string") {
311
- console.error(
312
- `Error: "${filename}" config file is invalid: ` +
313
- `One of the element in "pages" has an invalid "path" property ` +
314
- "(should be a string)."
315
- );
316
- process.exit(1);
317
- } else if (typeof page.displayName !== "string") {
318
- console.error(
319
- `Error: "${filename}" config file is invalid: ` +
320
- `One of the element in "pages" has an invalid "displayName" property ` +
321
- "(should be a string)."
322
- );
323
- process.exit(1);
324
- }
325
- }
326
- return config;
327
- }