rx-player 4.5.0-dev.2026021900 → 4.5.0-dev.2026032600

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 (290) hide show
  1. package/CHANGELOG.md +15 -3
  2. package/VERSION +1 -1
  3. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  4. package/dist/commonjs/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  5. package/dist/commonjs/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  6. package/dist/commonjs/__GENERATED_CODE/embedded_worker.js +1 -1
  7. package/dist/commonjs/compat/browser_compatibility_types.d.ts +16 -14
  8. package/dist/commonjs/compat/browser_compatibility_types.d.ts.map +1 -1
  9. package/dist/commonjs/compat/browser_compatibility_types.js +7 -4
  10. package/dist/commonjs/compat/browser_version.d.ts +2 -1
  11. package/dist/commonjs/compat/browser_version.d.ts.map +1 -1
  12. package/dist/commonjs/compat/browser_version.js +13 -0
  13. package/dist/commonjs/compat/disable_remote_playback_on_managed_media_source.d.ts.map +1 -1
  14. package/dist/commonjs/compat/disable_remote_playback_on_managed_media_source.js +1 -1
  15. package/dist/commonjs/compat/is_codec_supported.d.ts.map +1 -1
  16. package/dist/commonjs/compat/is_codec_supported.js +4 -3
  17. package/dist/commonjs/compat/should_patch_out_dolby_vision_config_data_from_mp4.d.ts +26 -0
  18. package/dist/commonjs/compat/should_patch_out_dolby_vision_config_data_from_mp4.d.ts.map +1 -0
  19. package/dist/commonjs/compat/should_patch_out_dolby_vision_config_data_from_mp4.js +45 -0
  20. package/dist/commonjs/core/cmcd/cmcd_data_builder.js +2 -2
  21. package/dist/commonjs/core/entry/content_preparer.d.ts +1 -6
  22. package/dist/commonjs/core/entry/content_preparer.d.ts.map +1 -1
  23. package/dist/commonjs/core/entry/content_preparer.js +2 -125
  24. package/dist/commonjs/core/entry/core_entry.d.ts +1 -1
  25. package/dist/commonjs/core/entry/core_entry.d.ts.map +1 -1
  26. package/dist/commonjs/core/entry/core_entry.js +2 -7
  27. package/dist/commonjs/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  28. package/dist/commonjs/core/entry/core_text_displayer_interface.js +3 -1
  29. package/dist/commonjs/core/entry/index.d.ts +1 -1
  30. package/dist/commonjs/core/entry/index.d.ts.map +1 -1
  31. package/dist/commonjs/core/entry/utils.d.ts +64 -0
  32. package/dist/commonjs/core/entry/utils.d.ts.map +1 -1
  33. package/dist/commonjs/core/entry/utils.js +165 -0
  34. package/dist/commonjs/core/fetchers/segment/segment_fetcher.d.ts.map +1 -1
  35. package/dist/commonjs/core/fetchers/segment/segment_fetcher.js +2 -1
  36. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts +5 -6
  37. package/dist/commonjs/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  38. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  39. package/dist/commonjs/core/fetchers/thumbnails/thumbnail_fetcher.js +34 -30
  40. package/dist/commonjs/experimental/features/worker/index.d.ts +2 -1
  41. package/dist/commonjs/experimental/features/worker/index.d.ts.map +1 -1
  42. package/dist/commonjs/experimental/features/worker/index.js +4 -3
  43. package/dist/commonjs/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.d.ts.map +1 -1
  44. package/dist/commonjs/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.js +2 -1
  45. package/dist/commonjs/experimental/tools/mediaCapabilitiesProber/probers/defaultCodecsFinder.d.ts.map +1 -1
  46. package/dist/commonjs/experimental/tools/mediaCapabilitiesProber/probers/defaultCodecsFinder.js +8 -6
  47. package/dist/commonjs/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.d.ts.map +1 -1
  48. package/dist/commonjs/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.js +4 -3
  49. package/dist/commonjs/initialize_worker.js +1 -1
  50. package/dist/commonjs/main_thread/api/debug/modules/segment_buffer_content.js +3 -3
  51. package/dist/commonjs/main_thread/api/public_api.js +3 -3
  52. package/dist/commonjs/main_thread/init/utils/update_manifest_codec_support.d.ts.map +1 -1
  53. package/dist/commonjs/main_thread/init/utils/update_manifest_codec_support.js +24 -12
  54. package/dist/commonjs/manifest/classes/adaptation.d.ts.map +1 -1
  55. package/dist/commonjs/manifest/classes/adaptation.js +3 -1
  56. package/dist/commonjs/manifest/classes/representation.d.ts +6 -2
  57. package/dist/commonjs/manifest/classes/representation.d.ts.map +1 -1
  58. package/dist/commonjs/manifest/classes/representation.js +45 -23
  59. package/dist/commonjs/manifest/types.d.ts +14 -6
  60. package/dist/commonjs/manifest/types.d.ts.map +1 -1
  61. package/dist/commonjs/manifest/utils.js +4 -4
  62. package/dist/commonjs/mse/main_media_source_interface.d.ts.map +1 -1
  63. package/dist/commonjs/mse/main_media_source_interface.js +3 -2
  64. package/dist/commonjs/mse/worker_media_source_interface.d.ts.map +1 -1
  65. package/dist/commonjs/parsers/containers/isobmff/get_box.d.ts +12 -1
  66. package/dist/commonjs/parsers/containers/isobmff/get_box.d.ts.map +1 -1
  67. package/dist/commonjs/parsers/containers/isobmff/get_box.js +16 -0
  68. package/dist/commonjs/parsers/containers/isobmff/index.d.ts +2 -1
  69. package/dist/commonjs/parsers/containers/isobmff/index.d.ts.map +1 -1
  70. package/dist/commonjs/parsers/containers/isobmff/index.js +3 -1
  71. package/dist/commonjs/parsers/containers/isobmff/remove_dolby_vision_config_data.d.ts +13 -0
  72. package/dist/commonjs/parsers/containers/isobmff/remove_dolby_vision_config_data.d.ts.map +1 -0
  73. package/dist/commonjs/parsers/containers/isobmff/remove_dolby_vision_config_data.js +180 -0
  74. package/dist/commonjs/parsers/manifest/metaplaylist/metaplaylist_parser.js +4 -4
  75. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  76. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  77. package/dist/commonjs/transports/dash/segment_parser.d.ts.map +1 -1
  78. package/dist/commonjs/transports/dash/segment_parser.js +6 -0
  79. package/dist/commonjs/transports/metaplaylist/pipelines.d.ts.map +1 -1
  80. package/dist/commonjs/transports/metaplaylist/pipelines.js +2 -1
  81. package/dist/commonjs/transports/smooth/pipelines.js +3 -3
  82. package/dist/commonjs/transports/types.d.ts +28 -2
  83. package/dist/commonjs/transports/types.d.ts.map +1 -1
  84. package/dist/commonjs/transports/utils/parse_text_track.js +1 -1
  85. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.d.ts.map +1 -1
  86. package/dist/es2017/__GENERATED_CODE/embedded_dash_wasm.js +1 -1
  87. package/dist/es2017/__GENERATED_CODE/embedded_worker.d.ts.map +1 -1
  88. package/dist/es2017/__GENERATED_CODE/embedded_worker.js +1 -1
  89. package/dist/es2017/compat/browser_compatibility_types.d.ts +16 -14
  90. package/dist/es2017/compat/browser_compatibility_types.d.ts.map +1 -1
  91. package/dist/es2017/compat/browser_compatibility_types.js +7 -1
  92. package/dist/es2017/compat/browser_version.d.ts +2 -1
  93. package/dist/es2017/compat/browser_version.d.ts.map +1 -1
  94. package/dist/es2017/compat/browser_version.js +13 -1
  95. package/dist/es2017/compat/disable_remote_playback_on_managed_media_source.d.ts.map +1 -1
  96. package/dist/es2017/compat/disable_remote_playback_on_managed_media_source.js +2 -2
  97. package/dist/es2017/compat/is_codec_supported.d.ts.map +1 -1
  98. package/dist/es2017/compat/is_codec_supported.js +2 -1
  99. package/dist/es2017/compat/should_patch_out_dolby_vision_config_data_from_mp4.d.ts +26 -0
  100. package/dist/es2017/compat/should_patch_out_dolby_vision_config_data_from_mp4.d.ts.map +1 -0
  101. package/dist/es2017/compat/should_patch_out_dolby_vision_config_data_from_mp4.js +42 -0
  102. package/dist/es2017/core/cmcd/cmcd_data_builder.js +2 -2
  103. package/dist/es2017/core/entry/content_preparer.d.ts +1 -6
  104. package/dist/es2017/core/entry/content_preparer.d.ts.map +1 -1
  105. package/dist/es2017/core/entry/content_preparer.js +1 -76
  106. package/dist/es2017/core/entry/core_entry.d.ts +1 -1
  107. package/dist/es2017/core/entry/core_entry.d.ts.map +1 -1
  108. package/dist/es2017/core/entry/core_entry.js +2 -7
  109. package/dist/es2017/core/entry/core_text_displayer_interface.d.ts.map +1 -1
  110. package/dist/es2017/core/entry/core_text_displayer_interface.js +3 -1
  111. package/dist/es2017/core/entry/index.d.ts +1 -1
  112. package/dist/es2017/core/entry/index.d.ts.map +1 -1
  113. package/dist/es2017/core/entry/utils.d.ts +64 -0
  114. package/dist/es2017/core/entry/utils.d.ts.map +1 -1
  115. package/dist/es2017/core/entry/utils.js +98 -0
  116. package/dist/es2017/core/fetchers/segment/segment_fetcher.d.ts.map +1 -1
  117. package/dist/es2017/core/fetchers/segment/segment_fetcher.js +2 -1
  118. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts +5 -6
  119. package/dist/es2017/core/fetchers/segment/segment_queue.d.ts.map +1 -1
  120. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.d.ts.map +1 -1
  121. package/dist/es2017/core/fetchers/thumbnails/thumbnail_fetcher.js +21 -16
  122. package/dist/es2017/experimental/features/worker/index.d.ts +2 -1
  123. package/dist/es2017/experimental/features/worker/index.d.ts.map +1 -1
  124. package/dist/es2017/experimental/features/worker/index.js +2 -3
  125. package/dist/es2017/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.d.ts.map +1 -1
  126. package/dist/es2017/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.js +2 -1
  127. package/dist/es2017/experimental/tools/mediaCapabilitiesProber/probers/defaultCodecsFinder.d.ts.map +1 -1
  128. package/dist/es2017/experimental/tools/mediaCapabilitiesProber/probers/defaultCodecsFinder.js +3 -1
  129. package/dist/es2017/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.d.ts.map +1 -1
  130. package/dist/es2017/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.js +2 -1
  131. package/dist/es2017/initialize_worker.js +1 -1
  132. package/dist/es2017/main_thread/api/debug/modules/segment_buffer_content.js +3 -3
  133. package/dist/es2017/main_thread/api/public_api.js +3 -3
  134. package/dist/es2017/main_thread/init/utils/update_manifest_codec_support.d.ts.map +1 -1
  135. package/dist/es2017/main_thread/init/utils/update_manifest_codec_support.js +9 -7
  136. package/dist/es2017/manifest/classes/adaptation.d.ts.map +1 -1
  137. package/dist/es2017/manifest/classes/adaptation.js +3 -1
  138. package/dist/es2017/manifest/classes/representation.d.ts +6 -2
  139. package/dist/es2017/manifest/classes/representation.d.ts.map +1 -1
  140. package/dist/es2017/manifest/classes/representation.js +45 -23
  141. package/dist/es2017/manifest/types.d.ts +14 -6
  142. package/dist/es2017/manifest/types.d.ts.map +1 -1
  143. package/dist/es2017/manifest/utils.js +4 -4
  144. package/dist/es2017/mse/main_media_source_interface.d.ts.map +1 -1
  145. package/dist/es2017/mse/main_media_source_interface.js +2 -1
  146. package/dist/es2017/mse/worker_media_source_interface.d.ts.map +1 -1
  147. package/dist/es2017/parsers/containers/isobmff/get_box.d.ts +12 -1
  148. package/dist/es2017/parsers/containers/isobmff/get_box.d.ts.map +1 -1
  149. package/dist/es2017/parsers/containers/isobmff/get_box.js +16 -1
  150. package/dist/es2017/parsers/containers/isobmff/index.d.ts +2 -1
  151. package/dist/es2017/parsers/containers/isobmff/index.d.ts.map +1 -1
  152. package/dist/es2017/parsers/containers/isobmff/index.js +2 -1
  153. package/dist/es2017/parsers/containers/isobmff/remove_dolby_vision_config_data.d.ts +13 -0
  154. package/dist/es2017/parsers/containers/isobmff/remove_dolby_vision_config_data.d.ts.map +1 -0
  155. package/dist/es2017/parsers/containers/isobmff/remove_dolby_vision_config_data.js +155 -0
  156. package/dist/es2017/parsers/manifest/metaplaylist/metaplaylist_parser.js +4 -4
  157. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.d.ts.map +1 -1
  158. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +16 -1
  159. package/dist/es2017/transports/dash/segment_parser.d.ts.map +1 -1
  160. package/dist/es2017/transports/dash/segment_parser.js +7 -1
  161. package/dist/es2017/transports/metaplaylist/pipelines.d.ts.map +1 -1
  162. package/dist/es2017/transports/metaplaylist/pipelines.js +2 -1
  163. package/dist/es2017/transports/smooth/pipelines.js +3 -3
  164. package/dist/es2017/transports/types.d.ts +28 -2
  165. package/dist/es2017/transports/types.d.ts.map +1 -1
  166. package/dist/es2017/transports/utils/parse_text_track.js +1 -1
  167. package/dist/mpd-parser.wasm +0 -0
  168. package/dist/worker.js +8 -8
  169. package/eslint.config.mjs +1 -14
  170. package/package.json +19 -22
  171. package/src/__GENERATED_CODE/embedded_dash_wasm.ts +1 -1
  172. package/src/__GENERATED_CODE/embedded_worker.ts +1 -1
  173. package/src/compat/__tests__/browser_compatibility_types.test.ts +15 -26
  174. package/src/compat/__tests__/browser_version.test.ts +57 -18
  175. package/src/compat/__tests__/clear_element_src.test.ts +20 -40
  176. package/src/compat/__tests__/is_codec_supported.test.ts +39 -44
  177. package/src/compat/__tests__/is_vtt_cue.test.ts +5 -8
  178. package/src/compat/__tests__/make_vtt_cue.test.ts +20 -31
  179. package/src/compat/__tests__/remove_cue.test.ts +8 -20
  180. package/src/compat/__tests__/should_patch_out_dolby_vision_config_data_from_mp4.test.ts +78 -0
  181. package/src/compat/browser_compatibility_types.ts +8 -1
  182. package/src/compat/browser_version.ts +17 -1
  183. package/src/compat/disable_remote_playback_on_managed_media_source.ts +2 -2
  184. package/src/compat/is_codec_supported.ts +2 -1
  185. package/src/compat/should_patch_out_dolby_vision_config_data_from_mp4.ts +50 -0
  186. package/src/core/adaptive/__tests__/adaptive_representation_selector.test.ts +774 -0
  187. package/src/core/adaptive/__tests__/buffer_based_chooser.test.ts +26 -84
  188. package/src/core/adaptive/__tests__/guess_based_chooser.test.ts +5 -2
  189. package/src/core/adaptive/utils/__tests__/bandwidth_estimator.test.ts +117 -0
  190. package/src/core/adaptive/utils/__tests__/last_estimate_storage.test.ts +76 -0
  191. package/src/core/adaptive/utils/__tests__/pending_requests_store.test.ts +5 -2
  192. package/src/core/adaptive/utils/__tests__/representation_score_calculator.test.ts +4 -2
  193. package/src/core/cmcd/__tests__/cmcd_data_builder.test.ts +464 -0
  194. package/src/core/cmcd/cmcd_data_builder.ts +2 -2
  195. package/src/core/entry/__tests__/FreezeResolver.test.ts +1 -1
  196. package/src/core/entry/__tests__/content_time_boundaries_observer.test.ts +1 -2
  197. package/src/core/entry/__tests__/core_text_displayer_interface.test.ts +205 -0
  198. package/src/core/entry/__tests__/get_buffered_data_per_media_buffer.test.ts +95 -0
  199. package/src/core/entry/__tests__/track_choice_setter.test.ts +288 -0
  200. package/src/core/entry/__tests__/utils.test.ts +315 -0
  201. package/src/core/entry/content_preparer.ts +7 -118
  202. package/src/core/entry/core_entry.ts +7 -14
  203. package/src/core/entry/core_text_displayer_interface.ts +3 -1
  204. package/src/core/entry/index.ts +1 -1
  205. package/src/core/entry/utils.ts +151 -0
  206. package/src/core/fetchers/__tests__/cdn_prioritizer.test.ts +166 -0
  207. package/src/core/fetchers/manifest/__tests__/manifest_fetcher.test.ts +803 -0
  208. package/src/core/fetchers/segment/__tests__/segment_fetcher.test.ts +872 -0
  209. package/src/core/fetchers/segment/__tests__/segment_queue.test.ts +557 -0
  210. package/src/core/fetchers/segment/segment_fetcher.ts +2 -1
  211. package/src/core/fetchers/segment/segment_queue.ts +5 -6
  212. package/src/core/fetchers/thumbnails/__tests__/thumbnail_fetcher.test.ts +435 -0
  213. package/src/core/fetchers/thumbnails/thumbnail_fetcher.ts +28 -20
  214. package/src/core/fetchers/utils/__tests__/schedule_request.test.ts +331 -0
  215. package/src/core/stream/adaptation/__tests__/get_representations_switch_strategy.test.ts +4 -3
  216. package/src/core/stream/representation/utils/__tests__/append_segment_to_buffer.test.ts +1 -1
  217. package/src/core/stream/representation/utils/__tests__/get_segment_priority.test.ts +1 -1
  218. package/src/core/stream/representation/utils/__tests__/push_init_segment.test.ts +1 -1
  219. package/src/core/stream/representation/utils/__tests__/push_media_segment.test.ts +1 -1
  220. package/src/errors/__tests__/format_error.test.ts +23 -24
  221. package/src/experimental/features/worker/index.ts +2 -4
  222. package/src/experimental/tools/VideoThumbnailLoader/prepare_source_buffer.ts +2 -1
  223. package/src/experimental/tools/mediaCapabilitiesProber/__tests__/probers/mediaDisplayInfos.test.ts +106 -0
  224. package/src/experimental/tools/mediaCapabilitiesProber/probers/__tests__/HDCPPolicy.test.ts +19 -42
  225. package/src/experimental/tools/mediaCapabilitiesProber/probers/__tests__/decodingInfo.test.ts +33 -40
  226. package/src/experimental/tools/mediaCapabilitiesProber/probers/__tests__/defaultCodecsFinder.test.ts +44 -68
  227. package/src/experimental/tools/mediaCapabilitiesProber/probers/__tests__/mediaContentType.test.ts +45 -80
  228. package/src/experimental/tools/mediaCapabilitiesProber/probers/defaultCodecsFinder.ts +3 -1
  229. package/src/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.ts +2 -1
  230. package/src/features/__tests__/add_features.test.ts +12 -27
  231. package/src/initialize_worker.ts +1 -1
  232. package/src/main_thread/api/__tests__/option_utils.test.ts +38 -67
  233. package/src/main_thread/api/__tests__/public_api.test.ts +56 -138
  234. package/src/main_thread/api/debug/modules/segment_buffer_content.ts +3 -3
  235. package/src/main_thread/api/public_api.ts +3 -3
  236. package/src/main_thread/decrypt/__tests__/__global__/find_key_system.test.ts +46 -28
  237. package/src/main_thread/decrypt/__tests__/__global__/get_license.test.ts +40 -10
  238. package/src/main_thread/decrypt/__tests__/__global__/init_data.test.ts +112 -129
  239. package/src/main_thread/decrypt/__tests__/__global__/media_key_system_access.test.ts +282 -377
  240. package/src/main_thread/decrypt/__tests__/__global__/media_keys.test.ts +70 -63
  241. package/src/main_thread/decrypt/__tests__/__global__/server_certificate.test.ts +73 -54
  242. package/src/main_thread/decrypt/__tests__/__global__/utils.ts +43 -83
  243. package/src/main_thread/decrypt/__tests__/find_key_system.test.ts +36 -17
  244. package/src/main_thread/decrypt/utils/__tests__/clean_old_stored_persistent_info.test.ts +44 -48
  245. package/src/main_thread/init/utils/__tests__/are_same_stream_events.test.ts +7 -22
  246. package/src/main_thread/init/utils/__tests__/refresh_scheduled_events_list.test.ts +3 -6
  247. package/src/main_thread/init/utils/__tests__/update_manifest_codec_support.test.ts +42 -19
  248. package/src/main_thread/init/utils/update_manifest_codec_support.ts +8 -6
  249. package/src/manifest/classes/__tests__/adaptation.test.ts +69 -125
  250. package/src/manifest/classes/__tests__/manifest.test.ts +88 -95
  251. package/src/manifest/classes/__tests__/period.test.ts +167 -117
  252. package/src/manifest/classes/__tests__/representation.test.ts +84 -25
  253. package/src/manifest/classes/__tests__/update_periods.test.ts +96 -225
  254. package/src/manifest/classes/adaptation.ts +4 -1
  255. package/src/manifest/classes/representation.ts +59 -27
  256. package/src/manifest/types.ts +14 -6
  257. package/src/manifest/utils.ts +4 -4
  258. package/src/mse/__tests__/main_media_source_interface.test.ts +848 -0
  259. package/src/mse/__tests__/worker_media_source_interface.test.ts +608 -0
  260. package/src/mse/main_media_source_interface.ts +2 -1
  261. package/src/mse/worker_media_source_interface.ts +2 -2
  262. package/src/parsers/containers/isobmff/__tests__/get_box.test.ts +449 -0
  263. package/src/parsers/containers/isobmff/__tests__/remove_dolby_vision_config_data.test.ts +282 -0
  264. package/src/parsers/containers/isobmff/get_box.ts +17 -0
  265. package/src/parsers/containers/isobmff/index.ts +8 -1
  266. package/src/parsers/containers/isobmff/remove_dolby_vision_config_data.ts +179 -0
  267. package/src/parsers/manifest/dash/common/__tests__/get_clock_offset.test.ts +19 -25
  268. package/src/parsers/manifest/dash/common/__tests__/get_http_utc-timing_url.test.ts +7 -19
  269. package/src/parsers/manifest/dash/js-parser/node_parsers/__tests__/ContentProtection.test.ts +26 -37
  270. package/src/parsers/manifest/dash/js-parser/node_parsers/__tests__/Initialization.test.ts +24 -53
  271. package/src/parsers/manifest/dash/js-parser/node_parsers/__tests__/SegmentURL.test.ts +31 -78
  272. package/src/parsers/manifest/metaplaylist/metaplaylist_parser.ts +6 -4
  273. package/src/parsers/manifest/utils/__tests__/update_segment_timeline.test.ts +79 -87
  274. package/src/parsers/texttracks/ttml/__tests__/resolve_styles_inheritance.test.ts +20 -26
  275. package/src/parsers/texttracks/ttml/html/__tests__/__global__/html_ttml_parser.test.ts +2 -7
  276. package/src/parsers/texttracks/ttml/html/apply_line_height.ts +16 -1
  277. package/src/parsers/texttracks/webvtt/__tests__/parse_cue_block.test.ts +33 -30
  278. package/src/parsers/texttracks/webvtt/__tests__/parse_style_block.test.ts +33 -100
  279. package/src/parsers/texttracks/webvtt/html/__tests__/convert_payload_to_html.test.ts +16 -18
  280. package/src/parsers/texttracks/webvtt/html/__tests__/parse_webvtt_to_div.test.ts +73 -78
  281. package/src/parsers/texttracks/webvtt/html/__tests__/to_html.test.ts +36 -37
  282. package/src/transports/dash/segment_parser.ts +13 -0
  283. package/src/transports/metaplaylist/pipelines.ts +2 -1
  284. package/src/transports/smooth/isobmff/__tests__/create_boxes.test.ts +150 -127
  285. package/src/transports/smooth/pipelines.ts +3 -3
  286. package/src/transports/types.ts +28 -2
  287. package/src/transports/utils/__tests__/check_isobmff_integrity.test.ts +49 -75
  288. package/src/transports/utils/parse_text_track.ts +1 -1
  289. package/src/utils/__tests__/base64.test.ts +159 -191
  290. package/src/utils/__tests__/object_assign.test.ts +2 -2
