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
@@ -230,6 +230,7 @@ var DashWasmParser = /** @class */ (function () {
230
230
  "Unknown error";
231
231
  log.warn("DW: Could not create DASH-WASM parser:", message);
232
232
  _this.status = "failure";
233
+ throw err;
233
234
  });
234
235
  return [2 /*return*/, this._initProm];
235
236
  });
@@ -14,10 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { IPersistentSessionInfoV0, IPersistentSessionInfoV1, IPersistentSessionInfoV2, IPersistentSessionInfoV3, IPersistentSessionInfoV4 } from "./core/decrypt";
17
- import { EncryptedMediaError, MediaError, NetworkError, OtherError } from "./errors";
17
+ import { IMediaErrorTrackContext, EncryptedMediaError, MediaError, NetworkError, OtherError } from "./errors";
18
18
  import Manifest from "./manifest";
19
19
  import { ILocalManifest } from "./parsers/manifest/local";
20
20
  import { IMetaPlaylist } from "./parsers/manifest/metaplaylist/metaplaylist_parser";
21
+ export { IMediaErrorTrackContext };
21
22
  /**
22
23
  * This file defines and exports types we want to expose to library users.
23
24
  * Those types are considered as part of the API.
@@ -584,6 +585,8 @@ export interface IAudioRepresentation {
584
585
  id: string | number;
585
586
  bitrate?: number | undefined;
586
587
  codec?: string | undefined;
588
+ isCodecSupported?: boolean | undefined;
589
+ seemsDecipherable?: boolean | undefined;
587
590
  }
588
591
  /** Audio track returned by the RxPlayer. */
