rx-player 4.0.0-beta.0 → 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 (297) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +93 -0
  3. package/CONTRIBUTING.md +48 -168
  4. package/FILES.md +40 -92
  5. package/VERSION +1 -1
  6. package/dist/_esm5.processed/compat/browser_detection.d.ts +25 -12
  7. package/dist/_esm5.processed/compat/browser_detection.js +85 -38
  8. package/dist/_esm5.processed/compat/can_reuse_media_keys.js +2 -2
  9. package/dist/_esm5.processed/compat/eme/close_session.js +2 -2
  10. package/dist/_esm5.processed/compat/eme/load_session.js +1 -1
  11. package/dist/_esm5.processed/compat/event_listeners.js +1 -1
  12. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.d.ts +21 -0
  13. package/dist/_esm5.processed/compat/has_issues_with_high_media_source_duration.js +26 -0
  14. package/dist/_esm5.processed/config.d.ts +4 -0
  15. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +9 -6
  16. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.d.ts +18 -1
  17. package/dist/_esm5.processed/core/adaptive/buffer_based_chooser.js +106 -25
  18. package/dist/_esm5.processed/core/adaptive/guess_based_chooser.js +6 -6
  19. package/dist/_esm5.processed/core/adaptive/network_analyzer.js +8 -5
  20. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.d.ts +19 -1
  21. package/dist/_esm5.processed/core/adaptive/utils/representation_score_calculator.js +1 -1
  22. package/dist/_esm5.processed/core/api/debug/buffer_graph.d.ts +28 -0
  23. package/dist/_esm5.processed/core/api/debug/buffer_graph.js +175 -0
  24. package/dist/_esm5.processed/core/api/debug/buffer_size_graph.d.ts +10 -0
  25. package/dist/_esm5.processed/core/api/debug/buffer_size_graph.js +104 -0
  26. package/dist/_esm5.processed/core/api/debug/constants.d.ts +2 -0
  27. package/dist/_esm5.processed/core/api/debug/constants.js +2 -0
  28. package/dist/_esm5.processed/core/api/debug/index.d.ts +2 -0
  29. package/dist/_esm5.processed/core/api/debug/index.js +2 -0
  30. package/dist/_esm5.processed/core/api/debug/modules/general_info.d.ts +3 -0
  31. package/dist/_esm5.processed/core/api/debug/modules/general_info.js +180 -0
  32. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.d.ts +4 -0
  33. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.js +121 -0
  34. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.d.ts +3 -0
  35. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.js +35 -0
  36. package/dist/_esm5.processed/core/api/debug/render.d.ts +3 -0
  37. package/dist/_esm5.processed/core/api/debug/render.js +32 -0
  38. package/dist/_esm5.processed/core/api/debug/utils.d.ts +39 -0
  39. package/dist/_esm5.processed/core/api/debug/utils.js +57 -0
  40. package/dist/_esm5.processed/core/api/playback_observer.js +4 -2
  41. package/dist/_esm5.processed/core/api/public_api.d.ts +60 -3
  42. package/dist/_esm5.processed/core/api/public_api.js +280 -60
  43. package/dist/_esm5.processed/core/api/track_management/media_element_tracks_store.js +10 -1
  44. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +13 -1
  45. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +30 -15
  46. package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +3 -1
  47. package/dist/_esm5.processed/core/api/track_management/tracks_store.js +67 -152
  48. package/dist/_esm5.processed/core/api/utils.d.ts +10 -0
  49. package/dist/_esm5.processed/core/api/utils.js +23 -3
  50. package/dist/_esm5.processed/core/decrypt/__tests__/__global__/utils.d.ts +27 -8
  51. package/dist/_esm5.processed/core/decrypt/__tests__/__global__/utils.js +28 -7
  52. package/dist/_esm5.processed/core/decrypt/attach_media_keys.js +1 -1
  53. package/dist/_esm5.processed/core/decrypt/content_decryptor.js +1 -1
  54. package/dist/_esm5.processed/core/decrypt/find_key_system.js +29 -6
  55. package/dist/_esm5.processed/core/decrypt/session_events_listener.js +42 -32
  56. package/dist/_esm5.processed/core/decrypt/utils/check_key_statuses.js +4 -0
  57. package/dist/_esm5.processed/core/decrypt/utils/clean_old_loaded_sessions.js +2 -0
  58. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +5 -1
  59. package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.d.ts +17 -8
  60. package/dist/_esm5.processed/core/fetchers/cdn_prioritizer.js +10 -6
  61. package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +5 -4
  62. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +22 -5
  63. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +37 -21
  64. package/dist/_esm5.processed/core/fetchers/segment/task_prioritizer.js +21 -23
  65. package/dist/_esm5.processed/core/fetchers/utils/schedule_request.js +17 -7
  66. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +2 -2
  67. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +74 -41
  68. package/dist/_esm5.processed/core/init/types.d.ts +9 -1
  69. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.d.ts +28 -1
  70. package/dist/_esm5.processed/core/init/utils/content_time_boundaries_observer.js +24 -11
  71. package/dist/_esm5.processed/core/init/utils/create_media_source.js +3 -12
  72. package/dist/_esm5.processed/core/init/utils/end_of_stream.js +6 -3
  73. package/dist/_esm5.processed/core/init/utils/get_loaded_reference.js +2 -1
  74. package/dist/_esm5.processed/core/init/utils/initial_seek_and_play.js +9 -5
  75. package/dist/_esm5.processed/core/init/utils/initialize_content_decryption.js +2 -1
  76. package/dist/_esm5.processed/core/init/utils/media_source_duration_updater.d.ts +58 -0
  77. package/dist/_esm5.processed/core/init/utils/{media_duration_updater.js → media_source_duration_updater.js} +87 -86
  78. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +36 -2
  79. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +83 -3
  80. package/dist/_esm5.processed/core/init/utils/stream_events_emitter/stream_events_emitter.js +6 -4
  81. package/dist/_esm5.processed/core/init/utils/throw_on_media_error.js +1 -1
  82. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.d.ts +18 -7
  83. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +38 -50
  84. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.d.ts +8 -0
  85. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +16 -2
  86. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +8 -0
  87. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +12 -0
  88. package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +11 -4
  89. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  90. package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.js +13 -9
  91. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.js +30 -16
  92. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.d.ts +47 -0
  93. package/dist/_esm5.processed/core/stream/adaptation/utils/create_representation_estimator.js +70 -0
  94. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +41 -20
  95. package/dist/_esm5.processed/core/stream/period/period_stream.js +12 -11
  96. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +37 -28
  97. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.d.ts +4 -2
  98. package/dist/_esm5.processed/core/stream/representation/utils/append_segment_to_buffer.js +3 -3
  99. package/dist/_esm5.processed/core/stream/representation/utils/downloading_queue.js +16 -6
  100. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.d.ts +3 -2
  101. package/dist/_esm5.processed/core/stream/representation/utils/push_init_segment.js +8 -8
  102. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.d.ts +2 -2
  103. package/dist/_esm5.processed/core/stream/representation/utils/push_media_segment.js +2 -3
  104. package/dist/_esm5.processed/core/stream/utils/create_reload_request.js +1 -1
  105. package/dist/_esm5.processed/default_config.d.ts +41 -0
  106. package/dist/_esm5.processed/default_config.js +46 -2
  107. package/dist/_esm5.processed/errors/index.d.ts +2 -2
  108. package/dist/_esm5.processed/errors/media_error.d.ts +23 -1
  109. package/dist/_esm5.processed/errors/media_error.js +18 -5
  110. package/dist/_esm5.processed/experimental/features/debug_element.d.ts +8 -0
  111. package/dist/_esm5.processed/experimental/features/debug_element.js +10 -0
  112. package/dist/_esm5.processed/experimental/features/index.d.ts +1 -0
  113. package/dist/_esm5.processed/experimental/features/index.js +1 -0
  114. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.d.ts +1 -1
  115. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/load_and_push_segment.js +8 -7
  116. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.js +7 -4
  117. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +24 -12
  118. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/index.js +0 -2
  119. package/dist/_esm5.processed/features/features_object.js +1 -0
  120. package/dist/_esm5.processed/features/initialize_features.js +13 -10
  121. package/dist/_esm5.processed/features/types.d.ts +3 -0
  122. package/dist/_esm5.processed/manifest/adaptation.d.ts +21 -2
  123. package/dist/_esm5.processed/manifest/adaptation.js +80 -1
  124. package/dist/_esm5.processed/manifest/manifest.js +2 -0
  125. package/dist/_esm5.processed/manifest/period.js +2 -2
  126. package/dist/_esm5.processed/manifest/representation.d.ts +33 -2
  127. package/dist/_esm5.processed/manifest/representation.js +32 -4
  128. package/dist/_esm5.processed/manifest/utils.js +1 -3
  129. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_adaptation_sets.js +105 -137
  130. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representations.js +25 -5
  131. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.d.ts +1 -1
  132. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/parse_from_document.js +1 -1
  133. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.js +1 -0
  134. package/dist/_esm5.processed/public_types.d.ts +13 -3
  135. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +1 -1
  136. package/dist/_esm5.processed/transports/dash/add_segment_integrity_checks_to_loader.js +15 -11
  137. package/dist/_esm5.processed/transports/dash/low_latency_segment_loader.js +2 -2
  138. package/dist/_esm5.processed/transports/dash/manifest_parser.js +1 -1
  139. package/dist/_esm5.processed/transports/dash/segment_loader.js +4 -4
  140. package/dist/_esm5.processed/transports/local/segment_loader.js +13 -26
  141. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.d.ts +4 -6
  142. package/dist/_esm5.processed/transports/smooth/isobmff/create_boxes.js +4 -6
  143. package/dist/_esm5.processed/transports/smooth/segment_loader.js +4 -4
  144. package/dist/_esm5.processed/transports/utils/call_custom_manifest_loader.js +3 -3
  145. package/dist/_esm5.processed/utils/cancellable_sleep.js +4 -10
  146. package/dist/_esm5.processed/utils/create_cancellable_promise.d.ts +26 -0
  147. package/dist/_esm5.processed/utils/create_cancellable_promise.js +52 -0
  148. package/dist/_esm5.processed/utils/is_null_or_undefined.d.ts +1 -1
  149. package/dist/_esm5.processed/utils/is_null_or_undefined.js +1 -1
  150. package/dist/_esm5.processed/utils/reference.js +6 -0
  151. package/dist/_esm5.processed/utils/request/xhr.js +1 -1
  152. package/dist/_esm5.processed/utils/task_canceller.d.ts +34 -15
  153. package/dist/_esm5.processed/utils/task_canceller.js +55 -22
  154. package/dist/mpd-parser.wasm +0 -0
  155. package/dist/rx-player.js +5424 -4712
  156. package/dist/rx-player.min.js +1 -1
  157. package/jest.config.js +1 -5
  158. package/package.json +44 -40
  159. package/scripts/build/constants.d.ts +1 -0
  160. package/scripts/build/generate_build.js +1 -1
  161. package/scripts/fast_demo_build.js +40 -40
  162. package/scripts/generate_full_demo.js +1 -1
  163. package/sonar-project.properties +1 -1
  164. package/src/compat/browser_detection.ts +105 -52
  165. package/src/compat/can_reuse_media_keys.ts +5 -2
  166. package/src/compat/eme/close_session.ts +2 -2
  167. package/src/compat/eme/load_session.ts +1 -1
  168. package/src/compat/event_listeners.ts +1 -1
  169. package/src/compat/has_issues_with_high_media_source_duration.ts +27 -0
  170. package/src/core/adaptive/__tests__/buffer_based_chooser.test.ts +147 -48
  171. package/src/core/adaptive/adaptive_representation_selector.ts +11 -6
  172. package/src/core/adaptive/buffer_based_chooser.ts +144 -26
  173. package/src/core/adaptive/guess_based_chooser.ts +9 -8
  174. package/src/core/adaptive/network_analyzer.ts +9 -4
  175. package/src/core/adaptive/utils/representation_score_calculator.ts +22 -2
  176. package/src/core/api/debug/buffer_graph.ts +247 -0
  177. package/src/core/api/debug/buffer_size_graph.ts +130 -0
  178. package/src/core/api/debug/constants.ts +2 -0
  179. package/src/core/api/debug/index.ts +3 -0
  180. package/src/core/api/debug/modules/general_info.ts +184 -0
  181. package/src/core/api/debug/modules/segment_buffer_content.ts +155 -0
  182. package/src/core/api/debug/modules/segment_buffer_size.ts +48 -0
  183. package/src/core/api/debug/render.ts +40 -0
  184. package/src/core/api/debug/utils.ts +103 -0
  185. package/src/core/api/playback_observer.ts +5 -2
  186. package/src/core/api/public_api.ts +334 -73
  187. package/src/core/api/track_management/media_element_tracks_store.ts +17 -8
  188. package/src/core/api/track_management/track_dispatcher.ts +37 -14
  189. package/src/core/api/track_management/tracks_store.ts +77 -167
  190. package/src/core/api/utils.ts +29 -3
  191. package/src/core/decrypt/__tests__/__global__/utils.ts +61 -40
  192. package/src/core/decrypt/attach_media_keys.ts +1 -1
  193. package/src/core/decrypt/content_decryptor.ts +1 -1
  194. package/src/core/decrypt/find_key_system.ts +25 -11
  195. package/src/core/decrypt/session_events_listener.ts +45 -39
  196. package/src/core/decrypt/utils/check_key_statuses.ts +6 -0
  197. package/src/core/decrypt/utils/clean_old_loaded_sessions.ts +2 -1
  198. package/src/core/decrypt/utils/loaded_sessions_store.ts +8 -1
  199. package/src/core/fetchers/cdn_prioritizer.ts +18 -9
  200. package/src/core/fetchers/manifest/manifest_fetcher.ts +5 -4
  201. package/src/core/fetchers/segment/segment_fetcher.ts +36 -14
  202. package/src/core/fetchers/segment/task_prioritizer.ts +25 -30
  203. package/src/core/fetchers/utils/schedule_request.ts +18 -7
  204. package/src/core/init/directfile_content_initializer.ts +2 -1
  205. package/src/core/init/media_source_content_initializer.ts +89 -50
  206. package/src/core/init/types.ts +9 -1
  207. package/src/core/init/utils/content_time_boundaries_observer.ts +48 -12
  208. package/src/core/init/utils/create_media_source.ts +4 -16
  209. package/src/core/init/utils/end_of_stream.ts +6 -3
  210. package/src/core/init/utils/get_loaded_reference.ts +2 -1
  211. package/src/core/init/utils/initial_seek_and_play.ts +9 -5
  212. package/src/core/init/utils/initialize_content_decryption.ts +2 -1
  213. package/src/core/init/utils/{media_duration_updater.ts → media_source_duration_updater.ts} +103 -110
  214. package/src/core/init/utils/rebuffering_controller.ts +115 -4
  215. package/src/core/init/utils/stream_events_emitter/stream_events_emitter.ts +6 -4
  216. package/src/core/init/utils/throw_on_media_error.ts +1 -1
  217. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +63 -66
  218. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +20 -2
  219. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +16 -0
  220. package/src/core/segment_buffers/implementations/types.ts +16 -4
  221. package/src/core/segment_buffers/index.ts +2 -0
  222. package/src/core/segment_buffers/segment_buffers_store.ts +16 -13
  223. package/src/core/stream/adaptation/adaptation_stream.ts +33 -19
  224. package/src/core/stream/adaptation/utils/create_representation_estimator.ts +114 -0
  225. package/src/core/stream/orchestrator/stream_orchestrator.ts +42 -20
  226. package/src/core/stream/period/period_stream.ts +13 -11
  227. package/src/core/stream/representation/representation_stream.ts +49 -37
  228. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +9 -4
  229. package/src/core/stream/representation/utils/downloading_queue.ts +16 -4
  230. package/src/core/stream/representation/utils/push_init_segment.ts +11 -6
  231. package/src/core/stream/representation/utils/push_media_segment.ts +3 -3
  232. package/src/core/stream/utils/create_reload_request.ts +1 -1
  233. package/src/default_config.ts +59 -11
  234. package/src/errors/__tests__/media_error.test.ts +6 -6
  235. package/src/errors/index.ts +4 -1
  236. package/src/errors/media_error.ts +67 -1
  237. package/src/experimental/features/__tests__/debug_element.test.ts +26 -0
  238. package/src/experimental/features/debug_element.ts +13 -0
  239. package/src/experimental/features/index.ts +1 -0
  240. package/src/experimental/tools/VideoThumbnailLoader/load_and_push_segment.ts +10 -7
  241. package/src/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.ts +7 -4
  242. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +25 -10
  243. package/src/experimental/tools/mediaCapabilitiesProber/index.ts +0 -4
  244. package/src/features/__tests__/initialize_features.test.ts +11 -0
  245. package/src/features/features_object.ts +1 -0
  246. package/src/features/initialize_features.ts +15 -10
  247. package/src/features/types.ts +9 -0
  248. package/src/manifest/__tests__/manifest.test.ts +7 -7
  249. package/src/manifest/__tests__/period.test.ts +90 -45
  250. package/src/manifest/adaptation.ts +96 -1
  251. package/src/manifest/manifest.ts +4 -0
  252. package/src/manifest/period.ts +4 -2
  253. package/src/manifest/representation.ts +77 -5
  254. package/src/manifest/utils.ts +1 -3
  255. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +116 -151
  256. package/src/parsers/manifest/dash/common/parse_representations.ts +21 -4
  257. package/src/parsers/manifest/dash/js-parser/parse_from_document.ts +1 -1
  258. package/src/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.ts +1 -0
  259. package/src/parsers/texttracks/ttml/parse_ttml.ts +1 -1
  260. package/src/public_types.ts +16 -1
  261. package/src/tools/TextTrackRenderer/text_track_renderer.ts +1 -1
  262. package/src/transports/dash/add_segment_integrity_checks_to_loader.ts +31 -22
  263. package/src/transports/dash/low_latency_segment_loader.ts +2 -2
  264. package/src/transports/dash/manifest_parser.ts +1 -1
  265. package/src/transports/dash/segment_loader.ts +4 -4
  266. package/src/transports/local/segment_loader.ts +14 -30
  267. package/src/transports/smooth/isobmff/create_boxes.ts +4 -6
  268. package/src/transports/smooth/segment_loader.ts +4 -4
  269. package/src/transports/utils/call_custom_manifest_loader.ts +3 -3
  270. package/src/typings/globals.d.ts +21 -19
  271. package/src/utils/cancellable_sleep.ts +5 -14
  272. package/src/utils/create_cancellable_promise.ts +69 -0
  273. package/src/utils/is_null_or_undefined.ts +1 -1
  274. package/src/utils/reference.ts +6 -0
  275. package/src/utils/request/xhr.ts +1 -1
  276. package/src/utils/task_canceller.ts +63 -34
  277. package/tsconfig.json +1 -1
  278. package/tsconfig.modules.json +1 -1
  279. package/dist/_esm5.processed/core/init/utils/media_duration_updater.d.ts +0 -56
  280. package/locked_reps.js +0 -46
  281. package/scripts/doc-generator/construct_table_of_contents.js +0 -76
  282. package/scripts/doc-generator/convert_MD_to_HMTL.js +0 -26
  283. package/scripts/doc-generator/create_documentation.js +0 -331
  284. package/scripts/doc-generator/create_documentation_page.js +0 -209
  285. package/scripts/doc-generator/create_page.js +0 -210
  286. package/scripts/doc-generator/generate_header_html.js +0 -147
  287. package/scripts/doc-generator/generate_page_html.js +0 -115
  288. package/scripts/doc-generator/generate_page_list_html.js +0 -92
  289. package/scripts/doc-generator/generate_sidebar_html.js +0 -85
  290. package/scripts/doc-generator/get_search_data_for_content.js +0 -137
  291. package/scripts/doc-generator/index.js +0 -34
  292. package/scripts/doc-generator/parse_doc_configs.js +0 -327
  293. package/scripts/doc-generator/scripts/lunr.js +0 -10
  294. package/scripts/doc-generator/scripts/script.js +0 -451
  295. package/scripts/doc-generator/styles/code.css +0 -99
  296. package/scripts/doc-generator/styles/style.css +0 -835
  297. package/scripts/doc-generator/utils.js +0 -74