@@ -0,0 +1,331 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
+ import { NetworkErrorTypes } from "../../../../errors";
3
+ import { RequestError } from "../../../../utils/request";
4
+ import TaskCanceller from "../../../../utils/task_canceller";
5
+ import { scheduleRequestWithCdns, scheduleRequestPromise } from "../schedule_request";
6
+
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
9
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
10
+
11
+ const { mockLog, mockCancellableSleep, mockGetFuzzedDelay, mockGetTimestamp } =
12
+ vi.hoisted(() => {
13
+ return {
14
+ mockLog: { warn: vi.fn() },
15
+ mockCancellableSleep: vi.fn(),
16
+ mockGetFuzzedDelay: vi.fn((delay: number) => delay),
17
+ mockGetTimestamp: vi.fn(() => 0),
18
+ };
19
+ });
20
+
21
+ vi.mock("../../../log", () => ({ default: mockLog }));
22
+ vi.mock("../../../utils/cancellable_sleep", () => ({ default: mockCancellableSleep }));
23
+ vi.mock("../../../utils/get_fuzzed_delay", () => ({ default: mockGetFuzzedDelay }));
24
+ vi.mock("../../../utils/monotonic_timestamp", () => ({ default: mockGetTimestamp }));
25
+
26
+ const defaultOptions = {
27
+ baseDelay: 100,
28
+ maxDelay: 2000,
29
+ maxRetry: 3,
30
+ onRetry: vi.fn(),
31
+ };
32
+
33
+ function makeCdn(id: string): any {
34
+ return { baseUrl: id };
35
+ }
36
+
37
+ beforeEach(() => {
38
+ mockGetTimestamp.mockReturnValue(0);
39
+ mockGetFuzzedDelay.mockImplementation((delay: number) => delay);
40
+ // By default cancellableSleep resolves immediately
41
+ mockCancellableSleep.mockResolvedValue(undefined);
42
+ });
43
+
44
+ afterEach(() => {
45
+ vi.resetAllMocks();
46
+ });
47
+
48
+ describe.skip("scheduleRequestWithCdns", () => {
49
+ it("resolves with the result of a successful request", async () => {
50
+ const cdn = makeCdn("https://cdn1.example.com");
51
+ const performRequest = vi.fn().mockResolvedValue("ok");
52
+ const result = await scheduleRequestWithCdns(
53
+ [cdn],
54
+ null,
55
+ performRequest,
56
+ defaultOptions,
57
+ new TaskCanceller("test").signal,
58
+ );
59
+ expect(result).toBe("ok");
60
+ expect(performRequest).toHaveBeenCalledTimes(1);
61
+ expect(performRequest).toHaveBeenCalledWith(cdn, expect.anything());
62
+ });
63
+
64
+ it("passes null cdn when cdns param is null", async () => {
65
+ const performRequest = vi.fn().mockResolvedValue("data");
66
+ await scheduleRequestWithCdns(
67
+ null,
68
+ null,
69
+ performRequest,
70
+ defaultOptions,
71
+ new TaskCanceller("test").signal,
72
+ );
73
+ expect(performRequest).toHaveBeenCalledWith(null, expect.anything());
74
+ });
75
+
76
+ it("throws immediately if cancellationSignal is already cancelled", async () => {
77
+ const cancellationError = new Error("cancelled");
78
+ const signal: any = {
79
+ cancellationError,
80
+ isCancelled: () => true,
81
+ };
82
+
83
+ await expect(
84
+ scheduleRequestWithCdns([makeCdn("a")], null, vi.fn(), defaultOptions, signal),
85
+ ).rejects.toThrow("cancelled");
86
+ });
87
+
88
+ it("throws 'No CDN to request' when given an empty CDN array", async () => {
89
+ await expect(
90
+ scheduleRequestWithCdns(
91
+ [],
92
+ null,
93
+ vi.fn(),
94
+ defaultOptions,
95
+ new TaskCanceller("test").signal,
96
+ ),
97
+ ).rejects.toThrow("No CDN to request");
98
+ expect(mockLog.warn).toHaveBeenCalled();
99
+ });
100
+
101
+ it("retries on a 500 HTTP error and resolves on second attempt", async () => {
102
+ const cdn = makeCdn("https://cdn1.example.com");
103
+ const error = new RequestError("url", 500, NetworkErrorTypes.ERROR_HTTP_CODE);
104
+ const performRequest = vi
105
+ .fn()
106
+ .mockRejectedValueOnce(error)
107
+ .mockResolvedValueOnce("recovered");
108
+
109
+ const onRetry = vi.fn();
110
+ const result = await scheduleRequestWithCdns(
111
+ [cdn],
112
+ null,
113
+ performRequest,
114
+ { ...defaultOptions, onRetry },
115
+ new TaskCanceller("test").signal,
116
+ );
117
+ expect(result).toBe("recovered");
118
+ expect(onRetry).toHaveBeenCalledTimes(1);
119
+ expect(onRetry).toHaveBeenCalledWith(error);
120
+ });
121
+
122
+ it("retries on TIMEOUT error", async () => {
123
+ const cdn = makeCdn("https://cdn1.example.com");
124
+ const error = new RequestError("url", 0, NetworkErrorTypes.TIMEOUT);
125
+ const performRequest = vi
126
+ .fn()
127
+ .mockRejectedValueOnce(error)
128
+ .mockResolvedValueOnce("ok");
129
+ const result = await scheduleRequestWithCdns(
130
+ [cdn],
131
+ null,
132
+ performRequest,
133
+ defaultOptions,
134
+ new TaskCanceller("test").signal,
135
+ );
136
+ expect(result).toBe("ok");
137
+ });
138
+
139
+ it("does NOT retry on a 403 HTTP error and rejects immediately", async () => {
140
+ const cdn = makeCdn("https://cdn1.example.com");
141
+ const error = new RequestError("url", 403, NetworkErrorTypes.ERROR_HTTP_CODE);
142
+ const performRequest = vi.fn().mockRejectedValue(error);
143
+ const onRetry = vi.fn();
144
+
145
+ await expect(
146
+ scheduleRequestWithCdns(
147
+ [cdn],
148
+ null,
149
+ performRequest,
150
+ { ...defaultOptions, maxRetry: 5, onRetry },
151
+ new TaskCanceller("test").signal,
152
+ ),
153
+ ).rejects.toThrow();
154
+ // 403 should not be retried — performRequest called once only
155
+ expect(performRequest).toHaveBeenCalledTimes(1);
156
+ expect(onRetry).not.toHaveBeenCalled();
157
+ });
158
+
159
+ it("blacklists a CDN after maxRetry exhaustion and rejects", async () => {
160
+ const cdn = makeCdn("https://cdn1.example.com");
161
+ const error = new RequestError("url", 500, NetworkErrorTypes.ERROR_HTTP_CODE);
162
+ const performRequest = vi.fn().mockRejectedValue(error);
163
+ const onRetry = vi.fn();
164
+ const maxRetry = 2;
165
+
166
+ await expect(
167
+ scheduleRequestWithCdns(
168
+ [cdn],
169
+ null,
170
+ performRequest,
171
+ { ...defaultOptions, maxRetry, onRetry },
172
+ new TaskCanceller("test").signal,
173
+ ),
174
+ ).rejects.toThrow();
175
+
176
+ // initial attempt + maxRetry retries = maxRetry+1 calls
177
+ expect(performRequest).toHaveBeenCalledTimes(maxRetry + 1);
178
+ });
179
+
180
+ it("falls over to next CDN when first CDN fails with a non-retryable error", async () => {
181
+ const cdn1 = makeCdn("https://cdn1.example.com");
182
+ const cdn2 = makeCdn("https://cdn2.example.com");
183
+ // 403 is non-retryable → should move to cdn2
184
+ const error403 = new RequestError("url", 403, NetworkErrorTypes.ERROR_HTTP_CODE);
185
+ const performRequest = vi
186
+ .fn()
187
+ .mockRejectedValueOnce(error403)
188
+ .mockResolvedValueOnce("cdn2-response");
189
+
190
+ const result = await scheduleRequestWithCdns(
191
+ [cdn1, cdn2],
192
+ null,
193
+ performRequest,
194
+ defaultOptions,
195
+ new TaskCanceller("test").signal,
196
+ );
197
+ expect(result).toBe("cdn2-response");
198
+ expect(performRequest).toHaveBeenNthCalledWith(1, cdn1, expect.anything());
199
+ expect(performRequest).toHaveBeenNthCalledWith(2, cdn2, expect.anything());
200
+ });
201
+
202
+ it("rejects with the last error when all CDNs are exhausted", async () => {
203
+ const cdn1 = makeCdn("cdn1");
204
+ const cdn2 = makeCdn("cdn2");
205
+ const error1 = new RequestError("url1", 403, NetworkErrorTypes.ERROR_HTTP_CODE);
206
+ const error2 = new RequestError("url2", 403, NetworkErrorTypes.ERROR_HTTP_CODE);
207
+ const performRequest = vi
208
+ .fn()
209
+ .mockRejectedValueOnce(error1)
210
+ .mockRejectedValueOnce(error2);
211
+
212
+ await expect(
213
+ scheduleRequestWithCdns(
214
+ [cdn1, cdn2],
215
+ null,
216
+ performRequest,
217
+ defaultOptions,
218
+ new TaskCanceller("test").signal,
219
+ ),
220
+ ).rejects.toThrow();
221
+ expect(performRequest).toHaveBeenCalledTimes(2);
222
+ });
223
+
224
+ it("downgrades CDN in prioritizer after failure", async () => {
225
+ const cdn = makeCdn("cdn1");
226
+ const error = new RequestError("url", 403, NetworkErrorTypes.ERROR_HTTP_CODE);
227
+ const cdnPrioritizer = {
228
+ getCdnPreferenceForResource: vi.fn().mockReturnValue([cdn]),
229
+ downgradeCdn: vi.fn(),
230
+ addEventListener: vi.fn(),
231
+ };
232
+ const performRequest = vi.fn().mockRejectedValue(error);
233
+
234
+ await expect(
235
+ scheduleRequestWithCdns(
236
+ [cdn],
237
+ cdnPrioritizer as never,
238
+ performRequest,
239
+ defaultOptions,
240
+ new TaskCanceller("test").signal,
241
+ ),
242
+ ).rejects.toThrow();
243
+
244
+ expect(cdnPrioritizer.downgradeCdn).toHaveBeenCalledWith(cdn);
245
+ });
246
+
247
+ it("retries on INTEGRITY_ERROR", async () => {
248
+ const cdn = makeCdn("cdn1");
249
+ const integrityError = { code: "INTEGRITY_ERROR" };
250
+ const performRequest = vi
251
+ .fn()
252
+ .mockRejectedValueOnce(integrityError)
253
+ .mockResolvedValueOnce("ok");
254
+
255
+ const result = await scheduleRequestWithCdns(
256
+ [cdn],
257
+ null,
258
+ performRequest,
259
+ { ...defaultOptions, maxRetry: 2 },
260
+ new TaskCanceller("test").signal,
261
+ );
262
+ expect(result).toBe("ok");
263
+ });
264
+
265
+ it("computes exponential backoff delay capped at maxDelay", async () => {
266
+ const cdn = makeCdn("cdn1");
267
+ const error = new RequestError("url", 500, NetworkErrorTypes.ERROR_HTTP_CODE);
268
+ // Fail twice then succeed
269
+ const performRequest = vi
270
+ .fn()
271
+ .mockRejectedValueOnce(error)
272
+ .mockRejectedValueOnce(error)
273
+ .mockResolvedValueOnce("done");
274
+
275
+ const baseDelay = 100;
276
+ const maxDelay = 150;
277
+
278
+ await scheduleRequestWithCdns(
279
+ [cdn],
280
+ null,
281
+ performRequest,
282
+ { baseDelay, maxDelay, maxRetry: 5, onRetry: vi.fn() },
283
+ new TaskCanceller("test").signal,
284
+ );
285
+
286
+ // After 1st failure: delay = min(100 * 2^0, 150) = 100
287
+ // After 2nd failure: delay = min(100 * 2^1, 150) = 150
288
+ expect(mockGetFuzzedDelay).toHaveBeenNthCalledWith(1, 100);
289
+ expect(mockGetFuzzedDelay).toHaveBeenNthCalledWith(2, 150);
290
+ });
291
+ });
292
+
293
+ describe("scheduleRequestPromise", () => {
294
+ it("resolves with the performRequest result", async () => {
295
+ const performRequest = vi.fn().mockResolvedValue("result");
296
+ const result = await scheduleRequestPromise(
297
+ performRequest,
298
+ defaultOptions,
299
+ new TaskCanceller("test").signal,
300
+ );
301
+ expect(result).toBe("result");
302
+ });
303
+
304
+ it("retries and resolves after transient failure", async () => {
305
+ const error = new RequestError("url", 500, NetworkErrorTypes.ERROR_HTTP_CODE);
306
+ const performRequest = vi
307
+ .fn()
308
+ .mockRejectedValueOnce(error)
309
+ .mockResolvedValueOnce("ok");
310
+ const result = await scheduleRequestPromise(
311
+ performRequest,
312
+ { ...defaultOptions, maxRetry: 2 },
313
+ new TaskCanceller("test").signal,
314
+ );
315
+ expect(result).toBe("ok");
316
+ });
317
+
318
+ it("rejects after all retries are exhausted", async () => {
319
+ const error = new RequestError("url", 500, NetworkErrorTypes.ERROR_HTTP_CODE);
320
+ const performRequest = vi.fn().mockRejectedValue(error);
321
+ await expect(
322
+ scheduleRequestPromise(
323
+ performRequest,
324
+ { ...defaultOptions, maxRetry: 1 },
325
+ new TaskCanceller("test").signal,
326
+ ),
327
+ ).rejects.toThrow();
328
+ // 1 initial + 1 retry = 2 total
329
+ expect(performRequest).toHaveBeenCalledTimes(2);
330
+ });
331
+ });
@@ -1,4 +1,4 @@
1
- import { describe, it, expect, vi, beforeEach } from "vitest";
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
2
  import type { IAdaptation, IPeriod } from "../../../../manifest";
