rx-player 3.26.3-dev.2022021400 → 3.27.0-dev.2022032100

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 (400) hide show
  1. package/.eslintrc.js +0 -4
  2. package/CHANGELOG.md +17 -2
  3. package/FILES.md +5 -4
  4. package/VERSION +1 -1
  5. package/dist/_esm5.processed/compat/browser_detection.d.ts +4 -2
  6. package/dist/_esm5.processed/compat/browser_detection.js +4 -2
  7. package/dist/_esm5.processed/compat/eme/close_session.d.ts +11 -5
  8. package/dist/_esm5.processed/compat/eme/close_session.js +143 -36
  9. package/dist/_esm5.processed/compat/eme/custom_key_system_access.d.ts +15 -0
  10. package/dist/_esm5.processed/compat/eme/custom_key_system_access.js +1 -17
  11. package/dist/_esm5.processed/compat/eme/custom_media_keys/ie11_media_keys.js +6 -7
  12. package/dist/_esm5.processed/compat/eme/custom_media_keys/index.d.ts +3 -5
  13. package/dist/_esm5.processed/compat/eme/custom_media_keys/index.js +20 -22
  14. package/dist/_esm5.processed/compat/eme/custom_media_keys/old_webkit_media_keys.js +58 -40
  15. package/dist/_esm5.processed/compat/eme/custom_media_keys/webkit_media_keys.js +49 -48
  16. package/dist/_esm5.processed/compat/eme/generate_key_request.d.ts +2 -3
  17. package/dist/_esm5.processed/compat/eme/generate_key_request.js +22 -26
  18. package/dist/_esm5.processed/compat/eme/load_session.d.ts +1 -2
  19. package/dist/_esm5.processed/compat/eme/load_session.js +67 -17
  20. package/dist/_esm5.processed/compat/event_listeners.js +2 -1
  21. package/dist/_esm5.processed/compat/should_favour_custom_safari_EME.js +2 -2
  22. package/dist/_esm5.processed/config.d.ts +166 -1080
  23. package/dist/_esm5.processed/config.js +17 -1119
  24. package/dist/_esm5.processed/core/abr/bandwidth_estimator.js +4 -1
  25. package/dist/_esm5.processed/core/abr/network_analyzer.js +2 -1
  26. package/dist/_esm5.processed/core/api/get_player_state.js +1 -1
  27. package/dist/_esm5.processed/core/api/index.d.ts +2 -1
  28. package/dist/_esm5.processed/core/api/media_element_track_choice_manager.js +2 -1
  29. package/dist/_esm5.processed/core/api/option_utils.d.ts +6 -3
  30. package/dist/_esm5.processed/core/api/option_utils.js +21 -7
  31. package/dist/_esm5.processed/core/api/playback_observer.js +5 -1
  32. package/dist/_esm5.processed/core/api/public_api.d.ts +82 -71
  33. package/dist/_esm5.processed/core/api/public_api.js +73 -35
  34. package/dist/_esm5.processed/core/{eme → decrypt}/__tests__/__global__/utils.d.ts +7 -49
  35. package/dist/_esm5.processed/core/{eme → decrypt}/__tests__/__global__/utils.js +25 -65
  36. package/dist/_esm5.processed/core/{eme → decrypt}/attach_media_keys.d.ts +12 -12
  37. package/dist/_esm5.processed/core/decrypt/attach_media_keys.js +103 -0
  38. package/dist/_esm5.processed/core/{eme/clear_eme_session.d.ts → decrypt/clear_on_stop.d.ts} +3 -4
  39. package/dist/_esm5.processed/core/decrypt/clear_on_stop.js +40 -0
  40. package/dist/_esm5.processed/core/decrypt/content_decryptor.d.ts +216 -0
  41. package/dist/_esm5.processed/core/decrypt/content_decryptor.js +865 -0
  42. package/dist/_esm5.processed/core/{eme/get_session.d.ts → decrypt/create_or_load_session.d.ts} +28 -26
  43. package/dist/_esm5.processed/core/decrypt/create_or_load_session.js +124 -0
  44. package/dist/_esm5.processed/core/{eme → decrypt}/create_session.d.ts +22 -19
  45. package/dist/_esm5.processed/core/decrypt/create_session.js +173 -0
  46. package/dist/_esm5.processed/core/{eme/dispose_media_keys.d.ts → decrypt/dispose_decryption_resources.d.ts} +4 -4
  47. package/dist/_esm5.processed/core/decrypt/dispose_decryption_resources.js +81 -0
  48. package/dist/_esm5.processed/core/{eme → decrypt}/find_key_system.d.ts +11 -14
  49. package/dist/_esm5.processed/core/decrypt/find_key_system.js +299 -0
  50. package/dist/_esm5.processed/core/{eme → decrypt}/get_current_key_system.d.ts +0 -0
  51. package/dist/_esm5.processed/core/{eme → decrypt}/get_current_key_system.js +1 -1
  52. package/dist/_esm5.processed/core/{eme → decrypt}/get_media_keys.d.ts +13 -5
  53. package/dist/_esm5.processed/core/decrypt/get_media_keys.js +153 -0
  54. package/dist/_esm5.processed/core/{eme → decrypt}/index.d.ts +5 -6
  55. package/dist/_esm5.processed/core/{eme → decrypt}/index.js +5 -5
  56. package/dist/_esm5.processed/core/{eme → decrypt}/init_media_keys.d.ts +6 -4
  57. package/dist/_esm5.processed/core/decrypt/init_media_keys.js +82 -0
  58. package/dist/_esm5.processed/core/decrypt/session_events_listener.d.ts +77 -0
  59. package/dist/_esm5.processed/core/{eme → decrypt}/session_events_listener.js +25 -24
  60. package/dist/_esm5.processed/core/{eme → decrypt}/set_server_certificate.d.ts +15 -6
  61. package/dist/_esm5.processed/core/decrypt/set_server_certificate.js +141 -0
  62. package/dist/_esm5.processed/core/{eme → decrypt}/types.d.ts +119 -241
  63. package/dist/_esm5.processed/core/{eme → decrypt}/types.js +0 -0
  64. package/dist/_esm5.processed/core/{eme → decrypt}/utils/are_init_values_compatible.d.ts +3 -3
  65. package/dist/_esm5.processed/core/{eme → decrypt}/utils/are_init_values_compatible.js +5 -5
  66. package/dist/_esm5.processed/core/{eme → decrypt/utils}/check_key_statuses.d.ts +2 -2
  67. package/dist/_esm5.processed/core/{eme → decrypt/utils}/check_key_statuses.js +4 -3
  68. package/dist/_esm5.processed/core/{eme/utils/close_session.d.ts → decrypt/utils/clean_old_loaded_sessions.d.ts} +8 -7
  69. package/dist/_esm5.processed/core/decrypt/utils/clean_old_loaded_sessions.js +84 -0
  70. package/dist/_esm5.processed/core/{eme → decrypt/utils}/clean_old_stored_persistent_info.d.ts +1 -1
  71. package/dist/_esm5.processed/core/{eme → decrypt/utils}/clean_old_stored_persistent_info.js +2 -2
  72. package/dist/_esm5.processed/core/{eme → decrypt/utils}/get_drm_system_id.d.ts +0 -0
  73. package/dist/_esm5.processed/core/{eme → decrypt/utils}/get_drm_system_id.js +1 -1
  74. package/dist/_esm5.processed/core/decrypt/utils/init_data_values_container.d.ts +69 -0
  75. package/dist/_esm5.processed/core/decrypt/utils/init_data_values_container.js +99 -0
  76. package/dist/_esm5.processed/core/{eme → decrypt}/utils/is_session_usable.d.ts +0 -1
  77. package/dist/_esm5.processed/core/{eme → decrypt}/utils/is_session_usable.js +4 -5
  78. package/dist/_esm5.processed/core/decrypt/utils/key_id_comparison.d.ts +44 -0
  79. package/dist/_esm5.processed/core/decrypt/utils/key_id_comparison.js +77 -0
  80. package/dist/_esm5.processed/core/decrypt/utils/key_session_record.d.ts +104 -0
  81. package/dist/_esm5.processed/core/decrypt/utils/key_session_record.js +155 -0
  82. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.d.ts +108 -0
  83. package/dist/_esm5.processed/core/decrypt/utils/loaded_sessions_store.js +302 -0
  84. package/dist/_esm5.processed/core/{eme → decrypt/utils}/media_keys_infos_store.d.ts +4 -4
  85. package/dist/_esm5.processed/core/{eme → decrypt/utils}/media_keys_infos_store.js +0 -0
  86. package/dist/_esm5.processed/core/{eme → decrypt}/utils/persistent_sessions_store.d.ts +8 -18
  87. package/dist/_esm5.processed/core/{eme → decrypt}/utils/persistent_sessions_store.js +119 -97
  88. package/dist/_esm5.processed/core/{eme/utils/init_data_container.d.ts → decrypt/utils/serializable_bytes.d.ts} +8 -5
  89. package/dist/_esm5.processed/core/{eme/utils/init_data_container.js → decrypt/utils/serializable_bytes.js} +9 -9
  90. package/dist/_esm5.processed/core/{eme → decrypt/utils}/server_certificate_store.d.ts +1 -1
  91. package/dist/_esm5.processed/core/{eme → decrypt/utils}/server_certificate_store.js +1 -1
  92. package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +3 -5
  93. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +1 -1
  94. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.js +1 -1
  95. package/dist/_esm5.processed/core/fetchers/utils/try_urls_with_backoff.js +2 -3
  96. package/dist/_esm5.processed/core/init/get_initial_time.js +1 -1
  97. package/dist/_esm5.processed/core/init/initialize_directfile.d.ts +1 -1
  98. package/dist/_esm5.processed/core/init/initialize_directfile.js +11 -17
  99. package/dist/_esm5.processed/core/init/initialize_media_source.d.ts +6 -3
  100. package/dist/_esm5.processed/core/init/initialize_media_source.js +18 -69
  101. package/dist/_esm5.processed/core/init/link_drm_and_content.d.ts +61 -0
  102. package/dist/_esm5.processed/core/init/link_drm_and_content.js +94 -0
  103. package/dist/_esm5.processed/core/init/manifest_update_scheduler.js +2 -1
  104. package/dist/_esm5.processed/core/init/stall_avoider.js +1 -1
  105. package/dist/_esm5.processed/core/init/stream_events_emitter/stream_events_emitter.js +1 -1
  106. package/dist/_esm5.processed/core/init/types.d.ts +2 -4
  107. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +1 -1
  108. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +3 -1
  109. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.d.ts +17 -1
  110. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.js +22 -5
  111. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.d.ts +2 -1
  112. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.js +6 -3
  113. package/dist/_esm5.processed/core/stream/events_generators.d.ts +8 -3
  114. package/dist/_esm5.processed/core/stream/events_generators.js +3 -2
  115. package/dist/_esm5.processed/core/stream/index.d.ts +1 -0
  116. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.d.ts +1 -0
  117. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +3 -3
  118. package/dist/_esm5.processed/core/stream/period/create_empty_adaptation_stream.js +2 -1
  119. package/dist/_esm5.processed/core/stream/period/get_adaptation_switch_strategy.d.ts +15 -11
  120. package/dist/_esm5.processed/core/stream/period/get_adaptation_switch_strategy.js +6 -3
  121. package/dist/_esm5.processed/core/stream/period/index.d.ts +1 -0
  122. package/dist/_esm5.processed/core/stream/period/period_stream.d.ts +5 -12
  123. package/dist/_esm5.processed/core/stream/period/period_stream.js +3 -3
  124. package/dist/_esm5.processed/core/stream/representation/force_garbage_collection.js +2 -2
  125. package/dist/_esm5.processed/core/stream/representation/get_buffer_status.d.ts +6 -1
  126. package/dist/_esm5.processed/core/stream/representation/get_buffer_status.js +12 -9
  127. package/dist/_esm5.processed/core/stream/representation/get_needed_segments.d.ts +19 -14
  128. package/dist/_esm5.processed/core/stream/representation/get_needed_segments.js +86 -10
  129. package/dist/_esm5.processed/core/stream/representation/get_segment_priority.js +1 -1
  130. package/dist/_esm5.processed/core/stream/representation/push_media_segment.js +3 -3
  131. package/dist/_esm5.processed/core/stream/representation/representation_stream.d.ts +6 -0
  132. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +19 -8
  133. package/dist/_esm5.processed/core/stream/types.d.ts +1 -1
  134. package/dist/_esm5.processed/default_config.d.ts +1114 -0
  135. package/dist/_esm5.processed/default_config.js +1145 -0
  136. package/dist/_esm5.processed/experimental/index.d.ts +2 -0
  137. package/dist/_esm5.processed/experimental/index.js +2 -0
  138. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/push_data.d.ts +1 -0
  139. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/thumbnail_loader.js +6 -7
  140. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/api/index.js +2 -3
  141. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.d.ts +15 -0
  142. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.js +1 -2
  143. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/DRMInfos.js +3 -5
  144. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/HDCPPolicy.js +3 -5
  145. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/decodingInfo.js +1 -2
  146. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.js +1 -2
  147. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/mediaContentTypeWithFeatures/index.js +1 -2
  148. package/dist/_esm5.processed/experimental/tools/mediaCapabilitiesProber/probers/mediaDisplayInfos.js +1 -2
  149. package/dist/_esm5.processed/features/features_object.js +1 -1
  150. package/dist/_esm5.processed/features/initialize_features.js +1 -1
  151. package/dist/_esm5.processed/features/list/eme.d.ts +3 -3
  152. package/dist/_esm5.processed/features/list/eme.js +5 -5
  153. package/dist/_esm5.processed/features/types.d.ts +3 -3
  154. package/dist/_esm5.processed/manifest/manifest.d.ts +1 -14
  155. package/dist/_esm5.processed/manifest/manifest.js +10 -74
  156. package/dist/_esm5.processed/manifest/representation.d.ts +35 -3
  157. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/is_period_fulfilled.js +1 -2
  158. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.js +1 -2
  159. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +1 -1
  160. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_adaptation_sets.js +87 -75
  161. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.js +1 -2
  162. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.js +4 -5
  163. package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.js +1 -0
  164. package/dist/_esm5.processed/public_types.d.ts +3 -2
  165. package/dist/_esm5.processed/transports/dash/add_segment_integrity_checks_to_loader.js +1 -2
  166. package/dist/_esm5.processed/transports/dash/image_pipelines.d.ts +4 -3
  167. package/dist/_esm5.processed/transports/dash/image_pipelines.js +60 -11
  168. package/dist/_esm5.processed/transports/dash/init_segment_loader.js +1 -2
  169. package/dist/_esm5.processed/transports/dash/manifest_parser.js +2 -3
  170. package/dist/_esm5.processed/transports/dash/segment_loader.d.ts +1 -1
  171. package/dist/_esm5.processed/transports/dash/segment_loader.js +3 -4
  172. package/dist/_esm5.processed/transports/dash/segment_parser.js +6 -3
  173. package/dist/_esm5.processed/transports/dash/text_loader.js +1 -2
  174. package/dist/_esm5.processed/transports/dash/text_parser.js +8 -2
  175. package/dist/_esm5.processed/transports/local/segment_loader.js +2 -3
  176. package/dist/_esm5.processed/transports/local/segment_parser.js +4 -1
  177. package/dist/_esm5.processed/transports/local/text_parser.js +8 -2
  178. package/dist/_esm5.processed/transports/metaplaylist/pipelines.js +2 -3
  179. package/dist/_esm5.processed/transports/smooth/pipelines.js +71 -14
  180. package/dist/_esm5.processed/transports/smooth/segment_loader.js +3 -4
  181. package/dist/_esm5.processed/transports/types.d.ts +22 -0
  182. package/dist/_esm5.processed/transports/utils/call_custom_manifest_loader.js +1 -2
  183. package/dist/_esm5.processed/utils/cancellable_sleep.js +1 -2
  184. package/dist/_esm5.processed/utils/cast_to_observable.js +1 -3
  185. package/dist/_esm5.processed/utils/deep_merge.d.ts +12 -0
  186. package/dist/_esm5.processed/utils/deep_merge.js +53 -0
  187. package/dist/_esm5.processed/utils/reference.d.ts +29 -0
  188. package/dist/_esm5.processed/utils/reference.js +72 -24
  189. package/dist/_esm5.processed/utils/request/fetch.js +1 -2
  190. package/dist/_esm5.processed/utils/request/xhr.js +2 -3
  191. package/dist/_esm5.processed/utils/rx-from_cancellable_promise.js +7 -2
  192. package/dist/_esm5.processed/utils/task_canceller.d.ts +5 -3
  193. package/dist/_esm5.processed/utils/task_canceller.js +3 -3
  194. package/dist/rx-player.js +4936 -3340
  195. package/dist/rx-player.min.js +1 -1
  196. package/dummy +1 -0
  197. package/{dist/_esm5.processed/utils/promise.d.ts → experimental/index.d.ts} +1 -2
  198. package/{dist/_esm5.processed/utils/promise.js → experimental/index.js} +1 -3
  199. package/package.json +32 -35
  200. package/{src/typings/pinkie.d.ts → scripts/build/templates/experimental/index.d.ts} +1 -4
  201. package/scripts/build/templates/experimental/index.js +16 -0
  202. package/scripts/update-version +2 -2
  203. package/sonar-project.properties +1 -1
  204. package/src/README.md +6 -6
  205. package/src/compat/__tests__/play.test.ts +2 -4
  206. package/src/compat/__tests__/should_favour_custom_safari_EME.test.ts +45 -5
  207. package/src/compat/browser_detection.ts +4 -2
  208. package/src/compat/eme/close_session.ts +89 -56
  209. package/src/compat/eme/custom_key_system_access.ts +1 -2
  210. package/src/compat/eme/custom_media_keys/ie11_media_keys.ts +6 -7
  211. package/src/compat/eme/custom_media_keys/index.ts +20 -38
  212. package/src/compat/eme/custom_media_keys/old_webkit_media_keys.ts +68 -52
  213. package/src/compat/eme/custom_media_keys/webkit_media_keys.ts +57 -56
  214. package/src/compat/eme/generate_key_request.ts +25 -33
  215. package/src/compat/eme/load_session.ts +28 -31
  216. package/src/compat/event_listeners.ts +2 -1
  217. package/src/compat/should_favour_custom_safari_EME.ts +5 -2
  218. package/src/config.ts +17 -1210
  219. package/src/core/README.md +1 -1
  220. package/src/core/abr/bandwidth_estimator.ts +4 -4
  221. package/src/core/abr/network_analyzer.ts +5 -6
  222. package/src/core/api/__tests__/get_player_state.test.ts +3 -3
  223. package/src/core/api/__tests__/option_utils.test.ts +29 -17
  224. package/src/core/api/get_player_state.ts +1 -1
  225. package/src/core/api/index.ts +3 -0
  226. package/src/core/api/option_utils.ts +42 -23
  227. package/src/core/api/playback_observer.ts +12 -8
  228. package/src/core/api/public_api.ts +152 -113
  229. package/src/core/decrypt/README.md +22 -0
  230. package/src/core/decrypt/__tests__/__global__/get_license.test.ts +418 -0
  231. package/src/core/decrypt/__tests__/__global__/init_data.test.ts +675 -0
  232. package/src/core/{eme → decrypt}/__tests__/__global__/media_key_system_access.test.ts +99 -92
  233. package/src/core/decrypt/__tests__/__global__/media_keys.test.ts +156 -0
  234. package/src/core/decrypt/__tests__/__global__/server_certificate.test.ts +262 -0
  235. package/src/core/{eme → decrypt}/__tests__/__global__/utils.ts +31 -93
  236. package/src/core/{eme → decrypt}/attach_media_keys.ts +48 -56
  237. package/src/core/decrypt/clear_on_stop.ts +47 -0
  238. package/src/core/decrypt/content_decryptor.ts +1157 -0
  239. package/src/core/decrypt/create_or_load_session.ts +130 -0
  240. package/src/core/decrypt/create_session.ts +174 -0
  241. package/src/core/decrypt/dispose_decryption_resources.ts +39 -0
  242. package/src/core/{eme → decrypt}/find_key_system.ts +111 -122
  243. package/src/core/{eme → decrypt}/get_current_key_system.ts +1 -1
  244. package/src/core/decrypt/get_media_keys.ts +145 -0
  245. package/src/core/{eme → decrypt}/index.ts +11 -8
  246. package/src/core/decrypt/init_media_keys.ts +51 -0
  247. package/src/core/{eme → decrypt}/session_events_listener.ts +93 -55
  248. package/src/core/decrypt/set_server_certificate.ts +104 -0
  249. package/src/core/{eme → decrypt}/types.ts +128 -258
  250. package/src/core/{eme → decrypt}/utils/__tests__/are_init_values_compatible.test.ts +1 -1
  251. package/src/core/{eme → decrypt/utils}/__tests__/clean_old_loaded_sessions.test.ts +29 -71
  252. package/src/core/{eme → decrypt/utils}/__tests__/clean_old_stored_persistent_info.test.ts +6 -6
  253. package/src/core/{eme → decrypt}/utils/are_init_values_compatible.ts +9 -9
  254. package/src/core/{eme → decrypt/utils}/check_key_statuses.ts +6 -5
  255. package/{dist/_esm5.processed/core/eme/clean_old_loaded_sessions.js → src/core/decrypt/utils/clean_old_loaded_sessions.ts} +19 -20
  256. package/src/core/{eme → decrypt/utils}/clean_old_stored_persistent_info.ts +3 -3
  257. package/src/core/{eme → decrypt/utils}/get_drm_system_id.ts +1 -1
  258. package/src/core/decrypt/utils/init_data_values_container.ts +119 -0
  259. package/src/core/{eme → decrypt}/utils/is_session_usable.ts +4 -5
  260. package/src/core/decrypt/utils/key_id_comparison.ts +82 -0
  261. package/src/core/decrypt/utils/key_session_record.ts +175 -0
  262. package/src/core/decrypt/utils/loaded_sessions_store.ts +317 -0
  263. package/src/core/{eme → decrypt/utils}/media_keys_infos_store.ts +4 -4
  264. package/src/core/{eme → decrypt}/utils/persistent_sessions_store.ts +122 -104
  265. package/src/core/{eme/utils/init_data_container.ts → decrypt/utils/serializable_bytes.ts} +8 -5
  266. package/src/core/{eme → decrypt/utils}/server_certificate_store.ts +2 -2
  267. package/src/core/fetchers/manifest/manifest_fetcher.ts +5 -7
  268. package/src/core/fetchers/segment/segment_fetcher.ts +4 -4
  269. package/src/core/fetchers/segment/segment_fetcher_creator.ts +2 -2
  270. package/src/core/fetchers/utils/try_urls_with_backoff.ts +2 -3
  271. package/src/core/init/.initialize_media_source.ts.un~ +0 -0
  272. package/src/core/init/get_initial_time.ts +2 -1
  273. package/src/core/init/initialize_directfile.ts +17 -20
  274. package/src/core/init/initialize_media_source.ts +44 -106
  275. package/src/core/init/link_drm_and_content.ts +176 -0
  276. package/src/core/init/manifest_update_scheduler.ts +5 -3
  277. package/src/core/init/stall_avoider.ts +6 -5
  278. package/src/core/init/stream_events_emitter/stream_events_emitter.ts +2 -1
  279. package/src/core/init/types.ts +1 -39
  280. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +2 -1
  281. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +3 -4
  282. package/src/core/segment_buffers/inventory/segment_inventory.ts +42 -8
  283. package/src/core/stream/adaptation/adaptation_stream.ts +7 -1
  284. package/src/core/stream/events_generators.ts +9 -4
  285. package/src/core/stream/index.ts +1 -0
  286. package/src/core/stream/orchestrator/stream_orchestrator.ts +9 -4
  287. package/src/core/stream/period/create_empty_adaptation_stream.ts +2 -1
  288. package/src/core/stream/period/get_adaptation_switch_strategy.ts +25 -15
  289. package/src/core/stream/period/index.ts +1 -0
  290. package/src/core/stream/period/period_stream.ts +10 -16
  291. package/src/core/stream/representation/force_garbage_collection.ts +2 -2
  292. package/src/core/stream/representation/get_buffer_status.ts +28 -16
  293. package/src/core/stream/representation/get_needed_segments.ts +124 -28
  294. package/src/core/stream/representation/get_segment_priority.ts +1 -2
  295. package/src/core/stream/representation/push_media_segment.ts +3 -2
  296. package/src/core/stream/representation/representation_stream.ts +30 -7
  297. package/src/core/stream/types.ts +1 -1
  298. package/src/default_config.ts +1241 -0
  299. package/src/experimental/index.ts +5 -0
  300. package/src/experimental/tools/VideoThumbnailLoader/push_data.ts +1 -0
  301. package/src/experimental/tools/VideoThumbnailLoader/thumbnail_loader.ts +7 -7
  302. package/src/experimental/tools/mediaCapabilitiesProber/__tests__/probers/DRMInfos.test.ts +3 -10
  303. package/src/experimental/tools/mediaCapabilitiesProber/__tests__/probers/HDCPPolicy.test.ts +9 -10
  304. package/src/experimental/tools/mediaCapabilitiesProber/__tests__/probers/decodingInfos.test.ts +2 -4
  305. package/src/experimental/tools/mediaCapabilitiesProber/api/index.ts +2 -3
  306. package/src/experimental/tools/mediaCapabilitiesProber/api/probeMediaConfiguration.ts +1 -2
  307. package/src/experimental/tools/mediaCapabilitiesProber/probers/DRMInfos.ts +3 -5
  308. package/src/experimental/tools/mediaCapabilitiesProber/probers/HDCPPolicy.ts +3 -5
  309. package/src/experimental/tools/mediaCapabilitiesProber/probers/decodingInfo.ts +1 -2
  310. package/src/experimental/tools/mediaCapabilitiesProber/probers/mediaContentType.ts +1 -2
  311. package/src/experimental/tools/mediaCapabilitiesProber/probers/mediaContentTypeWithFeatures/index.ts +1 -2
  312. package/src/experimental/tools/mediaCapabilitiesProber/probers/mediaDisplayInfos.ts +1 -2
  313. package/src/features/__tests__/initialize_features.test.ts +2 -2
  314. package/src/features/features_object.ts +1 -1
  315. package/src/features/initialize_features.ts +1 -1
  316. package/src/features/list/__tests__/eme.test.ts +5 -5
  317. package/src/features/list/eme.ts +5 -5
  318. package/src/features/types.ts +3 -10
  319. package/src/manifest/manifest.ts +6 -76
  320. package/src/manifest/representation.ts +36 -3
  321. package/src/parsers/manifest/dash/common/indexes/is_period_fulfilled.ts +1 -2
  322. package/src/parsers/manifest/dash/common/indexes/template.ts +1 -2
  323. package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +1 -1
  324. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +109 -64
  325. package/src/parsers/manifest/dash/common/parse_mpd.ts +1 -2
  326. package/src/parsers/manifest/dash/wasm-parser/ts/dash-wasm-parser.ts +4 -5
  327. package/src/parsers/manifest/smooth/create_parser.ts +1 -0
  328. package/src/parsers/texttracks/webvtt/html/__tests__/create_styled_element.test.ts +1 -0
  329. package/src/public_types.ts +6 -1
  330. package/src/transports/dash/add_segment_integrity_checks_to_loader.ts +1 -2
  331. package/src/transports/dash/image_pipelines.ts +15 -14
  332. package/src/transports/dash/init_segment_loader.ts +1 -2
  333. package/src/transports/dash/manifest_parser.ts +2 -3
  334. package/src/transports/dash/segment_loader.ts +4 -5
  335. package/src/transports/dash/segment_parser.ts +5 -0
  336. package/src/transports/dash/text_loader.ts +2 -3
  337. package/src/transports/dash/text_parser.ts +8 -0
  338. package/src/transports/local/segment_loader.ts +2 -3
  339. package/src/transports/local/segment_parser.ts +4 -0
  340. package/src/transports/local/text_parser.ts +8 -0
  341. package/src/transports/metaplaylist/pipelines.ts +2 -3
  342. package/src/transports/smooth/pipelines.ts +26 -14
  343. package/src/transports/smooth/segment_loader.ts +5 -6
  344. package/src/transports/types.ts +22 -0
  345. package/src/transports/utils/call_custom_manifest_loader.ts +1 -2
  346. package/src/utils/__tests__/deep_merge.test.ts +48 -0
  347. package/src/utils/cancellable_sleep.ts +1 -2
  348. package/src/utils/cast_to_observable.ts +0 -2
  349. package/src/utils/deep_merge.ts +46 -0
  350. package/src/utils/reference.ts +116 -23
  351. package/src/utils/request/fetch.ts +1 -2
  352. package/src/utils/request/xhr.ts +3 -3
  353. package/src/utils/rx-from_cancellable_promise.ts +7 -2
  354. package/src/utils/task_canceller.ts +6 -4
  355. package/tsconfig.json +0 -1
  356. package/tsconfig.modules.json +0 -1
  357. package/dist/_esm5.processed/core/eme/attach_media_keys.js +0 -57
  358. package/dist/_esm5.processed/core/eme/clean_old_loaded_sessions.d.ts +0 -59
  359. package/dist/_esm5.processed/core/eme/clear_eme_session.js +0 -50
  360. package/dist/_esm5.processed/core/eme/create_session.js +0 -126
  361. package/dist/_esm5.processed/core/eme/dispose_eme.d.ts +0 -19
  362. package/dist/_esm5.processed/core/eme/dispose_eme.js +0 -23
  363. package/dist/_esm5.processed/core/eme/dispose_media_keys.js +0 -36
  364. package/dist/_esm5.processed/core/eme/eme_manager.d.ts +0 -31
  365. package/dist/_esm5.processed/core/eme/eme_manager.js +0 -278
  366. package/dist/_esm5.processed/core/eme/find_key_system.js +0 -253
  367. package/dist/_esm5.processed/core/eme/get_media_keys.js +0 -85
  368. package/dist/_esm5.processed/core/eme/get_session.js +0 -68
  369. package/dist/_esm5.processed/core/eme/init_media_keys.js +0 -66
  370. package/dist/_esm5.processed/core/eme/session_events_listener.d.ts +0 -41
  371. package/dist/_esm5.processed/core/eme/set_server_certificate.js +0 -85
  372. package/dist/_esm5.processed/core/eme/utils/close_session.js +0 -81
  373. package/dist/_esm5.processed/core/eme/utils/init_data_store.d.ts +0 -115
  374. package/dist/_esm5.processed/core/eme/utils/init_data_store.js +0 -181
  375. package/dist/_esm5.processed/core/eme/utils/loaded_sessions_store.d.ts +0 -123
  376. package/dist/_esm5.processed/core/eme/utils/loaded_sessions_store.js +0 -173
  377. package/dist/_esm5.processed/core/init/create_eme_manager.d.ts +0 -34
  378. package/dist/_esm5.processed/core/init/create_eme_manager.js +0 -52
  379. package/src/core/eme/README.md +0 -26
  380. package/src/core/eme/__tests__/__global__/get_license.test.ts +0 -414
  381. package/src/core/eme/__tests__/__global__/init_data.test.ts +0 -908
  382. package/src/core/eme/__tests__/__global__/media_keys.test.ts +0 -266
  383. package/src/core/eme/__tests__/__global__/server_certificate.test.ts +0 -364
  384. package/src/core/eme/__tests__/init_media_keys.test.ts +0 -182
  385. package/src/core/eme/clean_old_loaded_sessions.ts +0 -96
  386. package/src/core/eme/clear_eme_session.ts +0 -62
  387. package/src/core/eme/create_session.ts +0 -187
  388. package/src/core/eme/dispose_eme.ts +0 -25
  389. package/src/core/eme/dispose_media_keys.ts +0 -46
  390. package/src/core/eme/eme_manager.ts +0 -387
  391. package/src/core/eme/get_media_keys.ts +0 -141
  392. package/src/core/eme/get_session.ts +0 -135
  393. package/src/core/eme/init_media_keys.ts +0 -106
  394. package/src/core/eme/set_server_certificate.ts +0 -115
  395. package/src/core/eme/utils/close_session.ts +0 -113
  396. package/src/core/eme/utils/init_data_store.ts +0 -234
  397. package/src/core/eme/utils/loaded_sessions_store.ts +0 -235
  398. package/src/core/init/create_eme_manager.ts +0 -95
  399. package/src/utils/__tests__/promise.test.ts +0 -23
  400. package/src/utils/promise.ts +0 -20