589
592
  export interface IAudioTrack {
@@ -609,7 +612,7 @@ export interface ITextTrack {
609
612
  * Kept equal to `language` if the attempt failed.
610
613
  */
611
614
  normalized: string;
612
- forced?: boolean | undefined;
615
+ forced: boolean | undefined;
613
616
  closedCaption: boolean;
614
617
  label?: string | undefined;
615
618
  id: number | string;
@@ -626,6 +629,8 @@ export interface IVideoRepresentation {
626
629
  codec?: string | undefined;
627
630
  frameRate?: number | undefined;
628
631
  hdrInfo?: IHDRInformation | undefined;
632
+ isCodecSupported?: boolean | undefined;
633
+ seemsDecipherable?: boolean | undefined;
629
634
  }
630
635
  /** Video track returned by the RxPlayer. */
631
636
  export interface IVideoTrack {
@@ -786,8 +791,14 @@ export interface ITrackUpdateEventPayload {
786
791
  "manual" | // Manually and explicitely updated
787
792
  "trickmode-enabled" | // Video trickmode tracks being enabled
788
793
  "trickmode-disabled" | // Video trickmode tracks being disabled
794
+ "no-playable-representation" | // Previous track had no playable Representation
789
795
  string;
790
796
  }
797
+ export interface IRepresentationListUpdateContext {
798
+ period: IPeriod;
799
+ trackType: ITrackType;
800
+ reason: "decipherability-update" | string;
801
+ }
791
802
  export interface ILockedVideoRepresentationsSettings {
792
803
  representations: string[];
793
804
  periodId?: string | undefined;
@@ -814,4 +825,3 @@ export interface ITextTrackSetting {
814
825
  trackId: string;
815
826
  periodId?: string | undefined;
816
827
  }
817
- export {};
@@ -52,7 +52,7 @@ var TextTrackRenderer = /** @class */ (function () {
52
52
  args.timeOffset :
53
53
  0;
54
54
  this._segmentBuffer.pushChunkSync({ inventoryInfos: null,
55
- data: { initSegment: null,
55
+ data: { initSegmentUniqueId: null,
56
56
  codec: args.type, timestampOffset: timestampOffset, appendWindow: [0, Infinity],
57
57
  chunk: { start: 0,
58
58
  end: Number.MAX_VALUE,
@@ -37,10 +37,9 @@ import inferSegmentContainer from "../utils/infer_segment_container";
37
37
  export default function addSegmentIntegrityChecks(segmentLoader) {
38
38
  return function (url, context, loaderOptions, initialCancelSignal, callbacks) {
39
39
  return new Promise(function (resolve, reject) {
40
- var requestCanceller = new TaskCanceller({ cancelOn: initialCancelSignal });
41
- // Reject the `CancellationError` when `requestCanceller`'s signal emits
42
- // `stopRejectingOnCancel` here is a function allowing to stop this mechanism
43
- var stopRejectingOnCancel = requestCanceller.signal.register(reject);
40
+ var requestCanceller = new TaskCanceller();
41
+ var unlinkCanceller = requestCanceller.linkToSignal(initialCancelSignal);
42
+ requestCanceller.signal.register(reject);
44
43
  segmentLoader(url, context, loaderOptions, requestCanceller.signal, __assign(__assign({}, callbacks), { onNewChunk: function (data) {
45
44
  try {
46
45
  trowOnIntegrityError(data);
@@ -48,17 +47,18 @@ export default function addSegmentIntegrityChecks(segmentLoader) {
48
47
  }
49
48
  catch (err) {
50
49
  // Do not reject with a `CancellationError` after cancelling the request
51
- stopRejectingOnCancel();
50
+ cleanUpCancellers();
52
51
  // Cancel the request
53
52
  requestCanceller.cancel();
54
53
  // Reject with thrown error
55
54
  reject(err);
56
55
  }
57
- } })).then(function (info) {
58
- if (requestCanceller.isUsed) {
56
+ } }))
57
+ .then(function (info) {
58
+ cleanUpCancellers();
59
+ if (requestCanceller.isUsed()) {
59
60
  return;
60
61
  }
61
- stopRejectingOnCancel();
62
62
  if (info.resultType === "segment-loaded") {
63
63
  try {
64
64
  trowOnIntegrityError(info.resultData.responseData);
@@ -69,10 +69,14 @@ export default function addSegmentIntegrityChecks(segmentLoader) {
69
69
  }
70
70
  }
71
71
  resolve(info);
72
- }, function (error) {
73
- stopRejectingOnCancel();
74
- reject(error);
72
+ }, function (err) {
73
+ cleanUpCancellers();
74
+ reject(err);
75
75
  });
76
+ function cleanUpCancellers() {
77
+ requestCanceller.signal.deregister(reject);
78
+ unlinkCanceller();
79
+ }
76
80
  });
77
81
  /**
78
82
  * If the data's seems to be corrupted, throws an `INTEGRITY_ERROR` error.
@@ -47,14 +47,14 @@ export default function lowLatencySegmentLoader(url, content, options, callbacks
47
47
  partialChunk = res[1];
48
48
  for (var i = 0; i < completeChunks.length; i++) {
49
49
  callbacks.onNewChunk(completeChunks[i]);
50
- if (cancelSignal.isCancelled) {
50
+ if (cancelSignal.isCancelled()) {
51
51
  return;
52
52
  }
53
53
  }
54
54
  callbacks.onProgress({ duration: info.duration,
55
55
  size: info.size,
56
56
  totalSize: info.totalSize });
57
- if (cancelSignal.isCancelled) {
57
+ if (cancelSignal.isCancelled()) {
58
58
  return;
59
59
  }
60
60
  }
@@ -96,7 +96,7 @@ export default function generateManifestParser(options) {
96
96
  if (parserResponse.value.warnings.length > 0) {
97
97
  onWarnings(parserResponse.value.warnings);
98
98
  }
99
- if (cancelSignal.isCancelled) {
99
+ if (cancelSignal.isCancelled()) {
100
100
  return Promise.reject(cancelSignal.cancellationError);
101
101
  }
102
102
  var manifest = new Manifest(parserResponse.value.parsed, options);
@@ -88,7 +88,7 @@ export default function generateSegmentLoader(_a) {
88
88
  * @param {Object} _args
89
89
  */
90
90
  var resolve = function (_args) {
91
- if (hasFinished || cancelSignal.isCancelled) {
91
+ if (hasFinished || cancelSignal.isCancelled()) {
92
92
  return;
93
93
  }
94
94
  hasFinished = true;
@@ -104,7 +104,7 @@ export default function generateSegmentLoader(_a) {
104
104
  */
105
105
  var reject = function (err) {
106
106
  var _a, _b;
107
- if (hasFinished || cancelSignal.isCancelled) {
107
+ if (hasFinished || cancelSignal.isCancelled()) {
108
108
  return;
109
109
  }
110
110
  hasFinished = true;
@@ -117,7 +117,7 @@ export default function generateSegmentLoader(_a) {
117
117
  rej(emittedErr);
118
118
  };
119
119
  var progress = function (_args) {
120
- if (hasFinished || cancelSignal.isCancelled) {
120
+ if (hasFinished || cancelSignal.isCancelled()) {
121
121
  return;
122
122
  }
123
123
  callbacks.onProgress({ duration: _args.duration,
@@ -129,7 +129,7 @@ export default function generateSegmentLoader(_a) {
129
129
  * the "regular" implementation
130
130
  */
131
131
  var fallback = function () {
132
- if (hasFinished || cancelSignal.isCancelled) {
132
+ if (hasFinished || cancelSignal.isCancelled()) {
133
133
  return;
134
134
  }
135
135
  hasFinished = true;
@@ -14,6 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { CustomLoaderError } from "../../errors";
17
+ import createCancellablePromise from "../../utils/create_cancellable_promise";
17
18
  import isNullOrUndefined from "../../utils/is_null_or_undefined";
18
19
  /**
19
20
  * @param {Function} customSegmentLoader
@@ -21,7 +22,7 @@ import isNullOrUndefined from "../../utils/is_null_or_undefined";
21
22
  * @returns {Promise}
22
23
  */
23
24
  function loadInitSegment(customSegmentLoader, cancelSignal) {
24
- return new Promise(function (res, rej) {
25
+ return createCancellablePromise(cancelSignal, function (res, rej) {
25
26
  /** `true` when the custom segmentLoader should not be active anymore. */
26
27
  var hasFinished = false;
27
28
  /**
@@ -29,11 +30,10 @@ function loadInitSegment(customSegmentLoader, cancelSignal) {
29
30
  * @param {Object} _args
30
31
  */
31
32
  var resolve = function (_args) {
32
- if (hasFinished || cancelSignal.isCancelled) {
33
+ if (hasFinished || cancelSignal.isCancelled()) {
33
34
  return;
34
35
  }
35
36
  hasFinished = true;
36
- cancelSignal.deregister(abortLoader);
37
37
  res({ resultType: "segment-loaded",
38
38
  resultData: { responseData: _args.data,
39
39
  size: _args.size,
@@ -44,20 +44,15 @@ function loadInitSegment(customSegmentLoader, cancelSignal) {
44
44
  * @param {*} err - The corresponding error encountered
45
45
  */
46
46
  var reject = function (err) {
47
- if (hasFinished || cancelSignal.isCancelled) {
47
+ if (hasFinished || cancelSignal.isCancelled()) {
48
48
  return;
49
49
  }
50
50
  hasFinished = true;
51
- cancelSignal.deregister(abortLoader);
52
51
  rej(err);
53
52
  };
54
53
  var abort = customSegmentLoader({ resolve: resolve, reject: reject });
55
- cancelSignal.register(abortLoader);
56
- /**
57
- * The logic to run when this loader is cancelled while pending.
58
- * @param {Error} err
59
- */
60
- function abortLoader(err) {
54
+ /** The logic to run when this loader is cancelled while pending. */
55
+ return function () {
61
56
  if (hasFinished) {
62
57
  return;
63
58
  }
@@ -65,8 +60,7 @@ function loadInitSegment(customSegmentLoader, cancelSignal) {
65
60
  if (typeof abort === "function") {
66
61
  abort();
67
62
  }
68
- rej(err);
69
- }
63
+ };
70
64
  });
71
65
  }
72
66
  /**
@@ -76,7 +70,7 @@ function loadInitSegment(customSegmentLoader, cancelSignal) {
76
70
  * @returns {Promise.<Object>}
77
71
  */
78
72
  function loadSegment(segment, customSegmentLoader, cancelSignal) {
79
- return new Promise(function (res, rej) {
73
+ return createCancellablePromise(cancelSignal, function (res, rej) {
80
74
  /** `true` when the custom segmentLoader should not be active anymore. */
81
75
  var hasFinished = false;
82
76
  /**
@@ -84,11 +78,10 @@ function loadSegment(segment, customSegmentLoader, cancelSignal) {
84
78
  * @param {Object} _args
85
79
  */
86
80
  var resolve = function (_args) {
87
- if (hasFinished || cancelSignal.isCancelled) {
81
+ if (hasFinished || cancelSignal.isCancelled()) {
88
82
  return;
89
83
  }
90
84
  hasFinished = true;
91
- cancelSignal.deregister(abortLoader);
92
85
  res({ resultType: "segment-loaded",
93
86
  resultData: { responseData: _args.data,
94
87
  size: _args.size,
@@ -100,11 +93,10 @@ function loadSegment(segment, customSegmentLoader, cancelSignal) {
100
93
  */
101
94
  var reject = function (err) {
102
95
  var _a, _b;
103
- if (hasFinished || cancelSignal.isCancelled) {
96
+ if (hasFinished || cancelSignal.isCancelled()) {
104
97
  return;
105
98
  }
106
99
  hasFinished = true;
107
- cancelSignal.deregister(abortLoader);
108
100
  // Format error and send it
109
101
  var castedErr = err;
110
102
  var message = (_a = castedErr === null || castedErr === void 0 ? void 0 : castedErr.message) !== null && _a !== void 0 ? _a : "Unknown error when fetching a local segment through a " +
@@ -113,12 +105,8 @@ function loadSegment(segment, customSegmentLoader, cancelSignal) {
113
105
  rej(emittedErr);
114
106
  };
115
107
  var abort = customSegmentLoader(segment, { resolve: resolve, reject: reject });
116
- cancelSignal.register(abortLoader);
117
- /**
118
- * The logic to run when this loader is cancelled while pending.
119
- * @param {Error} err
120
- */
121
- function abortLoader(err) {
108
+ /** The logic to run when this loader is cancelled while pending. */
109
+ return function () {
122
110
  if (hasFinished) {
123
111
  return;
124
112
  }
@@ -126,8 +114,7 @@ function loadSegment(segment, customSegmentLoader, cancelSignal) {
126
114
  if (typeof abort === "function") {
127
115
  abort();
128
116
  }
129
- rej(err);
130
- }
117
+ };
131
118
  });
132
119
  }
133
120
  /**
@@ -18,7 +18,7 @@
18
18
  * @param {Number} height
19
19
  * @param {Number} hRes - horizontal resolution, eg 72
20
20
  * @param {Number} vRes - vertical resolution, eg 72
21
- * @param {string} encDepth
21
+ * @param {string} encName
22
22
  * @param {Number} colorDepth - eg 24
23
23
  * @param {Uint8Array} avcc - Uint8Array representing the avcC atom
24
24
  * @returns {Uint8Array}
@@ -29,7 +29,7 @@ declare function createAVC1Box(width: number, height: number, hRes: number, vRes
29
29
  * @param {Number} height
30
30
  * @param {Number} hRes - horizontal resolution, eg 72
31
31
  * @param {Number} vRes - vertical resolution, eg 72
32
- * @param {string} encDepth
32
+ * @param {string} encName
33
33
  * @param {Number} colorDepth - eg 24
34
34
  * @param {Uint8Array} avcc - Uint8Array representing the avcC atom
35
35
  * @param {Uint8Array} sinf - Uint8Array representing the sinf atom
@@ -43,8 +43,6 @@ declare function createENCVBox(width: number, height: number, hRes: number, vRes
43
43
  * @param {Number} packetSize
44
44
  * @param {Number} sampleRate
45
45
  * @param {Uint8Array} esds - Uint8Array representing the esds atom
46
- * @param {Uint8Array} [sinf] - Uint8Array representing the sinf atom,
47
- * only if name == "enca"
48
46
  * @returns {Uint8Array}
49
47
  */
50
48
  declare function createMP4ABox(drefIdx: number, channelsCount: number, sampleSize: number, packetSize: number, sampleRate: number, esds: Uint8Array): Uint8Array;
@@ -61,7 +59,7 @@ declare function createMP4ABox(drefIdx: number, channelsCount: number, sampleSiz
61
59
  */
62
60
  declare function createENCABox(drefIdx: number, channelsCount: number, sampleSize: number, packetSize: number, sampleRate: number, esds: Uint8Array, sinf: Uint8Array): Uint8Array;
63
61
  /**
64
- * @param {url} Uint8Array
62
+ * @param {Uint8Array} url
65
63
  * @returns {Uint8Array}
66
64
  */
67
65
  declare function createDREFBox(url: Uint8Array): Uint8Array;
@@ -151,7 +149,7 @@ declare function createSAIZBox(sencContent: Uint8Array): Uint8Array;
151
149
  */
152
150
  declare function createSMHDBox(): Uint8Array;
153
151
  /**
154
- * @param {Array.<Uint8Array>} representations - arrays of Uint8Array,
152
+ * @param {Array.<Uint8Array>} reps - arrays of Uint8Array,
155
153
  * typically [avc1] or [encv, avc1]
156
154
  * @returns {Uint8Array}
157
155
  */
@@ -21,7 +21,7 @@ import { hexToBytes, strToUtf8, } from "../../../utils/string_parsing";
21
21
  * @param {Number} height
22
22
  * @param {Number} hRes - horizontal resolution, eg 72
23
23
  * @param {Number} vRes - vertical resolution, eg 72
24
- * @param {string} encDepth
24
+ * @param {string} encName
25
25
  * @param {Number} colorDepth - eg 24
26
26
  * @param {Uint8Array} avcc - Uint8Array representing the avcC atom
27
27
  * @returns {Uint8Array}
@@ -46,7 +46,7 @@ function createAVC1Box(width, height, hRes, vRes, encName, colorDepth, avcc) {
46
46
  * @param {Number} height
47
47
  * @param {Number} hRes - horizontal resolution, eg 72
48
48
  * @param {Number} vRes - vertical resolution, eg 72
49
- * @param {string} encDepth
49
+ * @param {string} encName
50
50
  * @param {Number} colorDepth - eg 24
51
51
  * @param {Uint8Array} avcc - Uint8Array representing the avcC atom
52
52
  * @param {Uint8Array} sinf - Uint8Array representing the sinf atom
@@ -74,8 +74,6 @@ function createENCVBox(width, height, hRes, vRes, encName, colorDepth, avcc, sin
74
74
  * @param {Number} packetSize
75
75
  * @param {Number} sampleRate
76
76
  * @param {Uint8Array} esds - Uint8Array representing the esds atom
77
- * @param {Uint8Array} [sinf] - Uint8Array representing the sinf atom,
78
- * only if name == "enca"
79
77
  * @returns {Uint8Array}
80
78
  */
81
79
  function createMP4ABox(drefIdx, channelsCount, sampleSize, packetSize, sampleRate, esds) {
@@ -96,7 +94,7 @@ function createENCABox(drefIdx, channelsCount, sampleSize, packetSize, sampleRat
96
94
  return createBox("enca", concat(6, itobe2(drefIdx), 8, itobe2(channelsCount), itobe2(sampleSize), 2, itobe2(packetSize), itobe2(sampleRate), 2, esds, sinf));
97
95
  }
98
96
  /**
99
- * @param {url} Uint8Array
97
+ * @param {Uint8Array} url
100
98
  * @returns {Uint8Array}
101
99
  */
102
100
  function createDREFBox(url) {
@@ -291,7 +289,7 @@ function createSMHDBox() {
291
289
  return createBox("smhd", new Uint8Array(8));
292
290
  }
293
291
  /**
294
- * @param {Array.<Uint8Array>} representations - arrays of Uint8Array,
292
+ * @param {Array.<Uint8Array>} reps - arrays of Uint8Array,
295
293
  * typically [avc1] or [encv, avc1]
296
294
  * @returns {Uint8Array}
297
295
  */
@@ -116,7 +116,7 @@ var generateSegmentLoader = function (_a) {
116
116
  * @param {Object} args
117
117
  */
118
118
  var resolve = function (_args) {
119
- if (hasFinished || cancelSignal.isCancelled) {
119
+ if (hasFinished || cancelSignal.isCancelled()) {
120
120
  return;
121
121
  }
122
122
  hasFinished = true;
@@ -142,7 +142,7 @@ var generateSegmentLoader = function (_a) {
142
142
  */
143
143
  var reject = function (err) {
144
144
  var _a, _b;
145
- if (hasFinished || cancelSignal.isCancelled) {
145
+ if (hasFinished || cancelSignal.isCancelled()) {
146
146
  return;
147
147
  }
148
148
  hasFinished = true;
@@ -155,7 +155,7 @@ var generateSegmentLoader = function (_a) {
155
155
  rej(emittedErr);
156
156
  };
157
157
  var progress = function (_args) {
158
- if (hasFinished || cancelSignal.isCancelled) {
158
+ if (hasFinished || cancelSignal.isCancelled()) {
159
159
  return;
160
160
  }
161
161
  callbacks.onProgress({ duration: _args.duration,
@@ -163,7 +163,7 @@ var generateSegmentLoader = function (_a) {
163
163
  totalSize: _args.totalSize });
164
164
  };
165
165
  var fallback = function () {
166
- if (hasFinished || cancelSignal.isCancelled) {
166
+ if (hasFinished || cancelSignal.isCancelled()) {
167
167
  return;
168
168
  }
169
169
  hasFinished = true;
@@ -25,7 +25,7 @@ export default function callCustomManifestLoader(customManifestLoader, fallbackM
25
25
  * @param {Object} args
26
26
  */
27
27
  var resolve = function (_args) {
28
- if (hasFinished || cancelSignal.isCancelled) {
28
+ if (hasFinished || cancelSignal.isCancelled()) {
29
29
  return;
30
30
  }
31
31
  hasFinished = true;
@@ -45,7 +45,7 @@ export default function callCustomManifestLoader(customManifestLoader, fallbackM
45
45
  */
46
46
  var reject = function (err) {
47
47
  var _a, _b;
48
- if (hasFinished || cancelSignal.isCancelled) {
48
+ if (hasFinished || cancelSignal.isCancelled()) {
49
49
  return;
50
50
  }
51
51
  hasFinished = true;
@@ -62,7 +62,7 @@ export default function callCustomManifestLoader(customManifestLoader, fallbackM
62
62
  * the "regular" implementation
63
63
  */
64
64
  var fallback = function () {
65
- if (hasFinished || cancelSignal.isCancelled) {
65
+ if (hasFinished || cancelSignal.isCancelled()) {
66
66
  return;
67
67
  }
68
68
  hasFinished = true;
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import createCancellablePromise from "./create_cancellable_promise";
16
17
  /**
17
18
  * Wait the given `delay`, resolving the Promise when finished.
18
19
  *
@@ -27,15 +28,8 @@
27
28
  * cancellation with the corresponding `CancellationError`.
28
29
  */
29
30
  export default function cancellableSleep(delay, cancellationSignal) {
30
- return new Promise(function (res, rej) {
31
- var timeout = setTimeout(function () {
32
- unregisterCancelSignal();
33
- res();
34
- }, delay);
35
- var unregisterCancelSignal = cancellationSignal
36
- .register(function onCancel(cancellationError) {
37
- clearTimeout(timeout);
38
- rej(cancellationError);
39
- });
31
+ return createCancellablePromise(cancellationSignal, function (res) {
32
+ var timeout = setTimeout(function () { return res(); }, delay);
33
+ return function () { return clearTimeout(timeout); };
40
34
  });
41
35
  }
@@ -0,0 +1,26 @@
1
+ import { CancellationSignal } from "./task_canceller";
2
+ /**
3
+ * Returns a Promise linked to a `CancellationSignal`, which will reject the
4
+ * corresponding `CancellationError` if that signal emits before the wanted
5
+ * task finishes (either on success or on error).
6
+ *
7
+ * The given callback mimicks the Promise interface with the added possibility
8
+ * of returning a callback which will be called when and if the task is
9
+ * cancelled before being either resolved or rejected.
10
+ * In that case, that logic will be called just before the Promise is rejected
11
+ * with the corresponding `CancellationError`.
12
+ * The point of this callback is to implement aborting logic, such as for
13
+ * example aborting a request.
14
+ *
15
+ * @param {Object} cancellationSignal - The `CancellationSignal` the returned
16
+ * Promise will be linked to.
17
+ * @param {Function} cb - The function implementing the cancellable Promise. Its
18
+ * arguments follow Promise's semantics but it can also return a function which
19
+ * will be called when and if `cancellationSignal` emits before either arguments
20
+ * are called.
21
+ * @returns {Promise} - The created Promise, which will resolve when and if the
22
+ * first argument to `cb` is called first and reject either if the second
23
+ * argument to `cb` is called first or if the given `CancellationSignal` emits
24
+ * before either of the two previous conditions.
25
+ */
26
+ export default function createCancellablePromise<T>(cancellationSignal: CancellationSignal, cb: (resolve: (val: T) => void, reject: (err: unknown) => void) => (() => void) | void): Promise<T>;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Returns a Promise linked to a `CancellationSignal`, which will reject the
3
+ * corresponding `CancellationError` if that signal emits before the wanted
4
+ * task finishes (either on success or on error).
5
+ *
6
+ * The given callback mimicks the Promise interface with the added possibility
7
+ * of returning a callback which will be called when and if the task is
8
+ * cancelled before being either resolved or rejected.
9
+ * In that case, that logic will be called just before the Promise is rejected
10
+ * with the corresponding `CancellationError`.
11
+ * The point of this callback is to implement aborting logic, such as for
12
+ * example aborting a request.
13
+ *
14
+ * @param {Object} cancellationSignal - The `CancellationSignal` the returned
15
+ * Promise will be linked to.
16
+ * @param {Function} cb - The function implementing the cancellable Promise. Its
17
+ * arguments follow Promise's semantics but it can also return a function which
18
+ * will be called when and if `cancellationSignal` emits before either arguments
19
+ * are called.
20
+ * @returns {Promise} - The created Promise, which will resolve when and if the
21
+ * first argument to `cb` is called first and reject either if the second
22
+ * argument to `cb` is called first or if the given `CancellationSignal` emits
23
+ * before either of the two previous conditions.
24
+ */
25
+ export default function createCancellablePromise(cancellationSignal, cb) {
26
+ var abortingLogic;
27
+ return new Promise(function (res, rej) {
28
+ if (cancellationSignal.cancellationError !== null) {
29
+ // If the signal was already triggered before, do not even call `cb`
30
+ return rej(cancellationSignal.cancellationError);
31
+ }
32
+ var hasUnregistered = false;
33
+ abortingLogic = cb(function onCancellablePromiseSuccess(val) {
34
+ cancellationSignal.deregister(onCancellablePromiseCancellation);
35
+ hasUnregistered = true;
36
+ res(val);
37
+ }, function onCancellablePromiseFailure(err) {
38
+ cancellationSignal.deregister(onCancellablePromiseCancellation);
39
+ hasUnregistered = true;
40
+ rej(err);
41
+ });
42
+ if (!hasUnregistered) {
43
+ cancellationSignal.register(onCancellablePromiseCancellation);
44
+ }
45
+ function onCancellablePromiseCancellation(error) {
46
+ if (abortingLogic !== undefined) {
47
+ abortingLogic();
48
+ }
49
+ rej(error);
50
+ }
51
+ });
52
+ }
@@ -19,6 +19,6 @@
19
19
  * not always understood by newcomers to the code, and which can be overused when
20
20
  * only one of the possibility can arise.
21
21
  * @param {*} x
22
- * @returns {*}
22
+ * @returns {boolean}
23
23
  */
24
24
  export default function isNullOrUndefined(x: unknown): x is null | undefined | void;
@@ -19,7 +19,7 @@
19
19
  * not always understood by newcomers to the code, and which can be overused when
20
20
  * only one of the possibility can arise.
21
21
  * @param {*} x
22
- * @returns {*}
22
+ * @returns {boolean}
23
23
  */
24
24
  export default function isNullOrUndefined(x) {
25
25
  return x === null || x === undefined;
@@ -126,6 +126,9 @@ export default function createSharedReference(initialValue, cancelSignal) {
126
126
  }
127
127
  options.clearSignal.register(unlisten);
128
128
  function unlisten() {
129
+ if ((options === null || options === void 0 ? void 0 : options.clearSignal) !== undefined) {
130
+ options.clearSignal.deregister(unlisten);
131
+ }
129
132
  if (cbObj.hasBeenCleared) {
130
133
  return;
131
134
  }
@@ -165,6 +168,9 @@ export default function createSharedReference(initialValue, cancelSignal) {
165
168
  finish: finish,
166
169
  };
167
170
  function finish() {
171
+ if (cancelSignal !== undefined) {
172
+ cancelSignal.deregister(finish);
173
+ }
168
174
  isFinished = true;
169
175
  var clonedCbs = cbs.slice();
170
176
  for (var _i = 0, clonedCbs_2 = clonedCbs; _i < clonedCbs_2.length; _i++) {
@@ -68,7 +68,7 @@ export default function request(options) {
68
68
  }
69
69
  reject(err);
70
70
  });
71
- if (cancelSignal.isCancelled) {
71
+ if (cancelSignal.isCancelled()) {
72
72
  return;
73
73
  }
74
74
  }