3
3
  import type { IReadOnlyPlaybackObserver } from "../../../../playback_observer";
4
4
  import type { SegmentSink } from "../../../segment_sinks";
@@ -30,8 +30,6 @@ describe("getRepresentationsSwitchingStrategy", () => {
30
30
  let mockPlaybackObserver: any;
31
31
 
32
32
  beforeEach(() => {
33
- vi.clearAllMocks();
34
-
35
33
  mockPeriod = {
36
34
  id: "period-1",
37
35
  start: 0,
@@ -60,6 +58,9 @@ describe("getRepresentationsSwitchingStrategy", () => {
60
58
  })),
61
59
  } as unknown as IReadOnlyPlaybackObserver<any>;
62
60
  });
61
+ afterEach(() => {
62
+ vi.resetAllMocks();
63
+ });
63
64
 
64
65
  describe("lazy switching mode", () => {
65
66
  it("should return continue when switching mode is lazy", () => {
@@ -51,7 +51,7 @@ describe("appendSegmentToBuffer", () => {
51
51
  });
52
52
 
53
53
  afterEach(() => {
54
- vi.clearAllMocks();
54
+ vi.resetAllMocks();
55
55
  });
56
56
 
57
57
  describe("successful append", () => {
@@ -17,7 +17,7 @@ describe("getSegmentPriority", () => {
17
17
  });
18
18
 
19
19
  afterEach(() => {
20
- vi.clearAllMocks();
20
+ vi.resetAllMocks();
21
21
  });
22
22
 
23
23
  describe("priority based on distance from wanted timestamp", () => {
@@ -21,7 +21,7 @@ describe("pushInitSegment", () => {
21
21
  let mockSegment: any;
22
22
 
23
23
  beforeEach(() => {
24
- vi.clearAllMocks();
24
+ vi.resetAllMocks();
25
25
 
26
26
  mockPlaybackObserver = {};
27
27
 
@@ -46,7 +46,7 @@ describe("pushMediaSegment", () => {
46
46
  } as any;
47
47
 
48
48
  beforeEach(() => {
49
- vi.clearAllMocks();
49
+ vi.resetAllMocks();
50
50
  mockGetCurrent.mockReturnValue({
51
51
  APPEND_WINDOW_SECURITIES: {
52
52
  START: 0.1,
@@ -1,29 +1,34 @@
1
- import { describe, beforeEach, it, expect, vi } from "vitest";
2
- import type IFormatError from "../format_error";
1
+ import { describe, beforeEach, it, expect, vi, afterEach } from "vitest";
2
+ import formatError from "../format_error";
3
+ import OtherError from "../other_error";
3
4
 
5
+ const mocks = vi.hoisted(() => {
6
+ return {
7
+ isKnownError: vi.fn(),
8
+ };
9
+ });
10
+
11
+ vi.mock("../is_known_error", () => {
12
+ return {
13
+ default: mocks.isKnownError,
14
+ };
15
+ });
4
16
  describe("errors - formatError", () => {
5
17
  beforeEach(() => {
6
18
  vi.resetModules();
7
19
  });
20
+ afterEach(() => {
21
+ mocks.isKnownError.mockReset();
22
+ });
8
23
 
9
- it("should just return the error if it is a Custom Error", async () => {
10
- vi.doMock("../is_known_error", () => ({
11
- default: () => true,
12
- }));
13
- const formatError = (await vi.importActual("../format_error"))
14
- .default as typeof IFormatError;
24
+ it("should just return the error if it is a Custom Error", () => {
25
+ mocks.isKnownError.mockImplementation(() => true);
15
26
  const error1 = new Error("Aaaaaa");
16
27
  expect(formatError(error1, { defaultCode: "NONE", defaultReason: "a" })).toBe(error1);
17
28
  });
18
29
 
19
- it("should stringify error if it is an Error but not a Custom Error", async () => {
20
- vi.doMock("../is_known_error", () => ({
21
- default: () => false,
22
- }));
23
- const OtherError = (await vi.importActual("../other_error"))
24
- .default as typeof IFormatError;
25
- const formatError = (await vi.importActual("../format_error"))
26
- .default as typeof IFormatError;
30
+ it("should stringify error if it is an Error but not a Custom Error", () => {
31
+ mocks.isKnownError.mockImplementation(() => false);
27
32
  const error1 = new Error("Abcdef");
28
33
  const formattedError = formatError(error1, {
29
34
  defaultCode: "NONE",
@@ -34,14 +39,8 @@ describe("errors - formatError", () => {
34
39
  expect(formattedError.code).toBe("NONE");
35
40
  });
36
41
 
37
- it("should stringify error if it is an Error but not a Custom Error", async () => {
38
- vi.doMock("../is_known_error", () => ({
39
- default: () => false,
40
- }));
41
- const OtherError = (await vi.importActual("../other_error"))
42
- .default as typeof IFormatError;
43
- const formatError = (await vi.importActual("../format_error"))
44
- .default as typeof IFormatError;
42
+ it("should stringify error if it is an Error but not a Custom Error", () => {
43
+ mocks.isKnownError.mockImplementation(() => false);
45
44
  const error1 = {};
46
45
  const formattedError = formatError(error1, {
47
46
  defaultCode: "NONE",
@@ -1,5 +1,3 @@
1
- export { DASH, DASH_WASM } from "../../../features/list";
1
+ export { DASH, DASH_WASM, SMOOTH } from "../../../features/list";
2
2
  export { LOCAL_MANIFEST } from "../local";
3
-
4
- // TODO: `SMOOTH` (has to be made worker-compatible)
5
- // TODO: `METAPLAYLIST` (once every transport is ported)
3
+ export { METAPLAYLIST } from "../metaplaylist";
@@ -14,8 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { MediaSource_ } from "../../../compat/browser_compatibility_types";
18
17
  import type { IMediaElement } from "../../../compat/browser_compatibility_types";
18
+ import BROWSER_GLOBALS from "../../../compat/browser_compatibility_types";
19
19
  import disableRemotePlaybackOnManagedMediaSource from "../../../compat/disable_remote_playback_on_managed_media_source";
20
20
  import resetMediaElement from "../../../compat/reset_media_element";
21
21
  import log from "../../../log";
@@ -43,6 +43,7 @@ export default function prepareSourceBuffer(
43
43
  cleanUpSignal: CancellationSignal,
44
44
  ): Promise<MainSourceBufferInterface> {
45
45
  return createCancellablePromise(cleanUpSignal, (resolve, reject) => {
46
+ const { MediaSource_ } = BROWSER_GLOBALS;
46
47
  if (isNullOrUndefined(MediaSource_)) {
47
48
  throw new Error("No MediaSource Object was found in the current browser.");
48
49
  }
@@ -0,0 +1,106 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import globalScope from "../../../../../utils/global_scope";
3
+ import probeMediaDisplayInfos from "../../probers/mediaDisplayInfos";
4
+
5
+ describe("MediaCapabilitiesProber probers probeMediaDisplayInfos", () => {
6
+ it("should throw if matchMedia is undefined", async () => {
7
+ const origMatchMedia = globalScope.matchMedia;
8
+ (
9
+ globalScope as { matchMedia: typeof globalScope.matchMedia | undefined }
10
+ ).matchMedia = undefined;
11
+
12
+ expect(() => probeMediaDisplayInfos({})).toThrowError("matchMedia API not available");
13
+ (
14
+ globalScope as { matchMedia: typeof globalScope.matchMedia | undefined }
15
+ ).matchMedia = origMatchMedia;
16
+ });
17
+
18
+ it("should throw if no colorSpace in display configuration", async () => {
19
+ const mockMatchMedia = vi.fn(() => true);
20
+ globalScope.matchMedia = mockMatchMedia as unknown as typeof globalScope.matchMedia;
21
+ const config = {
22
+ display: {},
23
+ };
24
+
25
+ let err: Error | undefined;
26
+ try {
27
+ probeMediaDisplayInfos(config);
28
+ } catch (error) {
29
+ err = error as Error;
30
+ }
31
+ expect(err).not.toBe(undefined);
32
+ const { message } = err as Error;
33
+ expect(message).toBe("Not enough arguments for calling matchMedia.");
34
+ });
35
+
36
+ it("should throw if no display in configuration", async () => {
37
+ const mockMatchMedia = vi.fn(() => true);
38
+ globalScope.matchMedia = mockMatchMedia as unknown as typeof globalScope.matchMedia;
39
+ const config = {};
40
+
41
+ let err: Error | undefined;
42
+ try {
43
+ probeMediaDisplayInfos(config);
44
+ } catch (error) {
45
+ err = error as Error;
46
+ }
47
+ expect(err).not.toBe(undefined);
48
+ const { message } = err as Error;
49
+ expect(message).toBe("Not enough arguments for calling matchMedia.");
50
+ });
51
+
52
+ it("should throw if mediaMatch called with bad arguments", async () => {
53
+ const mockMatchMedia = vi.fn(() => ({
54
+ media: "not all",
55
+ }));
56
+ globalScope.matchMedia = mockMatchMedia as unknown as typeof globalScope.matchMedia;
57
+ const config = {
58
+ display: {
59
+ colorSpace: "srgb",
60
+ },
61
+ };
62
+
63
+ let err: Error | undefined;
64
+ try {
65
+ probeMediaDisplayInfos(config);
66
+ } catch (error) {
67
+ err = error as Error;
68
+ }
69
+ expect(err).not.toBe(undefined);
70
+ const { message } = err as Error;
71
+ expect(message).toBe("Bad arguments for calling matchMedia.");
72
+ expect(mockMatchMedia).toHaveBeenCalledTimes(1);
73
+ });
74
+
75
+ it("should resolves with `Supported` if color space is supported", async () => {
76
+ const mockMatchMedia = vi.fn(() => ({
77
+ matches: true,
78
+ }));
79
+ globalScope.matchMedia = mockMatchMedia as unknown as typeof globalScope.matchMedia;
80
+ const config = {
81
+ display: {
82
+ colorSpace: "srgb",
83
+ },
84
+ };
85
+
86
+ const res = probeMediaDisplayInfos(config);
87
+ expect(res).toEqual("Supported");
88
+ expect(mockMatchMedia).toHaveBeenCalledTimes(1);
89
+ });
90
+
91
+ it("should resolves with `NotSupported` if color space is not supported", async () => {
92
+ const mockMatchMedia = vi.fn(() => ({
93
+ matches: false,
94
+ }));
95
+ globalScope.matchMedia = mockMatchMedia as unknown as typeof globalScope.matchMedia;
96
+ const config = {
97
+ display: {
98
+ colorSpace: "p5",
99
+ },
100
+ };
101
+
102
+ const res = probeMediaDisplayInfos(config);
103
+ expect(res).toEqual("NotSupported");
104
+ expect(mockMatchMedia).toHaveBeenCalledTimes(1);
105
+ });
106
+ });