rx-player 4.0.0-dev.2023111400 → 4.0.0-dev.2023121900

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 (336) hide show
  1. package/CHANGELOG.md +20 -60
  2. package/FILES.md +1 -1
  3. package/README.md +2 -33
  4. package/VERSION +1 -1
  5. package/dist/_esm5.processed/core/api/debug/buffer_graph.js +2 -6
  6. package/dist/_esm5.processed/core/api/debug/modules/general_info.js +20 -10
  7. package/dist/_esm5.processed/core/api/option_utils.d.ts +0 -2
  8. package/dist/_esm5.processed/core/api/option_utils.js +0 -6
  9. package/dist/_esm5.processed/core/api/public_api.d.ts +1 -2
  10. package/dist/_esm5.processed/core/api/public_api.js +9 -17
  11. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +1 -1
  12. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +3 -14
  13. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +2 -36
  14. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +2 -82
  15. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  16. package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.js +1 -1
  17. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  18. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  19. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  20. package/dist/_esm5.processed/core/segment_buffers/inventory/index.d.ts +2 -2
  21. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  22. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.js +19 -10
  23. package/dist/_esm5.processed/core/stream/representation/utils/get_buffer_status.js +1 -1
  24. package/dist/_esm5.processed/core/stream/representation/utils/get_needed_segments.js +1 -1
  25. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_extent.js +1 -8
  26. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  27. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_origin.js +1 -9
  28. package/dist/_esm5.processed/public_types.d.ts +2 -0
  29. package/dist/commonjs/compat/is_codec_supported.js +22 -1
  30. package/dist/commonjs/config.d.ts +2 -1
  31. package/dist/commonjs/core/adaptive/adaptive_representation_selector.d.ts +2 -19
  32. package/dist/commonjs/core/adaptive/adaptive_representation_selector.js +2 -2
  33. package/dist/commonjs/core/adaptive/network_analyzer.js +3 -3
  34. package/dist/commonjs/core/api/debug/buffer_graph.js +2 -6
  35. package/dist/commonjs/core/api/debug/modules/general_info.js +17 -10
  36. package/dist/commonjs/core/api/index.d.ts +1 -1
  37. package/dist/commonjs/core/api/option_utils.d.ts +2 -0
  38. package/dist/commonjs/core/api/option_utils.js +2 -3
  39. package/dist/commonjs/core/api/playback_observer.d.ts +128 -8
  40. package/dist/commonjs/core/api/playback_observer.js +217 -64
  41. package/dist/commonjs/core/api/public_api.d.ts +9 -0
  42. package/dist/commonjs/core/api/public_api.js +41 -16
  43. package/dist/commonjs/core/api/utils.js +1 -1
  44. package/dist/commonjs/core/decrypt/get_media_keys.js +2 -6
  45. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  46. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.js +11 -3
  47. package/dist/commonjs/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  48. package/dist/commonjs/core/fetchers/segment/segment_fetcher.js +8 -4
  49. package/dist/commonjs/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  50. package/dist/commonjs/core/fetchers/utils/schedule_request.js +1 -1
  51. package/dist/commonjs/core/init/directfile_content_initializer.js +29 -8
  52. package/dist/commonjs/core/init/media_source_content_initializer.d.ts +6 -0
  53. package/dist/commonjs/core/init/media_source_content_initializer.js +32 -20
  54. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  55. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.js +17 -19
  56. package/dist/commonjs/core/init/utils/create_stream_playback_observer.d.ts +1 -5
  57. package/dist/commonjs/core/init/utils/create_stream_playback_observer.js +16 -14
  58. package/dist/commonjs/core/init/utils/get_initial_time.d.ts +17 -3
  59. package/dist/commonjs/core/init/utils/get_initial_time.js +9 -7
  60. package/dist/commonjs/core/init/utils/initial_seek_and_play.d.ts +9 -11
  61. package/dist/commonjs/core/init/utils/initial_seek_and_play.js +121 -91
  62. package/dist/commonjs/core/init/utils/rebuffering_controller.js +27 -70
  63. package/dist/commonjs/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
  64. package/dist/commonjs/core/segment_buffers/garbage_collector.js +1 -2
  65. package/dist/commonjs/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  66. package/dist/commonjs/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  67. package/dist/commonjs/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  68. package/dist/commonjs/core/segment_buffers/index.d.ts +2 -2
  69. package/dist/commonjs/core/segment_buffers/inventory/index.d.ts +2 -2
  70. package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  71. package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.js +19 -10
  72. package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
  73. package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
  74. package/dist/commonjs/core/stream/orchestrator/stream_orchestrator.js +14 -18
  75. package/dist/commonjs/core/stream/period/period_stream.js +5 -8
  76. package/dist/commonjs/core/stream/period/types.d.ts +2 -3
  77. package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
  78. package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
  79. package/dist/commonjs/core/stream/representation/representation_stream.js +3 -4
  80. package/dist/commonjs/core/stream/representation/types.d.ts +2 -2
  81. package/dist/commonjs/core/stream/representation/utils/append_segment_to_buffer.js +11 -12
  82. package/dist/commonjs/core/stream/representation/utils/get_buffer_status.js +4 -4
  83. package/dist/commonjs/core/stream/representation/utils/get_needed_segments.js +1 -1
  84. package/dist/commonjs/default_config.d.ts +12 -16
  85. package/dist/commonjs/default_config.js +21 -16
  86. package/dist/commonjs/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  87. package/dist/commonjs/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  88. package/dist/commonjs/manifest/adaptation.js +2 -1
  89. package/dist/commonjs/manifest/representation_index/static.d.ts +1 -1
  90. package/dist/commonjs/manifest/representation_index/static.js +2 -2
  91. package/dist/commonjs/manifest/representation_index/types.d.ts +4 -4
  92. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  93. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.js +4 -3
  94. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  95. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  96. package/dist/commonjs/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  97. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  98. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.js +2 -2
  99. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  100. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.js +42 -29
  101. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  102. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  103. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +250 -51
  104. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  105. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  106. package/dist/commonjs/parsers/manifest/dash/common/parse_adaptation_sets.js +13 -10
  107. package/dist/commonjs/parsers/manifest/dash/common/parse_mpd.js +27 -14
  108. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  109. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.js +17 -18
  110. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  111. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.js +21 -8
  112. package/dist/commonjs/parsers/manifest/dash/common/parse_representations.js +7 -3
  113. package/dist/commonjs/parsers/manifest/local/representation_index.d.ts +1 -1
  114. package/dist/commonjs/parsers/manifest/local/representation_index.js +3 -3
  115. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  116. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.js +2 -2
  117. package/dist/commonjs/parsers/manifest/smooth/representation_index.d.ts +5 -5
  118. package/dist/commonjs/parsers/manifest/smooth/representation_index.js +25 -9
  119. package/dist/commonjs/parsers/manifest/utils/index_helpers.js +1 -1
  120. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  121. package/dist/commonjs/public_types.d.ts +107 -36
  122. package/dist/commonjs/transports/dash/init_segment_loader.js +10 -5
  123. package/dist/commonjs/transports/dash/manifest_parser.js +5 -2
  124. package/dist/commonjs/transports/dash/segment_loader.js +2 -1
  125. package/dist/commonjs/transports/dash/text_loader.js +2 -0
  126. package/dist/commonjs/transports/metaplaylist/manifest_loader.js +2 -1
  127. package/dist/commonjs/transports/metaplaylist/pipelines.js +4 -1
  128. package/dist/commonjs/transports/smooth/pipelines.js +4 -2
  129. package/dist/commonjs/transports/smooth/segment_loader.js +2 -1
  130. package/dist/commonjs/transports/types.d.ts +12 -0
  131. package/dist/commonjs/transports/utils/generate_manifest_loader.js +6 -3
  132. package/dist/commonjs/utils/request/fetch.d.ts +6 -0
  133. package/dist/commonjs/utils/request/fetch.js +29 -8
  134. package/dist/commonjs/utils/request/xhr.d.ts +11 -5
  135. package/dist/commonjs/utils/request/xhr.js +29 -8
  136. package/dist/es2017/compat/is_codec_supported.js +22 -1
  137. package/dist/es2017/config.d.ts +2 -1
  138. package/dist/es2017/core/adaptive/adaptive_representation_selector.d.ts +2 -19
  139. package/dist/es2017/core/adaptive/adaptive_representation_selector.js +2 -2
  140. package/dist/es2017/core/adaptive/network_analyzer.js +3 -3
  141. package/dist/es2017/core/api/debug/buffer_graph.js +2 -6
  142. package/dist/es2017/core/api/debug/modules/general_info.js +17 -10
  143. package/dist/es2017/core/api/index.d.ts +1 -1
  144. package/dist/es2017/core/api/option_utils.d.ts +2 -0
  145. package/dist/es2017/core/api/option_utils.js +2 -3
  146. package/dist/es2017/core/api/playback_observer.d.ts +128 -8
  147. package/dist/es2017/core/api/playback_observer.js +217 -66
  148. package/dist/es2017/core/api/public_api.d.ts +9 -0
  149. package/dist/es2017/core/api/public_api.js +40 -15
  150. package/dist/es2017/core/api/utils.js +1 -1
  151. package/dist/es2017/core/decrypt/get_media_keys.js +2 -6
  152. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  153. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.js +11 -3
  154. package/dist/es2017/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  155. package/dist/es2017/core/fetchers/segment/segment_fetcher.js +8 -4
  156. package/dist/es2017/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  157. package/dist/es2017/core/fetchers/utils/schedule_request.js +1 -1
  158. package/dist/es2017/core/init/directfile_content_initializer.js +31 -8
  159. package/dist/es2017/core/init/media_source_content_initializer.d.ts +6 -0
  160. package/dist/es2017/core/init/media_source_content_initializer.js +34 -22
  161. package/dist/es2017/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  162. package/dist/es2017/core/init/utils/content_time_boundaries_observer.js +17 -17
  163. package/dist/es2017/core/init/utils/create_stream_playback_observer.d.ts +1 -5
  164. package/dist/es2017/core/init/utils/create_stream_playback_observer.js +16 -14
  165. package/dist/es2017/core/init/utils/get_initial_time.d.ts +17 -3
  166. package/dist/es2017/core/init/utils/get_initial_time.js +9 -7
  167. package/dist/es2017/core/init/utils/initial_seek_and_play.d.ts +9 -11
  168. package/dist/es2017/core/init/utils/initial_seek_and_play.js +120 -91
  169. package/dist/es2017/core/init/utils/rebuffering_controller.js +27 -70
  170. package/dist/es2017/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
  171. package/dist/es2017/core/segment_buffers/garbage_collector.js +1 -2
  172. package/dist/es2017/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  173. package/dist/es2017/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  174. package/dist/es2017/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  175. package/dist/es2017/core/segment_buffers/index.d.ts +2 -2
  176. package/dist/es2017/core/segment_buffers/inventory/index.d.ts +2 -2
  177. package/dist/es2017/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  178. package/dist/es2017/core/segment_buffers/inventory/segment_inventory.js +19 -10
  179. package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
  180. package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
  181. package/dist/es2017/core/stream/orchestrator/stream_orchestrator.js +16 -18
  182. package/dist/es2017/core/stream/period/period_stream.js +4 -7
  183. package/dist/es2017/core/stream/period/types.d.ts +2 -3
  184. package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
  185. package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
  186. package/dist/es2017/core/stream/representation/representation_stream.js +3 -4
  187. package/dist/es2017/core/stream/representation/types.d.ts +2 -2
  188. package/dist/es2017/core/stream/representation/utils/append_segment_to_buffer.js +1 -2
  189. package/dist/es2017/core/stream/representation/utils/get_buffer_status.js +4 -4
  190. package/dist/es2017/core/stream/representation/utils/get_needed_segments.js +1 -1
  191. package/dist/es2017/default_config.d.ts +12 -16
  192. package/dist/es2017/default_config.js +21 -16
  193. package/dist/es2017/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  194. package/dist/es2017/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  195. package/dist/es2017/manifest/adaptation.js +2 -1
  196. package/dist/es2017/manifest/representation_index/static.d.ts +1 -1
  197. package/dist/es2017/manifest/representation_index/static.js +2 -2
  198. package/dist/es2017/manifest/representation_index/types.d.ts +4 -4
  199. package/dist/es2017/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  200. package/dist/es2017/parsers/manifest/dash/common/indexes/base.js +4 -3
  201. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  202. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  203. package/dist/es2017/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  204. package/dist/es2017/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  205. package/dist/es2017/parsers/manifest/dash/common/indexes/list.js +2 -2
  206. package/dist/es2017/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  207. package/dist/es2017/parsers/manifest/dash/common/indexes/template.js +40 -27
  208. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  209. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  210. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +246 -51
  211. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  212. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  213. package/dist/es2017/parsers/manifest/dash/common/parse_adaptation_sets.js +11 -8
  214. package/dist/es2017/parsers/manifest/dash/common/parse_mpd.js +27 -13
  215. package/dist/es2017/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  216. package/dist/es2017/parsers/manifest/dash/common/parse_periods.js +13 -16
  217. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  218. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.js +10 -8
  219. package/dist/es2017/parsers/manifest/dash/common/parse_representations.js +7 -3
  220. package/dist/es2017/parsers/manifest/local/representation_index.d.ts +1 -1
  221. package/dist/es2017/parsers/manifest/local/representation_index.js +3 -3
  222. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  223. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.js +2 -2
  224. package/dist/es2017/parsers/manifest/smooth/representation_index.d.ts +5 -5
  225. package/dist/es2017/parsers/manifest/smooth/representation_index.js +25 -9
  226. package/dist/es2017/parsers/manifest/utils/index_helpers.js +1 -1
  227. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  228. package/dist/es2017/public_types.d.ts +107 -36
  229. package/dist/es2017/transports/dash/init_segment_loader.js +5 -0
  230. package/dist/es2017/transports/dash/manifest_parser.js +3 -0
  231. package/dist/es2017/transports/dash/segment_loader.js +1 -0
  232. package/dist/es2017/transports/dash/text_loader.js +2 -0
  233. package/dist/es2017/transports/metaplaylist/manifest_loader.js +1 -0
  234. package/dist/es2017/transports/metaplaylist/pipelines.js +4 -1
  235. package/dist/es2017/transports/smooth/pipelines.js +2 -0
  236. package/dist/es2017/transports/smooth/segment_loader.js +1 -0
  237. package/dist/es2017/transports/types.d.ts +12 -0
  238. package/dist/es2017/transports/utils/generate_manifest_loader.js +3 -0
  239. package/dist/es2017/utils/request/fetch.d.ts +6 -0
  240. package/dist/es2017/utils/request/fetch.js +29 -8
  241. package/dist/es2017/utils/request/xhr.d.ts +11 -5
  242. package/dist/es2017/utils/request/xhr.js +30 -9
  243. package/dist/mpd-parser.wasm +0 -0
  244. package/dist/rx-player.js +1335 -812
  245. package/dist/rx-player.min.js +1 -1
  246. package/package.json +7 -4
  247. package/scripts/canal-release.patch +78 -0
  248. package/scripts/make-dev-releases +65 -0
  249. package/scripts/update-version +7 -0
  250. package/sonar-project.properties +1 -1
  251. package/src/compat/is_codec_supported.ts +23 -1
  252. package/src/core/adaptive/adaptive_representation_selector.ts +4 -21
  253. package/src/core/adaptive/network_analyzer.ts +3 -3
  254. package/src/core/api/debug/buffer_graph.ts +2 -5
  255. package/src/core/api/debug/modules/general_info.ts +15 -10
  256. package/src/core/api/index.ts +1 -0
  257. package/src/core/api/option_utils.ts +3 -3
  258. package/src/core/api/playback_observer.ts +327 -107
  259. package/src/core/api/public_api.ts +42 -14
  260. package/src/core/api/utils.ts +3 -1
  261. package/src/core/decrypt/get_media_keys.ts +2 -8
  262. package/src/core/fetchers/manifest/manifest_fetcher.ts +21 -3
  263. package/src/core/fetchers/segment/segment_fetcher.ts +19 -5
  264. package/src/core/fetchers/segment/segment_fetcher_creator.ts +1 -0
  265. package/src/core/fetchers/utils/schedule_request.ts +1 -1
  266. package/src/core/init/directfile_content_initializer.ts +31 -15
  267. package/src/core/init/media_source_content_initializer.ts +40 -27
  268. package/src/core/init/utils/content_time_boundaries_observer.ts +24 -23
  269. package/src/core/init/utils/create_stream_playback_observer.ts +19 -20
  270. package/src/core/init/utils/get_initial_time.ts +25 -12
  271. package/src/core/init/utils/initial_seek_and_play.ts +140 -108
  272. package/src/core/init/utils/rebuffering_controller.ts +32 -77
  273. package/src/core/init/utils/stream_events_emitter/stream_events_emitter.ts +5 -2
  274. package/src/core/segment_buffers/garbage_collector.ts +1 -1
  275. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +10 -2
  276. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +1 -1
  277. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +1 -1
  278. package/src/core/segment_buffers/index.ts +2 -0
  279. package/src/core/segment_buffers/inventory/index.ts +2 -0
  280. package/src/core/segment_buffers/inventory/segment_inventory.ts +49 -17
  281. package/src/core/stream/adaptation/get_representations_switch_strategy.ts +21 -12
  282. package/src/core/stream/orchestrator/stream_orchestrator.ts +14 -19
  283. package/src/core/stream/period/period_stream.ts +7 -8
  284. package/src/core/stream/period/types.ts +2 -3
  285. package/src/core/stream/period/utils/get_adaptation_switch_strategy.ts +21 -15
  286. package/src/core/stream/representation/representation_stream.ts +3 -5
  287. package/src/core/stream/representation/types.ts +2 -2
  288. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +1 -1
  289. package/src/core/stream/representation/utils/get_buffer_status.ts +5 -4
  290. package/src/core/stream/representation/utils/get_needed_segments.ts +2 -2
  291. package/src/default_config.ts +22 -17
  292. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +3 -1
  293. package/src/experimental/tools/createMetaplaylist/get_duration_from_manifest.ts +2 -0
  294. package/src/manifest/adaptation.ts +2 -1
  295. package/src/manifest/representation_index/static.ts +2 -2
  296. package/src/manifest/representation_index/types.ts +4 -4
  297. package/src/parsers/manifest/dash/common/__tests__/manifest_bounds_calculator.test.ts +182 -36
  298. package/src/parsers/manifest/dash/common/indexes/base.ts +12 -4
  299. package/src/parsers/manifest/dash/common/indexes/get_segments_from_timeline.ts +19 -5
  300. package/src/parsers/manifest/dash/common/indexes/index.ts +16 -4
  301. package/src/parsers/manifest/dash/common/indexes/list.ts +2 -2
  302. package/src/parsers/manifest/dash/common/indexes/template.ts +52 -31
  303. package/src/parsers/manifest/dash/common/indexes/timeline/index.ts +4 -1
  304. package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +366 -60
  305. package/src/parsers/manifest/dash/common/manifest_bounds_calculator.ts +63 -25
  306. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +10 -4
  307. package/src/parsers/manifest/dash/common/parse_mpd.ts +28 -15
  308. package/src/parsers/manifest/dash/common/parse_periods.ts +12 -17
  309. package/src/parsers/manifest/dash/common/parse_representation_index.ts +50 -26
  310. package/src/parsers/manifest/dash/common/parse_representations.ts +9 -3
  311. package/src/parsers/manifest/local/representation_index.ts +3 -3
  312. package/src/parsers/manifest/metaplaylist/representation_index.ts +2 -2
  313. package/src/parsers/manifest/smooth/representation_index.ts +23 -9
  314. package/src/parsers/manifest/utils/__tests__/get_first_time_from_adaptations.test.ts +1 -1
  315. package/src/parsers/manifest/utils/__tests__/get_last_time_from_adaptation.test.ts +1 -1
  316. package/src/parsers/manifest/utils/index_helpers.ts +1 -1
  317. package/src/parsers/texttracks/ttml/html/apply_line_height.ts +3 -1
  318. package/src/public_types.ts +108 -36
  319. package/src/transports/dash/init_segment_loader.ts +5 -0
  320. package/src/transports/dash/manifest_parser.ts +6 -0
  321. package/src/transports/dash/segment_loader.ts +1 -0
  322. package/src/transports/dash/text_loader.ts +2 -0
  323. package/src/transports/metaplaylist/manifest_loader.ts +1 -0
  324. package/src/transports/metaplaylist/pipelines.ts +4 -1
  325. package/src/transports/smooth/pipelines.ts +2 -0
  326. package/src/transports/smooth/segment_loader.ts +1 -0
  327. package/src/transports/types.ts +12 -0
  328. package/src/transports/utils/generate_manifest_loader.ts +3 -0
  329. package/src/utils/request/fetch.ts +35 -8
  330. package/src/utils/request/xhr.ts +45 -14
  331. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  332. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.js +0 -54
  333. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  334. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.js +0 -51
  335. package/src/parsers/manifest/utils/is_segment_still_available.ts +0 -58
  336. package/src/typings/object-assign.d.ts +0 -48