@@ -87,7 +87,7 @@ export default function attachMediaKeys(mediaElement, _a, cancelSignal) {
87
87
  _b.sent();
88
88
  // If this task has been cancelled while we were closing previous sessions,
89
89
  // stop now (and thus avoid setting the new media keys);
90
- if (cancelSignal.isCancelled) {
90
+ if (cancelSignal.isCancelled()) {
91
91
  throw cancelSignal.cancellationError;
92
92
  }
93
93
  MediaKeysInfosStore.setState(mediaElement, { keySystemOptions: keySystemOptions, mediaKeySystemAccess: mediaKeySystemAccess, mediaKeys: mediaKeys, loadedSessionsStore: loadedSessionsStore });
@@ -614,7 +614,7 @@ var ContentDecryptor = /** @class */ (function (_super) {
614
614
  * formatted and sent in an "error" event.
615
615
  */
616
616
  ContentDecryptor.prototype._onFatalError = function (err) {
617
- if (this._canceller.isUsed) {
617
+ if (this._canceller.isUsed()) {
618
618
  return;
619
619
  }
620
620
  var formattedErr = err instanceof Error ?
@@ -13,6 +13,17 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
16
27
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
28
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
29
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -127,7 +138,7 @@ function buildKeySystemConfigurations(keySystemTypeInfo) {
127
138
  if (!isNullOrUndefined(keySystem.distinctiveIdentifier)) {
128
139
  distinctiveIdentifier = keySystem.distinctiveIdentifier;
129
140
  }
130
- var _a = config.getCurrent(), EME_DEFAULT_WIDEVINE_ROBUSTNESSES = _a.EME_DEFAULT_WIDEVINE_ROBUSTNESSES, EME_DEFAULT_PLAYREADY_RECOMMENDATION_ROBUSTNESSES = _a.EME_DEFAULT_PLAYREADY_RECOMMENDATION_ROBUSTNESSES;
141
+ var _a = config.getCurrent(), EME_DEFAULT_AUDIO_CODECS = _a.EME_DEFAULT_AUDIO_CODECS, EME_DEFAULT_VIDEO_CODECS = _a.EME_DEFAULT_VIDEO_CODECS, EME_DEFAULT_WIDEVINE_ROBUSTNESSES = _a.EME_DEFAULT_WIDEVINE_ROBUSTNESSES, EME_DEFAULT_PLAYREADY_RECOMMENDATION_ROBUSTNESSES = _a.EME_DEFAULT_PLAYREADY_RECOMMENDATION_ROBUSTNESSES;
131
142
  // From the W3 EME spec, we have to provide videoCapabilities and
132
143
  // audioCapabilities.
133
144
  // These capabilities must specify a codec (even though you can use a
@@ -164,7 +175,7 @@ function buildKeySystemConfigurations(keySystemTypeInfo) {
164
175
  }
165
176
  var audioCodecs_1 = (audioCapabilitiesConfig === null || audioCapabilitiesConfig === void 0 ? void 0 : audioCapabilitiesConfig.type) === "contentType" ?
166
177
  audioCapabilitiesConfig.value :
167
- ["audio/mp4;codecs=\"mp4a.40.2\"", "audio/webm;codecs=opus"];
178
+ EME_DEFAULT_AUDIO_CODECS;
168
179
  audioCapabilities = flatMap(audioRobustnesses, function (robustness) {
169
180
  return audioCodecs_1.map(function (contentType) {
170
181
  return robustness !== undefined ? { contentType: contentType, robustness: robustness } :
@@ -194,9 +205,7 @@ function buildKeySystemConfigurations(keySystemTypeInfo) {
194
205
  }
195
206
  var videoCodecs_1 = (videoCapabilitiesConfig === null || videoCapabilitiesConfig === void 0 ? void 0 : videoCapabilitiesConfig.type) === "contentType" ?
196
207
  videoCapabilitiesConfig.value :
197
- ["video/mp4;codecs=\"avc1.4d401e\"",
198
- "video/mp4;codecs=\"avc1.42e01e\"",
199
- "video/webm;codecs=\"vp8\""];
208
+ EME_DEFAULT_VIDEO_CODECS;
200
209
  videoCapabilities = flatMap(videoRobustnesses, function (robustness) {
201
210
  return videoCodecs_1.map(function (contentType) {
202
211
  return robustness !== undefined ? { contentType: contentType, robustness: robustness } :
@@ -204,7 +213,21 @@ function buildKeySystemConfigurations(keySystemTypeInfo) {
204
213
  });
205
214
  });
206
215
  }
207
- return [{ initDataTypes: ["cenc"], videoCapabilities: videoCapabilities, audioCapabilities: audioCapabilities, distinctiveIdentifier: distinctiveIdentifier, persistentState: persistentState, sessionTypes: sessionTypes }];
216
+ var wantedMediaKeySystemConfiguration = {
217
+ initDataTypes: ["cenc"],
218
+ videoCapabilities: videoCapabilities,
219
+ audioCapabilities: audioCapabilities,
220
+ distinctiveIdentifier: distinctiveIdentifier,
221
+ persistentState: persistentState,
222
+ sessionTypes: sessionTypes,
223
+ };
224
+ return [
225
+ wantedMediaKeySystemConfiguration,
226
+ // Some legacy implementations have issues with `audioCapabilities` and
227
+ // `videoCapabilities`, so we're including a supplementary
228
+ // `MediaKeySystemConfiguration` without those properties.
229
+ __assign(__assign({}, wantedMediaKeySystemConfiguration), { audioCapabilities: undefined, videoCapabilities: undefined }),
230
+ ];
208
231
  }
209
232
  /**
210
233
  * Try to find a compatible key system from the keySystems array given.
@@ -86,12 +86,13 @@ export default function SessionEventsListener(session, keySystemOptions, keySyst
86
86
  log.info("DRM: Binding session events", session.sessionId);
87
87
  var _a = keySystemOptions.getLicenseConfig, getLicenseConfig = _a === void 0 ? {} : _a;
88
88
  /** Allows to manually cancel everything the `SessionEventsListener` is doing. */
89
- var manualCanceller = new TaskCanceller({ cancelOn: cancelSignal });
89
+ var manualCanceller = new TaskCanceller();
90
+ manualCanceller.linkToSignal(cancelSignal);
90
91
  if (!isNullOrUndefined(session.closed)) {
91
92
  session.closed
92
93
  .then(function () { return manualCanceller.cancel(); })
93
94
  .catch(function (err) {
94
- if (cancelSignal.isCancelled) {
95
+ if (cancelSignal.isCancelled()) {
95
96
  return;
96
97
  }
97
98
  manualCanceller.cancel();
@@ -104,11 +105,11 @@ export default function SessionEventsListener(session, keySystemOptions, keySyst
104
105
  }, manualCanceller.signal);
105
106
  onKeyStatusesChange(session, function () {
106
107
  try {
107
- handleKeyStatusesChangeEvent();
108
+ checkAndHandleCurrentKeyStatuses();
108
109
  }
109
110
  catch (error) {
110
- if (cancelSignal.isCancelled ||
111
- (manualCanceller.isUsed && error instanceof CancellationSignal)) {
111
+ if (cancelSignal.isCancelled() ||
112
+ (manualCanceller.isUsed() && error instanceof CancellationSignal)) {
112
113
  return;
113
114
  }
114
115
  manualCanceller.cancel();
@@ -125,18 +126,24 @@ export default function SessionEventsListener(session, keySystemOptions, keySyst
125
126
  var backoffOptions = getLicenseBackoffOptions(getLicenseConfig.retry);
126
127
  retryPromiseWithBackoff(function () { return runGetLicense(message, messageType); }, backoffOptions, manualCanceller.signal)
127
128
  .then(function (licenseObject) {
128
- if (manualCanceller.isUsed) {
129
+ if (manualCanceller.isUsed()) {
129
130
  return Promise.resolve();
130
131
  }
131
132
  if (isNullOrUndefined(licenseObject)) {
132
133
  log.info("DRM: No license given, skipping session.update");
133
134
  }
134
135
  else {
135
- return updateSessionWithMessage(session, licenseObject);
136
+ try {
137
+ return updateSessionWithMessage(session, licenseObject);
138
+ }
139
+ catch (err) {
140
+ manualCanceller.cancel();
141
+ callbacks.onError(err);
142
+ }
136
143
  }
137
144
  })
138
145
  .catch(function (err) {
139
- if (manualCanceller.isUsed) {
146
+ if (manualCanceller.isUsed()) {
140
147
  return;
141
148
  }
142
149
  manualCanceller.cancel();
@@ -153,56 +160,59 @@ export default function SessionEventsListener(session, keySystemOptions, keySyst
153
160
  callbacks.onError(formattedError);
154
161
  });
155
162
  }, manualCanceller.signal);
163
+ checkAndHandleCurrentKeyStatuses();
164
+ return;
156
165
  /**
157
166
  * Check current MediaKeyStatus for each key in the given MediaKeySession and:
158
167
  * - throw if at least one status is a non-recoverable error
159
168
  * - call warning callback for recoverable errors
160
169
  * - call onKeyUpdate callback when the MediaKeyStatus of any key is updated
161
170
  */
162
- function handleKeyStatusesChangeEvent() {
171
+ function checkAndHandleCurrentKeyStatuses() {
163
172
  log.info("DRM: keystatuseschange event received", session.sessionId);
164
- if (manualCanceller.isUsed || session.keyStatuses.size === 0) {
173
+ if (manualCanceller.isUsed() || session.keyStatuses.size === 0) {
165
174
  return;
166
175
  }
167
176
  var _a = checkKeyStatuses(session, keySystemOptions, keySystem), warning = _a.warning, blacklistedKeyIds = _a.blacklistedKeyIds, whitelistedKeyIds = _a.whitelistedKeyIds;
168
177
  if (warning !== undefined) {
169
178
  callbacks.onWarning(warning);
170
- if (manualCanceller.isUsed) {
179
+ if (manualCanceller.isUsed()) {
171
180
  return;
172
181
  }
173
182
  }
174
183
  callbacks.onKeyUpdate({ whitelistedKeyIds: whitelistedKeyIds, blacklistedKeyIds: blacklistedKeyIds });
175
184
  }
176
185
  function runGetLicense(message, messageType) {
186
+ var timeoutId;
177
187
  return new Promise(function (res, rej) {
178
- log.debug("DRM: Calling `getLicense`", messageType);
179
- var getLicense = keySystemOptions.getLicense(message, messageType);
180
- var getLicenseTimeout = isNullOrUndefined(getLicenseConfig.timeout) ?
181
- 10 * 1000 :
182
- getLicenseConfig.timeout;
183
- var timeoutId;
184
- if (getLicenseTimeout >= 0) {
185
- timeoutId = setTimeout(function () {
186
- rej(new GetLicenseTimeoutError("\"getLicense\" timeout exceeded (".concat(getLicenseTimeout, " ms)")));
187
- }, getLicenseTimeout);
188
- }
189
188
  try {
190
- Promise.resolve(getLicense).then(function (val) {
191
- clearTimeoutIfOne();
192
- res(val);
193
- }, function (err) {
194
- clearTimeoutIfOne();
195
- rej(err);
196
- });
189
+ log.debug("DRM: Calling `getLicense`", messageType);
190
+ var getLicense = keySystemOptions.getLicense(message, messageType);
191
+ var getLicenseTimeout_1 = isNullOrUndefined(getLicenseConfig.timeout) ?
192
+ 10 * 1000 :
193
+ getLicenseConfig.timeout;
194
+ if (getLicenseTimeout_1 >= 0) {
195
+ timeoutId = setTimeout(function () {
196
+ rej(new GetLicenseTimeoutError("\"getLicense\" timeout exceeded (".concat(getLicenseTimeout_1, " ms)")));
197
+ }, getLicenseTimeout_1);
198
+ }
199
+ Promise.resolve(getLicense)
200
+ .then(clearTimeoutAndResolve, clearTimeoutAndReject);
197
201
  }
198
202
  catch (err) {
199
- clearTimeoutIfOne();
200
- rej(err);
203
+ clearTimeoutAndReject(err);
201
204
  }
202
- function clearTimeoutIfOne() {
205
+ function clearTimeoutAndResolve(data) {
203
206
  if (timeoutId !== undefined) {
204
207
  clearTimeout(timeoutId);
205
208
  }
209
+ res(data);
210
+ }
211
+ function clearTimeoutAndReject(err) {
212
+ if (timeoutId !== undefined) {
213
+ clearTimeout(timeoutId);
214
+ }
215
+ rej(err);
206
216
  }
207
217
  });
208
218
  }
@@ -40,6 +40,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
40
  /* eslint-disable-next-line max-len */
41
41
  import getUUIDKidFromKeyStatusKID from "../../../compat/eme/get_uuid_kid_from_keystatus_kid";
42
42
  import { EncryptedMediaError } from "../../../errors";
43
+ import log from "../../../log";
43
44
  import assertUnreachable from "../../../utils/assert_unreachable";
44
45
  import { bytesToHex } from "../../../utils/string_parsing";
45
46
  /**
@@ -95,6 +96,9 @@ export default function checkKeyStatuses(session, options, keySystem) {
95
96
  })(), keyStatus = _a[0], keyStatusKeyId = _a[1];
96
97
  var keyId = getUUIDKidFromKeyStatusKID(keySystem, new Uint8Array(keyStatusKeyId));
97
98
  var keyStatusObj = { keyId: keyId.buffer, keyStatus: keyStatus };
99
+ if (log.hasLevel("DEBUG")) {
100
+ log.debug("DRM: key status update (".concat(bytesToHex(keyId), "): ").concat(keyStatus));
101
+ }
98
102
  switch (keyStatus) {
99
103
  case KEY_STATUSES.EXPIRED: {
100
104
  var error = new EncryptedMediaError("KEY_STATUS_CHANGE_ERROR", "A decryption key expired (".concat(bytesToHex(keyId), ")"), { keyStatuses: __spreadArray([keyStatusObj], badKeyStatuses, true) });
@@ -49,6 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
50
  }
51
51
  };
52
+ import log from "../../../log";
52
53
  /**
53
54
  * Close sessions from the loadedSessionsStore to allow at maximum `limit`
54
55
  * stored MediaKeySessions in it.
@@ -67,6 +68,7 @@ export default function cleanOldLoadedSessions(loadedSessionsStore, limit) {
67
68
  if (limit < 0 || limit >= loadedSessionsStore.getLength()) {
68
69
  return [2 /*return*/];
69
70
  }
71
+ log.info("DRM: LSS cache limit exceeded", limit, loadedSessionsStore.getLength());
70
72
  proms = [];
71
73
  entries = loadedSessionsStore.getAll().slice();
72
74
  toDelete = entries.length - limit;
@@ -92,6 +92,7 @@ var LoadedSessionsStore = /** @class */ (function () {
92
92
  LoadedSessionsStore.prototype.createSession = function (initData, sessionType) {
93
93
  var _this = this;
94
94
  var keySessionRecord = new KeySessionRecord(initData);
95
+ log.debug("DRM-LSS: calling `createSession`", sessionType);
95
96
  var mediaKeySession = this._mediaKeys.createSession(sessionType);
96
97
  var entry = { mediaKeySession: mediaKeySession, sessionType: sessionType, keySessionRecord: keySessionRecord, isGeneratingRequest: false,
97
98
  isLoadingPersistentSession: false,
@@ -99,6 +100,7 @@ var LoadedSessionsStore = /** @class */ (function () {
99
100
  if (!isNullOrUndefined(mediaKeySession.closed)) {
100
101
  mediaKeySession.closed
101
102
  .then(function () {
103
+ log.info("DRM-LSS: session was closed, removing it.", mediaKeySession.sessionId);
102
104
  var index = _this.getIndex(keySessionRecord);
103
105
  if (index >= 0 &&
104
106
  _this._storage[index].mediaKeySession === mediaKeySession) {
@@ -110,8 +112,8 @@ var LoadedSessionsStore = /** @class */ (function () {
110
112
  log.warn("DRM-LSS: MediaKeySession.closed rejected: ".concat(e));
111
113
  });
112
114
  }
113
- log.debug("DRM-LSS: Add MediaKeySession", entry.sessionType);
114
115
  this._storage.push(__assign({}, entry));
116
+ log.debug("DRM-LSS: MediaKeySession added", entry.sessionType, this._storage.length);
115
117
  return entry;
116
118
  };
117
119
  /**
@@ -132,6 +134,7 @@ var LoadedSessionsStore = /** @class */ (function () {
132
134
  if (stored.keySessionRecord.isCompatibleWith(initializationData)) {
133
135
  this._storage.splice(i, 1);
134
136
  this._storage.push(stored);
137
+ log.debug("DRM-LSS: Reusing session:", stored.mediaKeySession.sessionId, stored.sessionType);
135
138
  return __assign({}, stored);
136
139
  }
137
140
  }
@@ -365,6 +368,7 @@ var LoadedSessionsStore = /** @class */ (function () {
365
368
  for (var i = this._storage.length - 1; i >= 0; i--) {
366
369
  var stored = this._storage[i];
367
370
  if (stored.mediaKeySession === mediaKeySession) {
371
+ log.debug("DRM-LSS: Removing session without closing it", mediaKeySession.sessionId);
368
372
  this._storage.splice(i, 1);
369
373
  return true;
370
374
  }
@@ -14,17 +14,20 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { ICdnMetadata } from "../../parsers/manifest";
17
- import { IPlayerError } from "../../public_types";
18
17
  import EventEmitter from "../../utils/event_emitter";
19
18
  import { CancellationSignal } from "../../utils/task_canceller";
20
19
  /**
21
- * Class signaling the priority between multiple CDN available for any given
22
- * resource.
20
+ * Class storing and signaling the priority between multiple CDN available for
21
+ * any given resource.
23
22
  *
24
- * This class might perform requests and schedule timeouts by itself to keep its
25
- * internal list of CDN priority up-to-date.
26
- * When it is not needed anymore, you should call the `dispose` method to clear
27
- * all resources.
23
+ * This class was first created to implement the complexities behind
24
+ * Content Steering features, though its handling hasn't been added yet as we
25
+ * wait for its specification to be both standardized and relied on in the wild.
26
+ * In the meantime, it acts as an abstraction for the simple concept of
27
+ * avoiding to request a CDN for any segment when an issue is encountered with
28
+ * one (e.g. HTTP 500 statuses) and several CDN exist for a given resource. It
29
+ * should be noted that this is also one of the planified features of the
30
+ * Content Steering specification.
28
31
  *
29
32
  * @class CdnPrioritizer
30
33
  */
@@ -92,7 +95,13 @@ export default class CdnPrioritizer extends EventEmitter<ICdnPrioritizerEvents>
92
95
  */
93
96
  private _removeIndexFromDowngradeList;
94
97
  }
98
+ /** Events sent by a `CdnPrioritizer` */
95
99
  export interface ICdnPrioritizerEvents {
96
- warnings: IPlayerError[];
100
+ /**
101
+ * The priority of one or several CDN changed.
102
+ *
103
+ * You might want to re-check if a CDN should still be used when this event
104
+ * is triggered.
105
+ */
97
106
  priorityChange: null;
98
107
  }
@@ -32,13 +32,17 @@ import config from "../../config";
32
32
  import arrayFindIndex from "../../utils/array_find_index";
33
33
  import EventEmitter from "../../utils/event_emitter";
34
34
  /**
35
- * Class signaling the priority between multiple CDN available for any given
36
- * resource.
35
+ * Class storing and signaling the priority between multiple CDN available for
36
+ * any given resource.
37
37
  *
38
- * This class might perform requests and schedule timeouts by itself to keep its
39
- * internal list of CDN priority up-to-date.
40
- * When it is not needed anymore, you should call the `dispose` method to clear
41
- * all resources.
38
+ * This class was first created to implement the complexities behind
39
+ * Content Steering features, though its handling hasn't been added yet as we
40
+ * wait for its specification to be both standardized and relied on in the wild.
41
+ * In the meantime, it acts as an abstraction for the simple concept of
42
+ * avoiding to request a CDN for any segment when an issue is encountered with
43
+ * one (e.g. HTTP 500 statuses) and several CDN exist for a given resource. It
44
+ * should be noted that this is also one of the planified features of the
45
+ * Content Steering specification.
42
46
  *
43
47
  * @class CdnPrioritizer
44
48
  */
@@ -144,7 +144,7 @@ var ManifestFetcher = /** @class */ (function (_super) {
144
144
  manifestProm
145
145
  .then(function (val) {
146
146
  _this.trigger("manifestReady", val.manifest);
147
- if (!_this._canceller.isUsed) {
147
+ if (!_this._canceller.isUsed()) {
148
148
  _this._recursivelyRefreshManifest(val.manifest, val);
149
149
  }
150
150
  })
@@ -293,7 +293,7 @@ var ManifestFetcher = /** @class */ (function (_super) {
293
293
  function onWarnings(warnings) {
294
294
  for (var _i = 0, warnings_1 = warnings; _i < warnings_1.length; _i++) {
295
295
  var warning = warnings_1[_i];
296
- if (cancelSignal.isCancelled) {
296
+ if (cancelSignal.isCancelled()) {
297
297
  return;
298
298
  }
299
299
  var formattedError = formatError(warning, {
@@ -411,7 +411,8 @@ var ManifestFetcher = /** @class */ (function (_super) {
411
411
  * be effectively considered.
412
412
  * `nextRefreshCanceller` will allow to cancel every other when one is triggered.
413
413
  */
414
- var nextRefreshCanceller = new TaskCanceller({ cancelOn: this._canceller.signal });
414
+ var nextRefreshCanceller = new TaskCanceller();
415
+ nextRefreshCanceller.linkToSignal(this._canceller.signal);
415
416
  /* Function to manually schedule a Manifest refresh */
416
417
  this.scheduleManualRefresh = function (settings) {
417
418
  var enablePartialRefresh = settings.enablePartialRefresh, delay = settings.delay, canUseUnsafeMode = settings.canUseUnsafeMode;
@@ -584,7 +585,7 @@ var ManifestFetcher = /** @class */ (function (_super) {
584
585
  });
585
586
  };
586
587
  ManifestFetcher.prototype._onFatalError = function (err) {
587
- if (this._canceller.isUsed) {
588
+ if (this._canceller.isUsed()) {
588
589
  return;
589
590
  }
590
591
  this.trigger("error", err);
@@ -26,10 +26,22 @@ import CdnPrioritizer from "../cdn_prioritizer";
26
26
  * An `ISegmentFetcher` also implements a retry mechanism, based on the given
27
27
  * `options` argument, which may retry a segment request when it fails.
28
28
  *
29
- * @param {string} bufferType
30
- * @param {Object} pipeline
31
- * @param {Object} lifecycleCallbacks
32
- * @param {Object} options
29
+ * @param {string} bufferType - Type of buffer concerned (e.g. `"audio"`,
30
+ * `"video"`, `"text" etc.)
31
+ * @param {Object} pipeline - The transport-specific logic allowing to load
32
+ * segments of the given buffer type and transport protocol (e.g. DASH).
33
+ * @param {Object|null} cdnPrioritizer - Abstraction allowing to synchronize,
34
+ * update and keep track of the priorization of the CDN to use to load any given
35
+ * segment, in cases where multiple ones are available.
36
+ *
37
+ * Can be set to `null` in which case a minimal priorization logic will be used
38
+ * instead.
39
+ * @param {Object} lifecycleCallbacks - Callbacks that can be registered to be
40
+ * informed when new requests are made, ended, new metrics are available etc.
41
+ * This should be mainly useful to implement an adaptive logic relying on those
42
+ * metrics and events.
43
+ * @param {Object} options - Various tweaking options allowing to configure the
44
+ * behavior of the returned `ISegmentFetcher`.
33
45
  * @returns {Function}
34
46
  */
35
47
  export default function createSegmentFetcher<TLoadedFormat, TSegmentDataType>(bufferType: IBufferType, pipeline: ISegmentPipeline<TLoadedFormat, TSegmentDataType>, cdnPrioritizer: CdnPrioritizer | null, lifecycleCallbacks: ISegmentFetcherLifecycleCallbacks, options: ISegmentFetcherOptions): ISegmentFetcher<TSegmentDataType>;
@@ -59,10 +71,15 @@ export interface ISegmentFetcherCallbacks<TSegmentDataType> {
59
71
  /**
60
72
  * Callback called when all decodable chunks of the loaded segment have been
61
73
  * communicated through the `onChunk` callback.
74
+ *
75
+ * This callback is called before the corresponding `ISegmentFetcher`'s
76
+ * returned Promise is resolved.
62
77
  */
63
78
  onAllChunksReceived(): void;
64
79
  /**
65
- * Callback called when the segment request has to restart from scratch. */
80
+ * Callback called when the segment request has to restart from scratch, e.g.
81
+ * due to a request error.
82
+ */
66
83
  onRetry(error: IPlayerError): void;
67
84
  }
68
85
  /** Content used by the segment loader as a context to load a new segment. */
@@ -69,10 +69,22 @@ var generateRequestID = idGenerator();
69
69
  * An `ISegmentFetcher` also implements a retry mechanism, based on the given
70
70
  * `options` argument, which may retry a segment request when it fails.
71
71
  *
72
- * @param {string} bufferType
73
- * @param {Object} pipeline
74
- * @param {Object} lifecycleCallbacks
75
- * @param {Object} options
72
+ * @param {string} bufferType - Type of buffer concerned (e.g. `"audio"`,
73
+ * `"video"`, `"text" etc.)
74
+ * @param {Object} pipeline - The transport-specific logic allowing to load
75
+ * segments of the given buffer type and transport protocol (e.g. DASH).
76
+ * @param {Object|null} cdnPrioritizer - Abstraction allowing to synchronize,
77
+ * update and keep track of the priorization of the CDN to use to load any given
78
+ * segment, in cases where multiple ones are available.
79
+ *
80
+ * Can be set to `null` in which case a minimal priorization logic will be used
81
+ * instead.
82
+ * @param {Object} lifecycleCallbacks - Callbacks that can be registered to be
83
+ * informed when new requests are made, ended, new metrics are available etc.
84
+ * This should be mainly useful to implement an adaptive logic relying on those
85
+ * metrics and events.
86
+ * @param {Object} options - Various tweaking options allowing to configure the
87
+ * behavior of the returned `ISegmentFetcher`.
76
88
  * @returns {Function}
77
89
  */
78
90
  export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritizer, lifecycleCallbacks, options) {
@@ -97,8 +109,17 @@ export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritize
97
109
  * @returns {Promise}
98
110
  */
99
111
  return function fetchSegment(content, fetcherCallbacks, cancellationSignal) {
100
- var _a, _b;
112
+ var _a, _b, _c;
101
113
  return __awaiter(this, void 0, void 0, function () {
114
+ function onCancellation() {
115
+ var _a;
116
+ if (requestInfo !== undefined) {
117
+ return; // Request already terminated
118
+ }
119
+ log.debug("SF: Segment request cancelled", segmentIdString);
120
+ requestInfo = null;
121
+ (_a = lifecycleCallbacks.onRequestEnd) === null || _a === void 0 ? void 0 : _a.call(lifecycleCallbacks, { id: requestId });
122
+ }
102
123
  /**
103
124
  * Call a segment loader for the given URL with the right arguments.
104
125
  * @param {Object|null} cdnMetadata
@@ -169,8 +190,8 @@ export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritize
169
190
  }
170
191
  }
171
192
  var segment, adaptation, representation, manifest, period, segmentIdString, requestId, requestInfo, parsedChunks, segmentDurationAcc, metricsSent, context, loaderCallbacks, cached, res, loadedData, err_1;
172
- return __generator(this, function (_c) {
173
- switch (_c.label) {
193
+ return __generator(this, function (_d) {
194
+ switch (_d.label) {
174
195
  case 0:
175
196
  segment = content.segment, adaptation = content.adaptation, representation = content.representation, manifest = content.manifest, period = content.period;
176
197
  segmentIdString = getLoggableSegmentId(content);
@@ -225,21 +246,13 @@ export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritize
225
246
  log.debug("SF: Beginning request", segmentIdString);
226
247
  (_a = lifecycleCallbacks.onRequestBegin) === null || _a === void 0 ? void 0 : _a.call(lifecycleCallbacks, { requestTimestamp: performance.now(),
227
248
  id: requestId, content: content });
228
- cancellationSignal.register(function () {
229
- var _a;
230
- if (requestInfo !== undefined) {
231
- return; // Request already terminated
232
- }
233
- log.debug("SF: Segment request cancelled", segmentIdString);
234
- requestInfo = null;
235
- (_a = lifecycleCallbacks.onRequestEnd) === null || _a === void 0 ? void 0 : _a.call(lifecycleCallbacks, { id: requestId });
236
- });
237
- _c.label = 1;
249
+ cancellationSignal.register(onCancellation);
250
+ _d.label = 1;
238
251
  case 1:
239
- _c.trys.push([1, 3, , 4]);
252
+ _d.trys.push([1, 3, , 4]);
240
253
  return [4 /*yield*/, scheduleRequestWithCdns(content.representation.cdnMetadata, cdnPrioritizer, callLoaderWithUrl, objectAssign({ onRetry: onRetry }, options), cancellationSignal)];
241
254
  case 2:
242
- res = _c.sent();
255
+ res = _d.sent();
243
256
  if (res.resultType === "segment-loaded") {
244
257
  loadedData = res.resultData.responseData;
245
258
  if (cache !== undefined) {
@@ -259,21 +272,24 @@ export default function createSegmentFetcher(bufferType, pipeline, cdnPrioritize
259
272
  else {
260
273
  requestInfo = null;
261
274
  }
262
- if (!cancellationSignal.isCancelled) {
275
+ if (!cancellationSignal.isCancelled()) {
263
276
  // The current task could have been canceled as a result of one
264
277
  // of the previous callbacks call. In that case, we don't want to send
265
278
  // a "requestEnd" again as it has already been sent on cancellation.
266
279
  (_b = lifecycleCallbacks.onRequestEnd) === null || _b === void 0 ? void 0 : _b.call(lifecycleCallbacks, { id: requestId });
267
280
  }
281
+ cancellationSignal.deregister(onCancellation);
268
282
  return [3 /*break*/, 4];
269
283
  case 3:
270
- err_1 = _c.sent();
284
+ err_1 = _d.sent();
285
+ cancellationSignal.deregister(onCancellation);
271
286
  requestInfo = null;
272
287
  if (err_1 instanceof CancellationError) {
273
288
  log.debug("SF: Segment request aborted", segmentIdString);
274
289
  throw err_1;
275
290
  }
276
291
  log.debug("SF: Segment request failed", segmentIdString);
292
+ (_c = lifecycleCallbacks.onRequestEnd) === null || _c === void 0 ? void 0 : _c.call(lifecycleCallbacks, { id: requestId });
277
293
  throw errorSelector(err_1);
278
294
  case 4: return [2 /*return*/];
279
295
  }