@@ -0,0 +1,865 @@
1
+ /**
2
+ * Copyright 2015 CANAL+ Group
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ var __extends = (this && this.__extends) || (function () {
17
+ var extendStatics = function (d, b) {
18
+ extendStatics = Object.setPrototypeOf ||
19
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
20
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
21
+ return extendStatics(d, b);
22
+ };
23
+ return function (d, b) {
24
+ if (typeof b !== "function" && b !== null)
25
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26
+ extendStatics(d, b);
27
+ function __() { this.constructor = d; }
28
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
29
+ };
30
+ })();
31
+ var __assign = (this && this.__assign) || function () {
32
+ __assign = Object.assign || function(t) {
33
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
34
+ s = arguments[i];
35
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
36
+ t[p] = s[p];
37
+ }
38
+ return t;
39
+ };
40
+ return __assign.apply(this, arguments);
41
+ };
42
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
43
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
44
+ return new (P || (P = Promise))(function (resolve, reject) {
45
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
46
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
47
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
48
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
49
+ });
50
+ };
51
+ var __generator = (this && this.__generator) || function (thisArg, body) {
52
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
53
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
54
+ function verb(n) { return function (v) { return step([n, v]); }; }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while (_) try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [op[0] & 2, t.value];
60
+ switch (op[0]) {
61
+ case 0: case 1: t = op; break;
62
+ case 4: _.label++; return { value: op[1], done: false };
63
+ case 5: _.label++; y = op[1]; op = [0]; continue;
64
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
65
+ default:
66
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
67
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
68
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
69
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
70
+ if (t[2]) _.ops.pop();
71
+ _.trys.pop(); continue;
72
+ }
73
+ op = body.call(thisArg, _);
74
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
75
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
76
+ }
77
+ };
78
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
79
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
80
+ if (ar || !(i in from)) {
81
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
82
+ ar[i] = from[i];
83
+ }
84
+ }
85
+ return to.concat(ar || Array.prototype.slice.call(from));
86
+ };
87
+ import { events, generateKeyRequest, getInitData, } from "../../compat/";
88
+ import config from "../../config";
89
+ import { EncryptedMediaError, OtherError, } from "../../errors";
90
+ import log from "../../log";
91
+ import areArraysOfNumbersEqual from "../../utils/are_arrays_of_numbers_equal";
92
+ import arrayFind from "../../utils/array_find";
93
+ import arrayIncludes from "../../utils/array_includes";
94
+ import EventEmitter from "../../utils/event_emitter";
95
+ import isNullOrUndefined from "../../utils/is_null_or_undefined";
96
+ import { bytesToHex } from "../../utils/string_parsing";
97
+ import TaskCanceller from "../../utils/task_canceller";
98
+ import attachMediaKeys from "./attach_media_keys";
99
+ import createOrLoadSession from "./create_or_load_session";
100
+ import initMediaKeys from "./init_media_keys";
101
+ import SessionEventsListener, { BlacklistedSessionError, } from "./session_events_listener";
102
+ import setServerCertificate from "./set_server_certificate";
103
+ import cleanOldStoredPersistentInfo from "./utils/clean_old_stored_persistent_info";
104
+ import getDrmSystemId from "./utils/get_drm_system_id";
105
+ import InitDataValuesContainer from "./utils/init_data_values_container";
106
+ import { areAllKeyIdsContainedIn, areKeyIdsEqual, areSomeKeyIdsContainedIn, isKeyIdContainedIn, } from "./utils/key_id_comparison";
107
+ var onEncrypted$ = events.onEncrypted$;
108
+ /**
109
+ * Module communicating with the Content Decryption Module (or CDM) to be able
110
+ * to decrypt contents.
111
+ *
112
+ * The `ContentDecryptor` starts communicating with the CDM, to initialize the
113
+ * key system, as soon as it is created.
114
+ *
115
+ * You can be notified of various events, such as fatal errors, by registering
116
+ * to one of its multiple events (@see IContentDecryptorEvent).
117
+ *
118
+ * @class ContentDecryptor
119
+ */
120
+ var ContentDecryptor = /** @class */ (function (_super) {
121
+ __extends(ContentDecryptor, _super);
122
+ /**
123
+ * Create a new `ContentDecryptor`, and initialize its decryption capabilities
124
+ * right away.
125
+ * Goes into the `WaitingForAttachment` state once that initialization is
126
+ * done, after which you should call the `attach` method when you're ready for
127
+ * those decryption capabilities to be attached to the HTMLMediaElement.
128
+ *
129
+ * @param {HTMLMediaElement} mediaElement - The MediaElement which will be
130
+ * associated to a MediaKeys object
131
+ * @param {Array.<Object>} ksOptions - key system configuration.
132
+ * The `ContentDecryptor` can be given one or multiple key system
133
+ * configurations. It will choose the appropriate one depending on user
134
+ * settings and browser support.
135
+ */
136
+ function ContentDecryptor(mediaElement, ksOptions) {
137
+ var _this = _super.call(this) || this;
138
+ log.debug("DRM: Starting ContentDecryptor logic.");
139
+ var canceller = new TaskCanceller();
140
+ _this._currentSessions = [];
141
+ _this._canceller = canceller;
142
+ _this._wasAttachCalled = false;
143
+ _this._initDataQueue = [];
144
+ _this._stateData = { state: ContentDecryptorState.Initializing,
145
+ isMediaKeysAttached: false,
146
+ isInitDataQueueLocked: true,
147
+ data: null };
148
+ _this.error = null;
149
+ var listenerSub = onEncrypted$(mediaElement).subscribe(function (evt) {
150
+ log.debug("DRM: Encrypted event received from media element.");
151
+ var initData = getInitData(evt);
152
+ if (initData !== null) {
153
+ _this.onInitializationData(initData);
154
+ }
155
+ });
156
+ canceller.signal.register(function () {
157
+ listenerSub.unsubscribe();
158
+ });
159
+ initMediaKeys(mediaElement, ksOptions, canceller.signal)
160
+ .then(function (mediaKeysInfo) {
161
+ var options = mediaKeysInfo.options, mediaKeySystemAccess = mediaKeysInfo.mediaKeySystemAccess;
162
+ /**
163
+ * String identifying the key system, allowing the rest of the code to
164
+ * only advertise the required initialization data for license requests.
165
+ *
166
+ * Note that we only set this value if retro-compatibility to older
167
+ * persistent logic in the RxPlayer is not important, as the
168
+ * optimizations this property unlocks can break the loading of
169
+ * MediaKeySessions persisted in older RxPlayer's versions.
170
+ */
171
+ var systemId;
172
+ if (isNullOrUndefined(options.licenseStorage) ||
173
+ options.licenseStorage.disableRetroCompatibility === true) {
174
+ systemId = getDrmSystemId(mediaKeySystemAccess.keySystem);
175
+ }
176
+ _this.systemId = systemId;
177
+ if (_this._stateData.state === ContentDecryptorState.Initializing) {
178
+ _this._stateData = { state: ContentDecryptorState.WaitingForAttachment,
179
+ isInitDataQueueLocked: true,
180
+ isMediaKeysAttached: false,
181
+ data: { mediaKeysInfo: mediaKeysInfo, mediaElement: mediaElement } };
182
+ _this.trigger("stateChange", _this._stateData.state);
183
+ }
184
+ })
185
+ .catch(function (err) {
186
+ _this._onFatalError(err);
187
+ });
188
+ return _this;
189
+ }
190
+ /**
191
+ * Returns the current state of the ContentDecryptor.
192
+ * @see ContentDecryptorState
193
+ * @returns {Object}
194
+ */
195
+ ContentDecryptor.prototype.getState = function () {
196
+ return this._stateData.state;
197
+ };
198
+ /**
199
+ * Attach the current decryption capabilities to the HTMLMediaElement.
200
+ * This method should only be called once the `ContentDecryptor` is in the
201
+ * `WaitingForAttachment` state.
202
+ *
203
+ * You might want to first set the HTMLMediaElement's `src` attribute before
204
+ * calling this method, and only push data to it once the `ReadyForContent`
205
+ * state is reached, for compatibility reasons.
206
+ */
207
+ ContentDecryptor.prototype.attach = function () {
208
+ var _this = this;
209
+ if (this._stateData.state !== ContentDecryptorState.WaitingForAttachment) {
210
+ throw new Error("`attach` should only be called when " +
211
+ "in the WaitingForAttachment state");
212
+ }
213
+ else if (this._wasAttachCalled) {
214
+ log.warn("DRM: ContentDecryptor's `attach` method called more than once.");
215
+ return;
216
+ }
217
+ this._wasAttachCalled = true;
218
+ var _a = this._stateData.data, mediaElement = _a.mediaElement, mediaKeysInfo = _a.mediaKeysInfo;
219
+ var options = mediaKeysInfo.options, mediaKeys = mediaKeysInfo.mediaKeys, mediaKeySystemAccess = mediaKeysInfo.mediaKeySystemAccess, stores = mediaKeysInfo.stores;
220
+ var stateToAttatch = { loadedSessionsStore: stores.loadedSessionsStore, mediaKeySystemAccess: mediaKeySystemAccess, mediaKeys: mediaKeys, keySystemOptions: options };
221
+ var shouldDisableLock = options.disableMediaKeysAttachmentLock === true;
222
+ if (shouldDisableLock) {
223
+ this._stateData = { state: ContentDecryptorState.ReadyForContent,
224
+ isInitDataQueueLocked: true,
225
+ isMediaKeysAttached: false,
226
+ data: null };
227
+ this.trigger("stateChange", this._stateData.state);
228
+ if (this._isStopped()) { // previous trigger might have lead to disposal
229
+ return;
230
+ }
231
+ }
232
+ log.debug("DRM: Attaching current MediaKeys");
233
+ attachMediaKeys(mediaElement, stateToAttatch, this._canceller.signal)
234
+ .then(function () { return __awaiter(_this, void 0, void 0, function () {
235
+ var serverCertificate, resSsc, prevState;
236
+ return __generator(this, function (_a) {
237
+ switch (_a.label) {
238
+ case 0:
239
+ serverCertificate = options.serverCertificate;
240
+ if (!!isNullOrUndefined(serverCertificate)) return [3 /*break*/, 2];
241
+ return [4 /*yield*/, setServerCertificate(mediaKeys, serverCertificate)];
242
+ case 1:
243
+ resSsc = _a.sent();
244
+ if (resSsc.type === "error") {
245
+ this.trigger("warning", resSsc.value);
246
+ }
247
+ _a.label = 2;
248
+ case 2:
249
+ if (this._isStopped()) { // We might be stopped since then
250
+ return [2 /*return*/];
251
+ }
252
+ prevState = this._stateData.state;
253
+ this._stateData = { state: ContentDecryptorState.ReadyForContent,
254
+ isMediaKeysAttached: true,
255
+ isInitDataQueueLocked: false,
256
+ data: { mediaKeysData: mediaKeysInfo } };
257
+ if (prevState !== ContentDecryptorState.ReadyForContent) {
258
+ this.trigger("stateChange", ContentDecryptorState.ReadyForContent);
259
+ }
260
+ if (!this._isStopped()) {
261
+ this._processCurrentInitDataQueue();
262
+ }
263
+ return [2 /*return*/];
264
+ }
265
+ });
266
+ }); })
267
+ .catch(function (err) {
268
+ _this._onFatalError(err);
269
+ });
270
+ };
271
+ /**
272
+ * Stop this `ContentDecryptor` instance:
273
+ * - stop listening and reacting to the various event listeners
274
+ * - abort all operations.
275
+ *
276
+ * Once disposed, a `ContentDecryptor` cannot be used anymore.
277
+ */
278
+ ContentDecryptor.prototype.dispose = function () {
279
+ this.removeEventListener();
280
+ this._stateData = { state: ContentDecryptorState.Disposed,
281
+ isMediaKeysAttached: undefined,
282
+ isInitDataQueueLocked: undefined,
283
+ data: null };
284
+ this._canceller.cancel();
285
+ this.trigger("stateChange", this._stateData.state);
286
+ };
287
+ /**
288
+ * Method to call when new protection initialization data is encounted on the
289
+ * content.
290
+ *
291
+ * When called, the `ContentDecryptor` will try to obtain the decryption key
292
+ * if not already obtained.
293
+ *
294
+ * @param {Object} initializationData
295
+ */
296
+ ContentDecryptor.prototype.onInitializationData = function (initializationData) {
297
+ var _this = this;
298
+ if (this._stateData.isInitDataQueueLocked !== false) {
299
+ if (this._isStopped()) {
300
+ throw new Error("ContentDecryptor either disposed or stopped.");
301
+ }
302
+ this._initDataQueue.push(initializationData);
303
+ return;
304
+ }
305
+ var mediaKeysData = this._stateData.data.mediaKeysData;
306
+ var processedInitializationData = __assign(__assign({}, initializationData), { values: new InitDataValuesContainer(initializationData.values) });
307
+ this._processInitializationData(processedInitializationData, mediaKeysData)
308
+ .catch(function (err) { _this._onFatalError(err); });
309
+ };
310
+ /**
311
+ * Async logic run each time new initialization data has to be processed.
312
+ * The promise return may reject, in which case a fatal error should be linked
313
+ * the current `ContentDecryptor`.
314
+ *
315
+ * The Promise's resolution however provides no semantic value.
316
+ * @param {Object} initializationData
317
+ * @returns {Promise.<void>}
318
+ */
319
+ ContentDecryptor.prototype._processInitializationData = function (initializationData, mediaKeysData) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ var mediaKeySystemAccess, stores, options, firstCreatedSession, keyIds, hexKids, period, createdSessions, periodKeys, _i, createdSessions_1, createdSess, periodKeysArr, _a, periodKeysArr_1, kid, _b, periodKeysArr_2, innerKid, wantedSessionType, _c, EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS, EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION, maxSessionCacheSize, sessionRes, sessionInfo, _d, mediaKeySession, sessionType, isSessionPersisted, sub, requestData, error_1;
322
+ var _this = this;
323
+ return __generator(this, function (_e) {
324
+ switch (_e.label) {
325
+ case 0:
326
+ mediaKeySystemAccess = mediaKeysData.mediaKeySystemAccess, stores = mediaKeysData.stores, options = mediaKeysData.options;
327
+ if (this._tryToUseAlreadyCreatedSession(initializationData, mediaKeysData) ||
328
+ this._isStopped()) // _isStopped is voluntarly checked after here
329
+ {
330
+ return [2 /*return*/];
331
+ }
332
+ if (options.singleLicensePer === "content") {
333
+ firstCreatedSession = arrayFind(this._currentSessions, function (x) {
334
+ return x.source === "created-session" /* Created */;
335
+ });
336
+ if (firstCreatedSession !== undefined) {
337
+ keyIds = initializationData.keyIds;
338
+ if (keyIds === undefined) {
339
+ if (initializationData.content === undefined) {
340
+ log.warn("DRM: Unable to fallback from a non-decipherable quality.");
341
+ }
342
+ else {
343
+ blackListProtectionData(initializationData.content.manifest, initializationData);
344
+ }
345
+ return [2 /*return*/];
346
+ }
347
+ firstCreatedSession.record.associateKeyIds(keyIds);
348
+ if (initializationData.content !== undefined) {
349
+ if (log.getLevel() === "DEBUG") {
350
+ hexKids = keyIds
351
+ .reduce(function (acc, kid) { return "".concat(acc, ", ").concat(bytesToHex(kid)); }, "");
352
+ log.debug("DRM: Blacklisting new key ids", hexKids);
353
+ }
354
+ updateDecipherability(initializationData.content.manifest, [], keyIds);
355
+ }
356
+ return [2 /*return*/];
357
+ }
358
+ }
359
+ else if (options.singleLicensePer === "periods" &&
360
+ initializationData.content !== undefined) {
361
+ period = initializationData.content.period;
362
+ createdSessions = this._currentSessions
363
+ .filter(function (x) { return x.source === "created-session" /* Created */; });
364
+ periodKeys = new Set();
365
+ addKeyIdsFromPeriod(periodKeys, period);
366
+ for (_i = 0, createdSessions_1 = createdSessions; _i < createdSessions_1.length; _i++) {
367
+ createdSess = createdSessions_1[_i];
368
+ periodKeysArr = Array.from(periodKeys);
369
+ for (_a = 0, periodKeysArr_1 = periodKeysArr; _a < periodKeysArr_1.length; _a++) {
370
+ kid = periodKeysArr_1[_a];
371
+ if (createdSess.record.isAssociatedWithKeyId(kid)) {
372
+ createdSess.record.associateKeyIds(periodKeys.values());
373
+ // Re-loop through the Period's key ids to blacklist ones that are missing
374
+ // from `createdSess`'s `keyStatuses` and to update the content's
375
+ // decipherability.
376
+ for (_b = 0, periodKeysArr_2 = periodKeysArr; _b < periodKeysArr_2.length; _b++) {
377
+ innerKid = periodKeysArr_2[_b];
378
+ if (!isKeyIdContainedIn(innerKid, createdSess.keyStatuses.whitelisted) &&
379
+ !isKeyIdContainedIn(innerKid, createdSess.keyStatuses.blacklisted)) {
380
+ createdSess.keyStatuses.blacklisted.push(innerKid);
381
+ }
382
+ }
383
+ updateDecipherability(initializationData.content.manifest, createdSess.keyStatuses.whitelisted, createdSess.keyStatuses.blacklisted);
384
+ return [2 /*return*/];
385
+ }
386
+ }
387
+ }
388
+ }
389
+ // /!\ Do not forget to unlock when done
390
+ // TODO this is error-prone and can lead to performance issue when loading
391
+ // persistent sessions.
392
+ // Can we find a better strategy?
393
+ this._lockInitDataQueue();
394
+ if (options.persistentLicense !== true) {
395
+ wantedSessionType = "temporary";
396
+ }
397
+ else if (!canCreatePersistentSession(mediaKeySystemAccess)) {
398
+ log.warn("DRM: Cannot create \"persistent-license\" session: not supported");
399
+ wantedSessionType = "temporary";
400
+ }
401
+ else {
402
+ wantedSessionType = "persistent-license";
403
+ }
404
+ _c = config.getCurrent(), EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS = _c.EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS, EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION = _c.EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION;
405
+ maxSessionCacheSize = typeof options.maxSessionCacheSize === "number" ?
406
+ options.maxSessionCacheSize :
407
+ EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS;
408
+ return [4 /*yield*/, createOrLoadSession(initializationData, stores, wantedSessionType, maxSessionCacheSize, this._canceller.signal)];
409
+ case 1:
410
+ sessionRes = _e.sent();
411
+ if (this._isStopped()) {
412
+ return [2 /*return*/];
413
+ }
414
+ sessionInfo = {
415
+ record: sessionRes.value.keySessionRecord,
416
+ source: sessionRes.type,
417
+ keyStatuses: { whitelisted: [], blacklisted: [] },
418
+ blacklistedSessionError: null,
419
+ };
420
+ this._currentSessions.push(sessionInfo);
421
+ _d = sessionRes.value, mediaKeySession = _d.mediaKeySession, sessionType = _d.sessionType;
422
+ isSessionPersisted = false;
423
+ sub = SessionEventsListener(mediaKeySession, options, mediaKeySystemAccess.keySystem)
424
+ .subscribe({
425
+ next: function (evt) {
426
+ switch (evt.type) {
427
+ case "warning":
428
+ _this.trigger("warning", evt.value);
429
+ return;
430
+ }
431
+ var linkedKeys;
432
+ if (sessionInfo.source === "created-session" /* Created */) {
433
+ // When the license has been fetched, there might be implicit key ids
434
+ // linked to the session depending on the `singleLicensePer` option.
435
+ linkedKeys = getFetchedLicenseKeysInfo(initializationData, options.singleLicensePer, evt.value.whitelistedKeyIds, evt.value.blacklistedKeyIDs);
436
+ }
437
+ else {
438
+ // When the MediaKeySession is just a cached/persisted one, we don't
439
+ // have any concept of "implicit key id".
440
+ linkedKeys = { whitelisted: evt.value.whitelistedKeyIds,
441
+ blacklisted: evt.value.blacklistedKeyIDs };
442
+ }
443
+ sessionInfo.record.associateKeyIds(linkedKeys.whitelisted);
444
+ sessionInfo.record.associateKeyIds(linkedKeys.blacklisted);
445
+ sessionInfo.keyStatuses = { whitelisted: linkedKeys.whitelisted,
446
+ blacklisted: linkedKeys.blacklisted };
447
+ if (sessionInfo.record.getAssociatedKeyIds().length !== 0 &&
448
+ sessionType === "persistent-license" &&
449
+ stores.persistentSessionsStore !== null &&
450
+ !isSessionPersisted) {
451
+ var persistentSessionsStore = stores.persistentSessionsStore;
452
+ cleanOldStoredPersistentInfo(persistentSessionsStore, EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION - 1);
453
+ persistentSessionsStore.add(initializationData, sessionInfo.record.getAssociatedKeyIds(), mediaKeySession);
454
+ isSessionPersisted = true;
455
+ }
456
+ if (initializationData.content !== undefined) {
457
+ updateDecipherability(initializationData.content.manifest, linkedKeys.whitelisted, linkedKeys.blacklisted);
458
+ }
459
+ _this._unlockInitDataQueue();
460
+ },
461
+ error: function (err) {
462
+ if (!(err instanceof BlacklistedSessionError)) {
463
+ _this._onFatalError(err);
464
+ return;
465
+ }
466
+ sessionInfo.blacklistedSessionError = err;
467
+ if (initializationData.content !== undefined) {
468
+ var manifest = initializationData.content.manifest;
469
+ log.info("DRM: blacklisting Representations based on " +
470
+ "protection data.");
471
+ blackListProtectionData(manifest, initializationData);
472
+ }
473
+ _this._unlockInitDataQueue();
474
+ // TODO warning for blacklisted session?
475
+ },
476
+ });
477
+ this._canceller.signal.register(function () {
478
+ sub.unsubscribe();
479
+ });
480
+ if (options.singleLicensePer === undefined ||
481
+ options.singleLicensePer === "init-data") {
482
+ this._unlockInitDataQueue();
483
+ }
484
+ if (!(sessionRes.type === "created-session" /* Created */)) return [3 /*break*/, 5];
485
+ requestData = initializationData.values.constructRequestData();
486
+ _e.label = 2;
487
+ case 2:
488
+ _e.trys.push([2, 4, , 5]);
489
+ return [4 /*yield*/, generateKeyRequest(mediaKeySession, initializationData.type, requestData)];
490
+ case 3:
491
+ _e.sent();
492
+ return [3 /*break*/, 5];
493
+ case 4:
494
+ error_1 = _e.sent();
495
+ throw new EncryptedMediaError("KEY_GENERATE_REQUEST_ERROR", error_1 instanceof Error ? error_1.toString() :
496
+ "Unknown error");
497
+ case 5: return [2 /*return*/, Promise.resolve()];
498
+ }
499
+ });
500
+ });
501
+ };
502
+ ContentDecryptor.prototype._tryToUseAlreadyCreatedSession = function (initializationData, mediaKeysData) {
503
+ var stores = mediaKeysData.stores, options = mediaKeysData.options;
504
+ /**
505
+ * If set, a currently-used key session is already compatible to this
506
+ * initialization data.
507
+ */
508
+ var compatibleSessionInfo = arrayFind(this._currentSessions, function (x) { return x.record.isCompatibleWith(initializationData); });
509
+ if (compatibleSessionInfo === undefined) {
510
+ return false;
511
+ }
512
+ // Check if the compatible session is blacklisted
513
+ var blacklistedSessionError = compatibleSessionInfo.blacklistedSessionError;
514
+ if (!isNullOrUndefined(blacklistedSessionError)) {
515
+ if (initializationData.type === undefined ||
516
+ initializationData.content === undefined) {
517
+ log.error("DRM: This initialization data has already been blacklisted " +
518
+ "but the current content is not known.");
519
+ return true;
520
+ }
521
+ else {
522
+ log.info("DRM: This initialization data has already been blacklisted. " +
523
+ "Blacklisting the related content.");
524
+ var manifest = initializationData.content.manifest;
525
+ blackListProtectionData(manifest, initializationData);
526
+ return true;
527
+ }
528
+ }
529
+ // Check if the current key id(s) has been blacklisted by this session
530
+ if (initializationData.keyIds !== undefined) {
531
+ /**
532
+ * If set to `true`, the Representation(s) linked to this
533
+ * initialization data's key id should be marked as "not decipherable".
534
+ */
535
+ var isUndecipherable = void 0;
536
+ if (options.singleLicensePer === undefined ||
537
+ options.singleLicensePer === "init-data") {
538
+ // Note: In the default "init-data" mode, we only avoid a
539
+ // Representation if the key id was originally explicitely
540
+ // blacklisted (and not e.g. if its key was just not present in
541
+ // the license).
542
+ //
543
+ // This is to enforce v3.x.x retro-compatibility: we cannot
544
+ // fallback from a Representation unless some RxPlayer option
545
+ // documentating this behavior has been set.
546
+ var blacklisted = compatibleSessionInfo.keyStatuses.blacklisted;
547
+ isUndecipherable = areSomeKeyIdsContainedIn(initializationData.keyIds, blacklisted);
548
+ }
549
+ else {
550
+ // In any other mode, as soon as not all of this initialization
551
+ // data's linked key ids are explicitely whitelisted, we can mark
552
+ // the corresponding Representation as "not decipherable".
553
+ // This is because we've no such retro-compatibility guarantee to
554
+ // make there.
555
+ var whitelisted = compatibleSessionInfo.keyStatuses.whitelisted;
556
+ isUndecipherable = !areAllKeyIdsContainedIn(initializationData.keyIds, whitelisted);
557
+ }
558
+ if (isUndecipherable) {
559
+ if (initializationData.content === undefined) {
560
+ log.error("DRM: Cannot forbid key id, the content is unknown.");
561
+ return true;
562
+ }
563
+ log.info("DRM: Current initialization data is linked to blacklisted keys. " +
564
+ "Marking Representations as not decipherable");
565
+ updateDecipherability(initializationData.content.manifest, [], initializationData.keyIds);
566
+ return true;
567
+ }
568
+ }
569
+ // If we reached here, it means that this initialization data is not
570
+ // blacklisted in any way.
571
+ // Search loaded session and put it on top of the cache if it exists.
572
+ var entry = stores.loadedSessionsStore.reuse(initializationData);
573
+ if (entry !== null) {
574
+ // TODO update decipherability to `true` if not?
575
+ log.debug("DRM: Init data already processed. Skipping it.");
576
+ return true;
577
+ }
578
+ // Session not found in `loadedSessionsStore`, it might have been closed
579
+ // since.
580
+ // Remove from `this._currentSessions` and start again.
581
+ var indexOf = this._currentSessions.indexOf(compatibleSessionInfo);
582
+ if (indexOf === -1) {
583
+ log.error("DRM: Unable to remove processed init data: not found.");
584
+ }
585
+ else {
586
+ log.debug("DRM: A session from a processed init data is not available " +
587
+ "anymore. Re-processing it.");
588
+ this._currentSessions.splice(indexOf, 1);
589
+ }
590
+ return false;
591
+ };
592
+ ContentDecryptor.prototype._onFatalError = function (err) {
593
+ if (this._canceller.isUsed) {
594
+ return;
595
+ }
596
+ var formattedErr = err instanceof Error ?
597
+ err :
598
+ new OtherError("NONE", "Unknown encryption error");
599
+ this.error = formattedErr;
600
+ this._initDataQueue.length = 0;
601
+ this._stateData = { state: ContentDecryptorState.Error,
602
+ isMediaKeysAttached: undefined,
603
+ isInitDataQueueLocked: undefined,
604
+ data: null };
605
+ this._canceller.cancel();
606
+ this.trigger("error", formattedErr);
607
+ // The previous trigger might have lead to a disposal of the `ContentDecryptor`.
608
+ if (this._stateData.state === ContentDecryptorState.Error) {
609
+ this.trigger("stateChange", this._stateData.state);
610
+ }
611
+ };
612
+ /**
613
+ * Return `true` if the `ContentDecryptor` has either been disposed or
614
+ * encountered a fatal error which made it stop.
615
+ * @returns {boolean}
616
+ */
617
+ ContentDecryptor.prototype._isStopped = function () {
618
+ return this._stateData.state === ContentDecryptorState.Disposed ||
619
+ this._stateData.state === ContentDecryptorState.Error;
620
+ };
621
+ ContentDecryptor.prototype._processCurrentInitDataQueue = function () {
622
+ while (this._stateData.isInitDataQueueLocked === false) {
623
+ var initData = this._initDataQueue.shift();
624
+ if (initData === undefined) {
625
+ return;
626
+ }
627
+ this.onInitializationData(initData);
628
+ }
629
+ };
630
+ ContentDecryptor.prototype._lockInitDataQueue = function () {
631
+ if (this._stateData.isInitDataQueueLocked === false) {
632
+ this._stateData.isInitDataQueueLocked = true;
633
+ }
634
+ };
635
+ ContentDecryptor.prototype._unlockInitDataQueue = function () {
636
+ if (this._stateData.isMediaKeysAttached !== true) {
637
+ log.error("DRM: Trying to unlock in the wrong state");
638
+ return;
639
+ }
640
+ this._stateData.isInitDataQueueLocked = false;
641
+ this._processCurrentInitDataQueue();
642
+ };
643
+ return ContentDecryptor;
644
+ }(EventEmitter));
645
+ export default ContentDecryptor;
646
+ /**
647
+ * Returns `true` if the given MediaKeySystemAccess can create
648
+ * "persistent-license" MediaKeySessions.
649
+ * @param {MediaKeySystemAccess} mediaKeySystemAccess
650
+ * @returns {Boolean}
651
+ */
652
+ function canCreatePersistentSession(mediaKeySystemAccess) {
653
+ var sessionTypes = mediaKeySystemAccess.getConfiguration().sessionTypes;
654
+ return sessionTypes !== undefined &&
655
+ arrayIncludes(sessionTypes, "persistent-license");
656
+ }
657
+ function updateDecipherability(manifest, whitelistedKeyIds, blacklistedKeyIDs) {
658
+ manifest.updateRepresentationsDeciperability(function (representation) {
659
+ if (representation.contentProtections === undefined) {
660
+ return representation.decipherable;
661
+ }
662
+ var contentKIDs = representation.contentProtections.keyIds;
663
+ for (var i = 0; i < contentKIDs.length; i++) {
664
+ var elt = contentKIDs[i];
665
+ for (var j = 0; j < blacklistedKeyIDs.length; j++) {
666
+ if (areKeyIdsEqual(blacklistedKeyIDs[j], elt.keyId)) {
667
+ return false;
668
+ }
669
+ }
670
+ for (var j = 0; j < whitelistedKeyIds.length; j++) {
671
+ if (areKeyIdsEqual(whitelistedKeyIds[j], elt.keyId)) {
672
+ return true;
673
+ }
674
+ }
675
+ }
676
+ return representation.decipherable;
677
+ });
678
+ }
679
+ function blackListProtectionData(manifest, initData) {
680
+ manifest.updateRepresentationsDeciperability(function (representation) {
681
+ var _a, _b;
682
+ if (representation.decipherable === false) {
683
+ return false;
684
+ }
685
+ var segmentProtections = (_b = (_a = representation.contentProtections) === null || _a === void 0 ? void 0 : _a.initData) !== null && _b !== void 0 ? _b : [];
686
+ var _loop_1 = function (i) {
687
+ if (initData.type === undefined ||
688
+ segmentProtections[i].type === initData.type) {
689
+ var containedInitData = initData.values.getFormattedValues()
690
+ .every(function (undecipherableVal) {
691
+ return segmentProtections[i].values.some(function (currVal) {
692
+ return (undecipherableVal.systemId === undefined ||
693
+ currVal.systemId === undecipherableVal.systemId) &&
694
+ areArraysOfNumbersEqual(currVal.data, undecipherableVal.data);
695
+ });
696
+ });
697
+ if (containedInitData) {
698
+ return { value: false };
699
+ }
700
+ }
701
+ };
702
+ for (var i = 0; i < segmentProtections.length; i++) {
703
+ var state_1 = _loop_1(i);
704
+ if (typeof state_1 === "object")
705
+ return state_1.value;
706
+ }
707
+ return representation.decipherable;
708
+ });
709
+ }
710
+ /** Enumeration of the various "state" the `ContentDecryptor` can be in. */
711
+ export var ContentDecryptorState;
712
+ (function (ContentDecryptorState) {
713
+ /**
714
+ * The `ContentDecryptor` is not yet ready to create key sessions and request
715
+ * licenses.
716
+ * This is is the initial state of the ContentDecryptor.
717
+ */
718
+ ContentDecryptorState[ContentDecryptorState["Initializing"] = 0] = "Initializing";
719
+ /**
720
+ * The `ContentDecryptor` has been initialized.
721
+ * You should now called the `attach` method when you want to add decryption
722
+ * capabilities to the HTMLMediaElement. The ContentDecryptor won't go to the
723
+ * `ReadyForContent` state until `attach` is called.
724
+ *
725
+ * For compatibility reasons, this should be done after the HTMLMediaElement's
726
+ * src attribute is set.
727
+ *
728
+ * It is also from when this state is reached that the `ContentDecryptor`'s
729
+ * `systemId` property may be known.
730
+ *
731
+ * This state is always coming after the `Initializing` state.
732
+ */
733
+ ContentDecryptorState[ContentDecryptorState["WaitingForAttachment"] = 1] = "WaitingForAttachment";
734
+ /**
735
+ * Content (encrypted or not) can begin to be pushed on the HTMLMediaElement
736
+ * (this state was needed because some browser quirks sometimes forces us to
737
+ * call EME API before this can be done).
738
+ *
739
+ * This state is always coming after the `WaitingForAttachment` state.
740
+ */
741
+ ContentDecryptorState[ContentDecryptorState["ReadyForContent"] = 2] = "ReadyForContent";
742
+ /**
743
+ * The `ContentDecryptor` has encountered a fatal error and has been stopped.
744
+ * It is now unusable.
745
+ */
746
+ ContentDecryptorState[ContentDecryptorState["Error"] = 3] = "Error";
747
+ /** The `ContentDecryptor` has been disposed of and is now unusable. */
748
+ ContentDecryptorState[ContentDecryptorState["Disposed"] = 4] = "Disposed";
749
+ })(ContentDecryptorState || (ContentDecryptorState = {}));
750
+ /**
751
+ * Returns information on all keys - explicit or implicit - that are linked to
752
+ * a loaded license.
753
+ *
754
+ * In the RxPlayer, there is a concept of "explicit" key ids, which are key ids
755
+ * found in a license whose status can be known through the `keyStatuses`
756
+ * property from a `MediaKeySession`, and of "implicit" key ids, which are key
757
+ * ids which were expected to be in a fetched license, but apparently weren't.
758
+ * @param {Object} initializationData
759
+ * @param {string|undefined} singleLicensePer
760
+ * @param {Array.<Uint8Array>} usableKeyIds
761
+ * @param {Array.<Uint8Array>} unusableKeyIds
762
+ * @returns {Object}
763
+ */
764
+ function getFetchedLicenseKeysInfo(initializationData, singleLicensePer, usableKeyIds, unusableKeyIds) {
765
+ var _a;
766
+ /**
767
+ * Every key id associated with the MediaKeySession, starting with
768
+ * whitelisted ones.
769
+ */
770
+ var associatedKeyIds = __spreadArray(__spreadArray([], usableKeyIds, true), unusableKeyIds, true);
771
+ if (singleLicensePer !== undefined && singleLicensePer !== "init-data") {
772
+ // We want to add the current key ids in the blacklist if it is
773
+ // not already there.
774
+ //
775
+ // We only do that when `singleLicensePer` is set to something
776
+ // else than the default `"init-data"` because this logic:
777
+ // 1. might result in a quality fallback, which is a v3.x.x
778
+ // breaking change if some APIs (like `singleLicensePer`)
779
+ // aren't used.
780
+ // 2. Rely on the EME spec regarding key statuses being well
781
+ // implemented on all supported devices, which we're not
782
+ // sure yet. Because in any other `singleLicensePer`, we
783
+ // need a good implementation anyway, it doesn't matter
784
+ // there.
785
+ var expectedKeyIds = initializationData.keyIds, content = initializationData.content;
786
+ if (expectedKeyIds !== undefined) {
787
+ var missingKeyIds = expectedKeyIds.filter(function (expected) {
788
+ return !associatedKeyIds.some(function (k) { return areKeyIdsEqual(k, expected); });
789
+ });
790
+ if (missingKeyIds.length > 0) {
791
+ associatedKeyIds.push.apply(associatedKeyIds, missingKeyIds);
792
+ }
793
+ }
794
+ if (content !== undefined) {
795
+ if (singleLicensePer === "content") {
796
+ // Put it in a Set to automatically filter out duplicates (by ref)
797
+ var contentKeys = new Set();
798
+ var manifest = content.manifest;
799
+ for (var _i = 0, _b = manifest.periods; _i < _b.length; _i++) {
800
+ var period = _b[_i];
801
+ addKeyIdsFromPeriod(contentKeys, period);
802
+ }
803
+ mergeKeyIdSetIntoArray(contentKeys, associatedKeyIds);
804
+ }
805
+ else if (singleLicensePer === "periods") {
806
+ var manifest = content.manifest;
807
+ for (var _c = 0, _d = manifest.periods; _c < _d.length; _c++) {
808
+ var period = _d[_c];
809
+ var periodKeys = new Set();
810
+ addKeyIdsFromPeriod(periodKeys, period);
811
+ if (((_a = initializationData.content) === null || _a === void 0 ? void 0 : _a.period.id) === period.id) {
812
+ mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
813
+ }
814
+ else {
815
+ var periodKeysArr = Array.from(periodKeys);
816
+ var _loop_2 = function (kid) {
817
+ var isFound = associatedKeyIds.some(function (k) { return areKeyIdsEqual(k, kid); });
818
+ if (isFound) {
819
+ mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
820
+ return "break";
821
+ }
822
+ };
823
+ for (var _e = 0, periodKeysArr_3 = periodKeysArr; _e < periodKeysArr_3.length; _e++) {
824
+ var kid = periodKeysArr_3[_e];
825
+ var state_2 = _loop_2(kid);
826
+ if (state_2 === "break")
827
+ break;
828
+ }
829
+ }
830
+ }
831
+ }
832
+ }
833
+ }
834
+ return { whitelisted: usableKeyIds,
835
+ /** associatedKeyIds starts with the whitelisted one. */
836
+ blacklisted: associatedKeyIds.slice(usableKeyIds.length) };
837
+ }
838
+ function mergeKeyIdSetIntoArray(set, arr) {
839
+ var setArr = Array.from(set.values());
840
+ var _loop_3 = function (kid) {
841
+ var isFound = arr.some(function (k) { return areKeyIdsEqual(k, kid); });
842
+ if (!isFound) {
843
+ arr.push(kid);
844
+ }
845
+ };
846
+ for (var _i = 0, setArr_1 = setArr; _i < setArr_1.length; _i++) {
847
+ var kid = setArr_1[_i];
848
+ _loop_3(kid);
849
+ }
850
+ }
851
+ function addKeyIdsFromPeriod(set, period) {
852
+ for (var _i = 0, _a = period.getAdaptations(); _i < _a.length; _i++) {
853
+ var adaptation = _a[_i];
854
+ for (var _b = 0, _c = adaptation.representations; _b < _c.length; _b++) {
855
+ var representation = _c[_b];
856
+ if (representation.contentProtections !== undefined &&
857
+ representation.contentProtections.keyIds.length >= -1) {
858
+ for (var _d = 0, _e = representation.contentProtections.keyIds; _d < _e.length; _d++) {
859
+ var kidInf = _e[_d];
860
+ set.add(kidInf.keyId);
861
+ }
862
+ }
863
+ }
864
+ }
865
+ }