@@ -137,8 +137,35 @@ export interface IRepresentationFilterRepresentation {
137
137
  /** String identifying the Representation, unique per Adaptation. */
138
138
  id: string;
139
139
  bitrate?: number | undefined;
140
- /** Codec used by the media segments of that Representation. */
141
- codec?: string | undefined;
140
+ /**
141
+ * Codec(s) relied on by the media segments of that Representation.
142
+ *
143
+ * For the great majority of cases, this value will be set to either
144
+ * `undefined` (meaning the codec is unknown) or to an array with a
145
+ * single element which will be the actual codec relied on when the
146
+ * corresponding Representation will be played.
147
+ *
148
+ * However in some very rare scenarios, this value might be set to an array
149
+ * with multiple codecs, itself being a list of its candidate codecs from the
150
+ * most wanted to the most compatible.
151
+ * The conditions for this more complex format are very specific:
152
+ *
153
+ * - It can only happen if the `representationFilter` callback is called in
154
+ * an environment where it hasn't yet been possible for the RxPlayer to
155
+ * check for codec support (mainly when running through the RxPlayer's
156
+ * `MULTI_THREAD` feature in a browser without MSE-in-worker
157
+ * capabilities).
158
+ *
159
+ * - The corresponding Representation is compatible to a restrictive codec
160
+ * yet also retro-compatible to a less restrictive one.
161
+ *
162
+ * The main example being Dolby Vision Representations which are
163
+ * retro-compatible to HDR10 HEVC codecs.
164
+ * In that very specific case, we could have an array with two elements:
165
+ * 1. The Dolby Vision codec
166
+ * 2. The base HDR10 codec
167
+ */
168
+ codecs?: string[] | undefined;
142
169
  /**
143
170
  * This property makes the most sense for video Representations.
144
171
  * It defines the height of the video, in pixels.
@@ -203,10 +230,20 @@ export type IStartAtOption = {
203
230
  percentage: number;
204
231
  } | {
205
232
  /**
206
- * If set, we should begin at this position relative to the content's end,
207
- * in seconds.
233
+ * If set, we should begin at this position relative to the content's maximum
234
+ * seekable position, in seconds.
208
235
  */
209
236
  fromLastPosition: number;
237
+ } | {
238
+ /**
239
+ * If set, we should begin at this position relative to the content's live
240
+ * edge if it makes sense, in seconds.
241
+ *
242
+ * If the live edge is unknown or if it does not make sense for the current
243
+ * content, that position is relative to the content's maximum position
244
+ * instead.
245
+ */
246
+ fromLivePosition: number;
210
247
  } | {
211
248
  /**
212
249
  * If set, we should begin at this position relative to the content's start,
@@ -214,40 +251,37 @@ export type IStartAtOption = {
214
251
  */
215
252
  fromFirstPosition: number;
216
253
  };
254
+ export interface RequestRetryParameters {
255
+ /**
256
+ * The amount of time maximum we should retry a request before failing on Error.
257
+ * Set to `Infinity` for an infinite number of requests.
258
+ */
259
+ maxRetry?: number | undefined;
260
+ /**
261
+ * Amount of time, in milliseconds, after which a request should be
262
+ * aborted and optionally retried, depending on the maxRetry configuration.
263
+ *
264
+ * Setting it to `-1` allows to disable any timeout.
265
+ * `undefined` means that a default, large, timeout will be used instead.
266
+ */
267
+ timeout?: number | undefined;
268
+ /**
269
+ * Amount of time, in milliseconds, after which a request that hasn't receive
270
+ * the headers and status code should be aborted and optionnaly retried,
271
+ * depending on the maxRetry configuration.
272
+ */
273
+ connectionTimeout?: number | undefined;
274
+ }
217
275
  /** Value for the `requestConfig` option of the `loadVideo` method. */
218
276
  export interface IRequestConfig {
219
- manifest?: {
220
- /**
221
- * The amount of time maximum we should retry a Manifest or Manifest-related
222
- * request before failing on Error.
223
- * Set to `Infinity` for an infinite number of requests.
224
- */
225
- maxRetry?: number | undefined;
226
- /**
227
- * Amount of time, in milliseconds, after which a manifest request should be
228
- * aborted and optionally retried, depending on the current configuration.
229
- *
230
- * Setting it to `-1` allows to disable any timeout.
231
- * `undefined` means that a default, large, timeout will be used instead.
232
- */
233
- timeout?: number | undefined;
234
- } | undefined;
235
- segment?: {
236
- /**
237
- * The amount of time maximum we should retry a segment or segment-related
238
- * request before failing on Error.
239
- * Set to `Infinity` for an infinite number of requests.
240
- */
241
- maxRetry?: number | undefined;
242
- /**
243
- * Amount of time, in milliseconds, after which a segment request should be
244
- * aborted and optionally retried, depending on the current configuration.
245
- *
246
- * Setting it to `-1` allows to disable any timeout.
247
- * `undefined` means that a default, large, timeout will be used instead.
248
- */
249
- timeout?: number | undefined;
250
- } | undefined;
277
+ /**
278
+ * Defines the retry parameters when requesting manifest
279
+ */
280
+ manifest?: RequestRetryParameters | undefined;
281
+ /**
282
+ * Defines the retry parameters when requesting a segment
283
+ */
284
+ segment?: RequestRetryParameters | undefined;
251
285
  }
252
286
  export type ISegmentLoader = (
253
287
  /** Information on the segment to request */
@@ -808,18 +842,55 @@ export interface ILockedAudioRepresentationsSettings {
808
842
  switchingMode?: IAudioRepresentationsSwitchingMode | undefined;
809
843
  }
810
844
  export interface IAudioTrackSetting {
845
+ /** `id` of the audio track you want to set. */
811
846
  trackId: string;
847
+ /**
848
+ * `id` of the Period for which you want that setting applied.
849
+ * Keeping it undefined means it will apply to the currently-playing Period.
850
+ */
812
851
  periodId?: string | undefined;
852
+ /**
853
+ * Behavior wanted when replacing an audio track / Adaptation by another.
854
+ * @see IAudioTrackSwitchingMode
855
+ *
856
+ * Keeping it undefined means that the RxPlayer will automatically select
857
+ * the most adapted choice.
858
+ */
813
859
  switchingMode?: IAudioTrackSwitchingMode | undefined;
860
+ /**
861
+ * Representations (a.k.a. qualities) you want to play in that new track.
862
+ * Keeping it undefined means that all compatible qualities may be played.
863
+ */
814
864
  lockedRepresentations?: string[] | undefined;
815
865
  }
816
866
  export interface IVideoTrackSetting {
867
+ /** `id` of the video track you want to set. */
817
868
  trackId: string;
869
+ /**
870
+ * `id` of the Period for which you want that setting applied.
871
+ * Keeping it undefined means it will apply to the currently-playing Period.
872
+ */
818
873
  periodId?: string | undefined;
874
+ /**
875
+ * Behavior wanted when replacing an video track / Adaptation by another.
876
+ * @see IVideoTrackSwitchingMode
877
+ *
878
+ * Keeping it undefined means that the RxPlayer will automatically select
879
+ * the most adapted choice.
880
+ */
819
881
  switchingMode?: IVideoTrackSwitchingMode | undefined;
882
+ /**
883
+ * Representations (a.k.a. qualities) you want to play in that new track.
884
+ * Keeping it undefined means that all compatible qualities may be played.
885
+ */
820
886
  lockedRepresentations?: string[] | undefined;
821
887
  }
822
888
  export interface ITextTrackSetting {
889
+ /** `id` of the text track you want to set. */
823
890
  trackId: string;
891
+ /**
892
+ * `id` of the Period for which you want that setting applied.
893
+ * Keeping it undefined means it will apply to the currently-playing Period.
894
+ */
824
895
  periodId?: string | undefined;
825
896
  }
@@ -46,14 +46,16 @@ var byte_range_1 = require("../utils/byte_range");
46
46
  function initSegmentLoader(url, segment, options, cancelSignal, callbacks) {
47
47
  if (segment.range === undefined) {
48
48
  return (0, request_1.default)({ url: url, responseType: "arraybuffer",
49
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
49
+ timeout: options.timeout,
50
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
50
51
  .then(function (data) { return ({ resultType: "segment-loaded",
51
52
  resultData: data }); });
52
53
  }
53
54
  if (segment.indexRange === undefined) {
54
55
  return (0, request_1.default)({ url: url, headers: { Range: (0, byte_range_1.default)(segment.range) },
55
56
  responseType: "arraybuffer",
56
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
57
+ timeout: options.timeout,
58
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
57
59
  .then(function (data) { return ({ resultType: "segment-loaded",
58
60
  resultData: data }); });
59
61
  }
@@ -62,16 +64,19 @@ function initSegmentLoader(url, segment, options, cancelSignal, callbacks) {
62
64
  return (0, request_1.default)({ url: url, headers: { Range: (0, byte_range_1.default)([segment.range[0],
63
65
  segment.indexRange[1]]) },
64
66
  responseType: "arraybuffer",
65
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
67
+ timeout: options.timeout,
68
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
66
69
  .then(function (data) { return ({ resultType: "segment-loaded",
67
70
  resultData: data }); });
68
71
  }
69
72
  var rangeRequest$ = (0, request_1.default)({ url: url, headers: { Range: (0, byte_range_1.default)(segment.range) },
70
73
  responseType: "arraybuffer",
71
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress });
74
+ timeout: options.timeout,
75
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress });
72
76
  var indexRequest$ = (0, request_1.default)({ url: url, headers: { Range: (0, byte_range_1.default)(segment.indexRange) },
73
77
  responseType: "arraybuffer",
74
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress });
78
+ timeout: options.timeout,
79
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress });
75
80
  return Promise.all([rangeRequest$, indexRequest$])
76
81
  .then(function (_a) {
77
82
  var _b = __read(_a, 2), initData = _b[0], indexData = _b[1];
@@ -109,12 +109,15 @@ function generateManifestParser(options) {
109
109
  var externalResources = value.urls.map(function (resourceUrl) {
110
110
  return scheduleRequest(function () {
111
111
  var defaultTimeout = config_1.default.getCurrent().DEFAULT_REQUEST_TIMEOUT;
112
+ var defaultConnectionTimeout = config_1.default.getCurrent().DEFAULT_CONNECTION_TIMEOUT;
112
113
  return value.format === "string" ? (0, request_1.default)({ url: resourceUrl,
113
114
  responseType: "text",
114
- timeout: defaultTimeout, cancelSignal: cancelSignal }) :
115
+ timeout: defaultTimeout,
116
+ connectionTimeout: defaultConnectionTimeout, cancelSignal: cancelSignal }) :
115
117
  (0, request_1.default)({ url: resourceUrl,
116
118
  responseType: "arraybuffer",
117
- timeout: defaultTimeout, cancelSignal: cancelSignal });
119
+ timeout: defaultTimeout,
120
+ connectionTimeout: defaultConnectionTimeout, cancelSignal: cancelSignal });
118
121
  }).then(function (res) {
119
122
  if (value.format === "string") {
120
123
  if (typeof res.responseData !== "string") {
@@ -54,7 +54,8 @@ function regularSegmentLoader(url, context, lowLatencyMode, options, callbacks,
54
54
  headers: segment.range !== undefined ?
55
55
  { Range: (0, byte_range_1.default)(segment.range) } :
56
56
  undefined,
57
- timeout: options.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
57
+ timeout: options.timeout,
58
+ connectionTimeout: options.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
58
59
  .then(function (data) { return ({ resultType: "segment-loaded",
59
60
  resultData: data }); });
60
61
  }
@@ -68,6 +68,7 @@ function generateTextTrackLoader(_a) {
68
68
  { Range: (0, byte_range_1.default)(range) } :
69
69
  null,
70
70
  timeout: options.timeout,
71
+ connectionTimeout: options.connectionTimeout,
71
72
  onProgress: callbacks.onProgress, cancelSignal: cancelSignal })
72
73
  .then(function (data) { return ({ resultType: "segment-loaded",
73
74
  resultData: data }); });
@@ -77,6 +78,7 @@ function generateTextTrackLoader(_a) {
77
78
  { Range: (0, byte_range_1.default)(range) } :
78
79
  null,
79
80
  timeout: options.timeout,
81
+ connectionTimeout: options.connectionTimeout,
80
82
  onProgress: callbacks.onProgress, cancelSignal: cancelSignal })
81
83
  .then(function (data) { return ({ resultType: "segment-loaded",
82
84
  resultData: data }); });
@@ -28,7 +28,8 @@ function regularManifestLoader(url, loaderOptions, cancelSignal) {
28
28
  throw new Error("Cannot perform HTTP(s) request. URL not known");
29
29
  }
30
30
  return (0, request_1.default)({ url: url, responseType: "text",
31
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal });
31
+ timeout: loaderOptions.timeout,
32
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal });
32
33
  }
33
34
  /**
34
35
  * Generate a manifest loader for the application
@@ -117,7 +117,10 @@ function default_1(options) {
117
117
  * Whether a ManifestLoader's timeout should be relied on here
118
118
  * is ambiguous.
119
119
  */
120
- var manOpts = { timeout: config_1.default.getCurrent().DEFAULT_REQUEST_TIMEOUT };
120
+ var manOpts = {
121
+ timeout: config_1.default.getCurrent().DEFAULT_REQUEST_TIMEOUT,
122
+ connectionTimeout: config_1.default.getCurrent().DEFAULT_CONNECTION_TIMEOUT,
123
+ };
121
124
  return transport.manifest.loadManifest(resource.url, manOpts, cancelSignal);
122
125
  }
123
126
  });
@@ -139,13 +139,15 @@ function default_1(transportOptions) {
139
139
  var isMP4 = (0, is_mp4_embedded_track_1.default)(context.mimeType);
140
140
  if (!isMP4) {
141
141
  return (0, request_1.default)({ url: url, responseType: "text",
142
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
142
+ timeout: loaderOptions.timeout,
143
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
143
144
  .then(function (data) { return ({ resultType: "segment-loaded",
144
145
  resultData: data }); });
145
146
  }
146
147
  else {
147
148
  return (0, request_1.default)({ url: url, responseType: "arraybuffer",
148
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
149
+ timeout: loaderOptions.timeout,
150
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
149
151
  .then(function (data) {
150
152
  if (transportOptions.checkMediaSegmentIntegrity !== true) {
151
153
  return { resultType: "segment-loaded",
@@ -49,7 +49,8 @@ function regularSegmentLoader(url, context, callbacks, loaderOptions, cancelSign
49
49
  if (Array.isArray(range)) {
50
50
  headers = { Range: (0, byte_range_1.default)(range) };
51
51
  }
52
- return (0, request_1.default)({ url: url, responseType: "arraybuffer", headers: headers, timeout: loaderOptions.timeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
52
+ return (0, request_1.default)({ url: url, responseType: "arraybuffer", headers: headers, timeout: loaderOptions.timeout,
53
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal, onProgress: callbacks.onProgress })
53
54
  .then(function (data) {
54
55
  var isMP4 = (0, is_mp4_embedded_track_1.default)(context.mimeType);
55
56
  if (!isMP4 || checkMediaSegmentIntegrity !== true) {
@@ -135,6 +135,12 @@ export interface IManifestLoaderOptions {
135
135
  * `undefined` means that no timeout will be enforced.
136
136
  */
137
137
  timeout?: number | undefined;
138
+ /**
139
+ * Connection timeout, in milliseconds, after which the request is canceled
140
+ * if the responses headers has not being received.
141
+ * Do not set or set to "undefined" to disable it.
142
+ */
143
+ connectionTimeout?: number | undefined;
138
144
  }
139
145
  /** Functions allowing to load and parse segments of any type. */
140
146
  export interface ISegmentPipeline<TLoadedFormat, TParsedSegmentDataFormat> {
@@ -168,6 +174,12 @@ export interface ISegmentLoaderOptions {
168
174
  * `undefined` means that no timeout will be enforced.
169
175
  */
170
176
  timeout?: number | undefined;
177
+ /**
178
+ * Connection timeout, in milliseconds, after which the request is canceled
179
+ * if the responses headers has not being received.
180
+ * Do not set or set to "undefined" to disable it.
181
+ */
182
+ connectionTimeout?: number | undefined;
171
183
  }
172
184
  /**
173
185
  * Segment parser function, allowing to parse a chunk (which may be a sub-part
@@ -34,13 +34,16 @@ function generateRegularManifestLoader(preferredType) {
34
34
  switch (preferredType) {
35
35
  case "arraybuffer":
36
36
  return (0, request_1.default)({ url: url, responseType: "arraybuffer",
37
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal });
37
+ timeout: loaderOptions.timeout,
38
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal });
38
39
  case "text":
39
40
  return (0, request_1.default)({ url: url, responseType: "text",
40
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal });
41
+ timeout: loaderOptions.timeout,
42
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal });
41
43
  case "document":
42
44
  return (0, request_1.default)({ url: url, responseType: "document",
43
- timeout: loaderOptions.timeout, cancelSignal: cancelSignal });
45
+ timeout: loaderOptions.timeout,
46
+ connectionTimeout: loaderOptions.connectionTimeout, cancelSignal: cancelSignal });
44
47
  default:
45
48
  (0, assert_unreachable_1.default)(preferredType);
46
49
  }
@@ -67,6 +67,12 @@ export interface IFetchOptions {
67
67
  * if not all data has been received yet.
68
68
  */
69
69
  timeout?: number | undefined;
70
+ /**
71
+ * Optional connection timeout, in milliseconds, after which the request is canceled
72
+ * if the responses headers has not being received.
73
+ * Do not set or set to "undefined" to disable it.
74
+ */
75
+ connectionTimeout?: number | undefined;
70
76
  }
71
77
  export default function fetchRequest(options: IFetchOptions): Promise<IFetchedStreamComplete>;
72
78
  /**
@@ -79,7 +79,8 @@ function fetchRequest(options) {
79
79
  }
80
80
  log_1.default.debug("Fetch: Called with URL", options.url);
81
81
  var cancellation = null;
82
- var timeouted = false;
82
+ var isTimedOut = false;
83
+ var isConnectionTimedOut = false;
83
84
  var sendingTime = (0, monotonic_timestamp_1.default)();
84
85
  var abortController = !(0, is_null_or_undefined_1.default)(_AbortController) ? new _AbortController() :
85
86
  null;
@@ -94,13 +95,26 @@ function fetchRequest(options) {
94
95
  }
95
96
  abortController.abort();
96
97
  }
97
- var timeout;
98
+ var timeoutId;
98
99
  if (options.timeout !== undefined) {
99
- timeout = setTimeout(function () {
100
- timeouted = true;
100
+ timeoutId = setTimeout(function () {
101
+ isTimedOut = true;
102
+ if (connectionTimeoutId !== undefined) {
103
+ clearTimeout(connectionTimeoutId);
104
+ }
101
105
  abortFetch();
102
106
  }, options.timeout);
103
107
  }
108
+ var connectionTimeoutId;
109
+ if (options.connectionTimeout !== undefined) {
110
+ connectionTimeoutId = setTimeout(function () {
111
+ isConnectionTimedOut = true;
112
+ if (timeoutId !== undefined) {
113
+ clearTimeout(timeoutId);
114
+ }
115
+ abortFetch();
116
+ }, options.connectionTimeout);
117
+ }
104
118
  var deregisterCancelLstnr = options.cancelSignal
105
119
  .register(function abortRequest(err) {
106
120
  cancellation = err;
@@ -113,8 +127,8 @@ function fetchRequest(options) {
113
127
  fetchOpts.signal = !(0, is_null_or_undefined_1.default)(abortController) ? abortController.signal :
114
128
  null;
115
129
  return fetch(options.url, fetchOpts).then(function (response) {
116
- if (!(0, is_null_or_undefined_1.default)(timeout)) {
117
- clearTimeout(timeout);
130
+ if (connectionTimeoutId !== undefined) {
131
+ clearTimeout(connectionTimeoutId);
118
132
  }
119
133
  if (response.status >= 300) {
120
134
  log_1.default.warn("Fetch: Request HTTP Error", response.status, response.url);
@@ -147,6 +161,9 @@ function fetchRequest(options) {
147
161
  return [2 /*return*/, readBufferAndSendEvents()];
148
162
  }
149
163
  else if (data.done) {
164
+ if (timeoutId !== undefined) {
165
+ clearTimeout(timeoutId);
166
+ }
150
167
  deregisterCancelLstnr();
151
168
  receivedTime = (0, monotonic_timestamp_1.default)();
152
169
  requestDuration = receivedTime - sendingTime;
@@ -163,8 +180,12 @@ function fetchRequest(options) {
163
180
  throw cancellation;
164
181
  }
165
182
  deregisterCancelLstnr();
166
- if (timeouted) {
167
- log_1.default.warn("Fetch: Request timeouted.");
183
+ if (isTimedOut) {
184
+ log_1.default.warn("Fetch: Request timed out.");
185
+ throw new errors_1.RequestError(options.url, 0, errors_1.NetworkErrorTypes.TIMEOUT);
186
+ }
187
+ else if (isConnectionTimedOut) {
188
+ log_1.default.warn("Fetch: Request connection timed out.");
168
189
  throw new errors_1.RequestError(options.url, 0, errors_1.NetworkErrorTypes.TIMEOUT);
169
190
  }
170
191
  else if (err instanceof errors_1.RequestError) {
@@ -18,14 +18,14 @@ import { CancellationSignal } from "../task_canceller";
18
18
  * Perform an HTTP request, according to the options given.
19
19
  *
20
20
  * Several errors can be rejected. Namely:
21
- * - RequestErrorTypes.TIMEOUT_ERROR: the request timeouted (took too long to
22
- * respond).
23
- * - RequestErrorTypes.PARSE_ERROR: the browser APIs used to parse the
21
+ * - NetworkErrorTypes.TIMEOUT: the request timed out (took too long)
22
+ *
23
+ * - NetworkErrorTypes.PARSE_ERROR: the browser APIs used to parse the
24
24
  * data failed.
25
- * - RequestErrorTypes.ERROR_HTTP_CODE: the HTTP code at the time of reception
25
+ * - NetworkErrorTypes.ERROR_HTTP_CODE: the HTTP code at the time of reception
26
26
  * was not in the 200-299 (included)
27
27
  * range.
28
- * - RequestErrorTypes.ERROR_EVENT: The XHR had an error event before the
28
+ * - NetworkErrorTypes.ERROR_EVENT: The XHR had an error event before the
29
29
  * response could be fetched.
30
30
  * @param {Object} options
31
31
  * @returns {Promise.<Object>}
@@ -50,6 +50,12 @@ export interface IRequestOptions<ResponseType> {
50
50
  * To not set or to set to `undefined` for disable.
51
51
  */
52
52
  timeout?: number | undefined;
53
+ /**
54
+ * Optional connection timeout, in milliseconds, after which the request is canceled
55
+ * if the responses headers has not being received.
56
+ * Do not set or set to "undefined" to disable it.
57
+ */
58
+ connectionTimeout?: number | undefined;
53
59
  /**
54
60
  * "Cancelation token" used to be able to cancel the request.
55
61
  * When this token is "cancelled", the request will be aborted and the Promise
@@ -27,10 +27,11 @@ function request(options) {
27
27
  responseType: (0, is_null_or_undefined_1.default)(options.responseType) ? DEFAULT_RESPONSE_TYPE :
28
28
  options.responseType,
29
29
  timeout: options.timeout,
30
+ connectionTimeout: options.connectionTimeout,
30
31
  };
31
32
  return new Promise(function (resolve, reject) {
32
33
  var onProgress = options.onProgress, cancelSignal = options.cancelSignal;
33
- var url = requestOptions.url, headers = requestOptions.headers, responseType = requestOptions.responseType, timeout = requestOptions.timeout;
34
+ var url = requestOptions.url, headers = requestOptions.headers, responseType = requestOptions.responseType, timeout = requestOptions.timeout, connectionTimeout = requestOptions.connectionTimeout;
34
35
  var xhr = new XMLHttpRequest();
35
36
  xhr.open("GET", url, true);
36
37
  var timeoutId;
@@ -44,9 +45,19 @@ function request(options) {
44
45
  // is more precise, it might also be more efficient.
45
46
  timeoutId = setTimeout(function () {
46
47
  clearCancellingProcess();
47
- reject(new errors_1.RequestError(url, xhr.status, "TIMEOUT"));
48
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.TIMEOUT));
48
49
  }, timeout + 3000);
49
50
  }
51
+ var connectionTimeoutId;
52
+ if (connectionTimeout !== undefined) {
53
+ connectionTimeoutId = setTimeout(function () {
54
+ clearCancellingProcess();
55
+ if (xhr.readyState !== XMLHttpRequest.DONE) {
56
+ xhr.abort();
57
+ }
58
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.TIMEOUT));
59
+ }, connectionTimeout);
60
+ }
50
61
  xhr.responseType = responseType;
51
62
  if (xhr.responseType === "document") {
52
63
  xhr.overrideMimeType("text/xml");
@@ -66,7 +77,7 @@ function request(options) {
66
77
  deregisterCancellationListener = cancelSignal
67
78
  .register(function abortRequest(err) {
68
79
  clearCancellingProcess();
69
- if (!(0, is_null_or_undefined_1.default)(xhr) && xhr.readyState !== 4) {
80
+ if (xhr.readyState !== XMLHttpRequest.DONE) {
70
81
  xhr.abort();
71
82
  }
72
83
  reject(err);
@@ -77,12 +88,19 @@ function request(options) {
77
88
  }
78
89
  xhr.onerror = function onXHRError() {
79
90
  clearCancellingProcess();
80
- reject(new errors_1.RequestError(url, xhr.status, "ERROR_EVENT"));
91
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.ERROR_EVENT));
81
92
  };
82
93
  xhr.ontimeout = function onXHRTimeout() {
83
94
  clearCancellingProcess();
84
- reject(new errors_1.RequestError(url, xhr.status, "TIMEOUT"));
95
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.TIMEOUT));
85
96
  };
97
+ if (connectionTimeout !== undefined) {
98
+ xhr.onreadystatechange = function clearConnectionTimeout() {
99
+ if (xhr.readyState >= XMLHttpRequest.HEADERS_RECEIVED) {
100
+ clearTimeout(connectionTimeoutId);
101
+ }
102
+ };
103
+ }
86
104
  if (onProgress !== undefined) {
87
105
  xhr.onprogress = function onXHRProgress(event) {
88
106
  var currentTime = (0, monotonic_timestamp_1.default)();
@@ -91,7 +109,7 @@ function request(options) {
91
109
  };
92
110
  }
93
111
  xhr.onload = function onXHRLoad(event) {
94
- if (xhr.readyState === 4) {
112
+ if (xhr.readyState === XMLHttpRequest.DONE) {
95
113
  clearCancellingProcess();
96
114
  if (xhr.status >= 200 && xhr.status < 300) {
97
115
  var receivedTime = (0, monotonic_timestamp_1.default)();
@@ -115,7 +133,7 @@ function request(options) {
115
133
  responseData = xhr.response;
116
134
  }
117
135
  if ((0, is_null_or_undefined_1.default)(responseData)) {
118
- reject(new errors_1.RequestError(url, xhr.status, "PARSE_ERROR"));
136
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.PARSE_ERROR));
119
137
  return;
120
138
  }
121
139
  resolve({ status: status_1, url: _url,
@@ -123,7 +141,7 @@ function request(options) {
123
141
  size: totalSize, responseData: responseData });
124
142
  }
125
143
  else {
126
- reject(new errors_1.RequestError(url, xhr.status, "ERROR_HTTP_CODE"));
144
+ reject(new errors_1.RequestError(url, xhr.status, errors_1.NetworkErrorTypes.ERROR_HTTP_CODE));
127
145
  }
128
146
  }
129
147
  };
@@ -135,6 +153,9 @@ function request(options) {
135
153
  if (timeoutId !== undefined) {
136
154
  clearTimeout(timeoutId);
137
155
  }
156
+ if (connectionTimeoutId !== undefined) {
157
+ clearTimeout(connectionTimeoutId);
158
+ }
138
159
  if (deregisterCancellationListener !== null) {
139
160
  deregisterCancellationListener();
140
161
  }
@@ -14,6 +14,16 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { MediaSource_ } from "./browser_compatibility_types";
17
+ /**
18
+ * Setting this value limit the number of entries in the support map
19
+ * preventing important memory usage, value is arbitrary
20
+ */
21
+ const MAX_SUPPORT_MAP_ENTRIES = 200;
22
+ /**
23
+ * caching the codec support reduce the amount of call to `isTypeSupported`
24
+ * and help for performance especially on low-end devices.
25
+ */
26
+ const supportMap = new Map();
17
27
  /**
18
28
  * Returns true if the given codec is supported by the browser's MediaSource
19
29
  * implementation.
@@ -30,7 +40,18 @@ export default function isCodecSupported(mimeType) {
30
40
  /* eslint-disable @typescript-eslint/unbound-method */
31
41
  if (typeof MediaSource_.isTypeSupported === "function") {
32
42
  /* eslint-enable @typescript-eslint/unbound-method */
33
- return MediaSource_.isTypeSupported(mimeType);
43
+ const cachedSupport = supportMap.get(mimeType);
44
+ if (cachedSupport !== undefined) {
45
+ return cachedSupport;
46
+ }
47
+ else {
48
+ const isSupported = MediaSource_.isTypeSupported(mimeType);
49
+ if (supportMap.size >= MAX_SUPPORT_MAP_ENTRIES) {
50
+ supportMap.clear();
51
+ }
52
+ supportMap.set(mimeType, isSupported);
53
+ return isSupported;
54
+ }
34
55
  }
35
56
  return true;
36
57
  }