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,1157 @@
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
+
17
+ import {
18
+ events,
19
+ generateKeyRequest,
20
+ getInitData,
21
+ ICustomMediaKeys,
22
+ ICustomMediaKeySystemAccess,
23
+ } from "../../compat/";
24
+ import config from "../../config";
25
+ import {
26
+ EncryptedMediaError,
27
+ ICustomError,
28
+ OtherError,
29
+ } from "../../errors";
30
+ import log from "../../log";
31
+ import Manifest, {
32
+ Period,
33
+ } from "../../manifest";
34
+ import areArraysOfNumbersEqual from "../../utils/are_arrays_of_numbers_equal";
35
+ import arrayFind from "../../utils/array_find";
36
+ import arrayIncludes from "../../utils/array_includes";
37
+ import EventEmitter from "../../utils/event_emitter";
38
+ import isNullOrUndefined from "../../utils/is_null_or_undefined";
39
+ import { bytesToHex } from "../../utils/string_parsing";
40
+ import TaskCanceller from "../../utils/task_canceller";
41
+ import attachMediaKeys from "./attach_media_keys";
42
+ import createOrLoadSession from "./create_or_load_session";
43
+ import { IMediaKeysInfos } from "./get_media_keys";
44
+ import initMediaKeys from "./init_media_keys";
45
+ import SessionEventsListener, {
46
+ BlacklistedSessionError,
47
+ } from "./session_events_listener";
48
+ import setServerCertificate from "./set_server_certificate";
49
+ import {
50
+ IProtectionData,
51
+ IKeySystemOption,
52
+ IMediaKeySessionStores,
53
+ MediaKeySessionLoadingType,
54
+ IProcessedProtectionData,
55
+ } from "./types";
56
+ import cleanOldStoredPersistentInfo from "./utils/clean_old_stored_persistent_info";
57
+ import getDrmSystemId from "./utils/get_drm_system_id";
58
+ import InitDataValuesContainer from "./utils/init_data_values_container";
59
+ import {
60
+ areAllKeyIdsContainedIn,
61
+ areKeyIdsEqual,
62
+ areSomeKeyIdsContainedIn,
63
+ isKeyIdContainedIn,
64
+ } from "./utils/key_id_comparison";
65
+ import KeySessionRecord from "./utils/key_session_record";
66
+
67
+ const { onEncrypted$ } = events;
68
+
69
+ /**
70
+ * Module communicating with the Content Decryption Module (or CDM) to be able
71
+ * to decrypt contents.
72
+ *
73
+ * The `ContentDecryptor` starts communicating with the CDM, to initialize the
74
+ * key system, as soon as it is created.
75
+ *
76
+ * You can be notified of various events, such as fatal errors, by registering
77
+ * to one of its multiple events (@see IContentDecryptorEvent).
78
+ *
79
+ * @class ContentDecryptor
80
+ */
81
+ export default class ContentDecryptor extends EventEmitter<IContentDecryptorEvent> {
82
+ /**
83
+ * Hexadecimal id identifying the currently-chosen key system.
84
+ * `undefined` if not known or if the key system hasn't been initialized yet.
85
+ *
86
+ * When providing protection initialization data to the ContentDecryptor, you
87
+ * may only provide those linked to that system id. You can also provide all
88
+ * available protection initialization data, in which case it will be
89
+ * automatically filtered.
90
+ *
91
+ * This `systemId` may only be known once the `ReadyForContent` state (@see
92
+ * ContentDecryptorState) is reached, and even then, it may still be unknown,
93
+ * in which case it will stay to `undefined`.
94
+ */
95
+ public systemId : string | undefined;
96
+
97
+ /**
98
+ * Set only if the `ContentDecryptor` failed on an error.
99
+ * The corresponding Error.
100
+ */
101
+ public error : Error | null;
102
+
103
+ /**
104
+ * State of the ContentDecryptor (@see ContentDecryptorState) and associated
105
+ * data.
106
+ *
107
+ * The ContentDecryptor goes into a series of steps as it is initializing.
108
+ * This private property stores the current state and the potentially linked
109
+ * data.
110
+ */
111
+ private _stateData : IContentDecryptorStateData;
112
+
113
+ /**
114
+ * Contains information about all key sessions loaded for this current
115
+ * content.
116
+ * This object is most notably used to check which keys are already obtained,
117
+ * thus avoiding to perform new unnecessary license requests and CDM interactions.
118
+ */
119
+ private _currentSessions : IActiveSessionInfo[];
120
+
121
+ /**
122
+ * Allows to dispose the resources taken by the current instance of the
123
+ * ContentDecryptor.
124
+ */
125
+ private _canceller : TaskCanceller;
126
+
127
+ /**
128
+ * `true` once the `attach` method has been called`.
129
+ * Allows to avoid calling multiple times that function.
130
+ */
131
+ private _wasAttachCalled : boolean;
132
+
133
+ /**
134
+ * This queue stores initialization data which hasn't been processed yet,
135
+ * probably because the "queue is locked" for now. (@see _stateData private
136
+ * property).
137
+ *
138
+ * For example, this queue stores initialization data communicated while
139
+ * initializing so it can be processed when the initialization is done.
140
+ */
141
+ private _initDataQueue : IProtectionData[];
142
+
143
+ /**
144
+ * Create a new `ContentDecryptor`, and initialize its decryption capabilities
145
+ * right away.
146
+ * Goes into the `WaitingForAttachment` state once that initialization is
147
+ * done, after which you should call the `attach` method when you're ready for
148
+ * those decryption capabilities to be attached to the HTMLMediaElement.
149
+ *
150
+ * @param {HTMLMediaElement} mediaElement - The MediaElement which will be
151
+ * associated to a MediaKeys object
152
+ * @param {Array.<Object>} ksOptions - key system configuration.
153
+ * The `ContentDecryptor` can be given one or multiple key system
154
+ * configurations. It will choose the appropriate one depending on user
155
+ * settings and browser support.
156
+ */
157
+ constructor(mediaElement : HTMLMediaElement, ksOptions: IKeySystemOption[]) {
158
+ super();
159
+
160
+ log.debug("DRM: Starting ContentDecryptor logic.");
161
+
162
+ const canceller = new TaskCanceller();
163
+ this._currentSessions = [];
164
+ this._canceller = canceller;
165
+ this._wasAttachCalled = false;
166
+ this._initDataQueue = [];
167
+ this._stateData = { state: ContentDecryptorState.Initializing,
168
+ isMediaKeysAttached: false,
169
+ isInitDataQueueLocked: true,
170
+ data: null };
171
+ this.error = null;
172
+
173
+ const listenerSub = onEncrypted$(mediaElement).subscribe(evt => {
174
+ log.debug("DRM: Encrypted event received from media element.");
175
+ const initData = getInitData(evt);
176
+ if (initData !== null) {
177
+ this.onInitializationData(initData);
178
+ }
179
+ });
180
+ canceller.signal.register(() => {
181
+ listenerSub.unsubscribe();
182
+ });
183
+
184
+ initMediaKeys(mediaElement, ksOptions, canceller.signal)
185
+ .then((mediaKeysInfo) => {
186
+ const { options, mediaKeySystemAccess } = mediaKeysInfo;
187
+
188
+ /**
189
+ * String identifying the key system, allowing the rest of the code to
190
+ * only advertise the required initialization data for license requests.
191
+ *
192
+ * Note that we only set this value if retro-compatibility to older
193
+ * persistent logic in the RxPlayer is not important, as the
194
+ * optimizations this property unlocks can break the loading of
195
+ * MediaKeySessions persisted in older RxPlayer's versions.
196
+ */
197
+ let systemId : string | undefined;
198
+ if (isNullOrUndefined(options.licenseStorage) ||
199
+ options.licenseStorage.disableRetroCompatibility === true)
200
+ {
201
+ systemId = getDrmSystemId(mediaKeySystemAccess.keySystem);
202
+ }
203
+
204
+ this.systemId = systemId;
205
+ if (this._stateData.state === ContentDecryptorState.Initializing) {
206
+ this._stateData = { state: ContentDecryptorState.WaitingForAttachment,
207
+ isInitDataQueueLocked: true,
208
+ isMediaKeysAttached: false,
209
+ data: { mediaKeysInfo,
210
+ mediaElement } };
211
+
212
+ this.trigger("stateChange", this._stateData.state);
213
+ }
214
+ })
215
+
216
+ .catch((err) => {
217
+ this._onFatalError(err);
218
+ });
219
+ }
220
+
221
+ /**
222
+ * Returns the current state of the ContentDecryptor.
223
+ * @see ContentDecryptorState
224
+ * @returns {Object}
225
+ */
226
+ public getState() : ContentDecryptorState {
227
+ return this._stateData.state;
228
+ }
229
+
230
+ /**
231
+ * Attach the current decryption capabilities to the HTMLMediaElement.
232
+ * This method should only be called once the `ContentDecryptor` is in the
233
+ * `WaitingForAttachment` state.
234
+ *
235
+ * You might want to first set the HTMLMediaElement's `src` attribute before
236
+ * calling this method, and only push data to it once the `ReadyForContent`
237
+ * state is reached, for compatibility reasons.
238
+ */
239
+ public attach() : void {
240
+ if (this._stateData.state !== ContentDecryptorState.WaitingForAttachment) {
241
+ throw new Error("`attach` should only be called when " +
242
+ "in the WaitingForAttachment state");
243
+ } else if (this._wasAttachCalled) {
244
+ log.warn("DRM: ContentDecryptor's `attach` method called more than once.");
245
+ return;
246
+ }
247
+ this._wasAttachCalled = true;
248
+
249
+ const { mediaElement, mediaKeysInfo } = this._stateData.data;
250
+ const { options, mediaKeys, mediaKeySystemAccess, stores } = mediaKeysInfo;
251
+ const stateToAttatch = { loadedSessionsStore: stores.loadedSessionsStore,
252
+ mediaKeySystemAccess,
253
+ mediaKeys,
254
+ keySystemOptions: options };
255
+
256
+ const shouldDisableLock = options.disableMediaKeysAttachmentLock === true;
257
+ if (shouldDisableLock) {
258
+ this._stateData = { state: ContentDecryptorState.ReadyForContent,
259
+ isInitDataQueueLocked: true,
260
+ isMediaKeysAttached: false,
261
+ data: null };
262
+ this.trigger("stateChange", this._stateData.state);
263
+ if (this._isStopped()) { // previous trigger might have lead to disposal
264
+ return ;
265
+ }
266
+ }
267
+
268
+ log.debug("DRM: Attaching current MediaKeys");
269
+ attachMediaKeys(mediaElement, stateToAttatch, this._canceller.signal)
270
+ .then(async () => {
271
+ const { serverCertificate } = options;
272
+
273
+ if (!isNullOrUndefined(serverCertificate)) {
274
+ const resSsc = await setServerCertificate(mediaKeys, serverCertificate);
275
+ if (resSsc.type === "error") {
276
+ this.trigger("warning", resSsc.value);
277
+ }
278
+ }
279
+
280
+ if (this._isStopped()) { // We might be stopped since then
281
+ return;
282
+ }
283
+
284
+ const prevState = this._stateData.state;
285
+ this._stateData = { state: ContentDecryptorState.ReadyForContent,
286
+ isMediaKeysAttached: true,
287
+ isInitDataQueueLocked: false,
288
+ data: { mediaKeysData: mediaKeysInfo } };
289
+ if (prevState !== ContentDecryptorState.ReadyForContent) {
290
+ this.trigger("stateChange", ContentDecryptorState.ReadyForContent);
291
+ }
292
+ if (!this._isStopped()) {
293
+ this._processCurrentInitDataQueue();
294
+ }
295
+ })
296
+
297
+ .catch((err) => {
298
+ this._onFatalError(err);
299
+ });
300
+ }
301
+
302
+ /**
303
+ * Stop this `ContentDecryptor` instance:
304
+ * - stop listening and reacting to the various event listeners
305
+ * - abort all operations.
306
+ *
307
+ * Once disposed, a `ContentDecryptor` cannot be used anymore.
308
+ */
309
+ public dispose() {
310
+ this.removeEventListener();
311
+ this._stateData = { state: ContentDecryptorState.Disposed,
312
+ isMediaKeysAttached: undefined,
313
+ isInitDataQueueLocked: undefined,
314
+ data: null };
315
+ this._canceller.cancel();
316
+ this.trigger("stateChange", this._stateData.state);
317
+ }
318
+
319
+ /**
320
+ * Method to call when new protection initialization data is encounted on the
321
+ * content.
322
+ *
323
+ * When called, the `ContentDecryptor` will try to obtain the decryption key
324
+ * if not already obtained.
325
+ *
326
+ * @param {Object} initializationData
327
+ */
328
+ public onInitializationData(
329
+ initializationData : IProtectionData
330
+ ) : void {
331
+ if (this._stateData.isInitDataQueueLocked !== false) {
332
+ if (this._isStopped()) {
333
+ throw new Error("ContentDecryptor either disposed or stopped.");
334
+ }
335
+ this._initDataQueue.push(initializationData);
336
+ return;
337
+ }
338
+
339
+ const { mediaKeysData } = this._stateData.data;
340
+ const processedInitializationData = {
341
+ ...initializationData,
342
+ values: new InitDataValuesContainer(initializationData.values),
343
+ };
344
+ this._processInitializationData(processedInitializationData, mediaKeysData)
345
+ .catch(err => { this._onFatalError(err); });
346
+ }
347
+
348
+ /**
349
+ * Async logic run each time new initialization data has to be processed.
350
+ * The promise return may reject, in which case a fatal error should be linked
351
+ * the current `ContentDecryptor`.
352
+ *
353
+ * The Promise's resolution however provides no semantic value.
354
+ * @param {Object} initializationData
355
+ * @returns {Promise.<void>}
356
+ */
357
+ private async _processInitializationData(
358
+ initializationData: IProcessedProtectionData,
359
+ mediaKeysData: IAttachedMediaKeysData
360
+ ) : Promise<void> {
361
+ const { mediaKeySystemAccess, stores, options } = mediaKeysData;
362
+
363
+ if (this._tryToUseAlreadyCreatedSession(initializationData, mediaKeysData) ||
364
+ this._isStopped()) // _isStopped is voluntarly checked after here
365
+ {
366
+ return;
367
+ }
368
+
369
+ if (options.singleLicensePer === "content") {
370
+ const firstCreatedSession = arrayFind(this._currentSessions, (x) =>
371
+ x.source === MediaKeySessionLoadingType.Created);
372
+
373
+ if (firstCreatedSession !== undefined) {
374
+ // We already fetched a `singleLicensePer: "content"` license, yet we
375
+ // could not use the already-created MediaKeySession with it.
376
+ // It means that we'll never handle it and we should thus blacklist it.
377
+ const keyIds = initializationData.keyIds;
378
+ if (keyIds === undefined) {
379
+ if (initializationData.content === undefined) {
380
+ log.warn("DRM: Unable to fallback from a non-decipherable quality.");
381
+ } else {
382
+ blackListProtectionData(initializationData.content.manifest,
383
+ initializationData);
384
+ }
385
+ return ;
386
+ }
387
+
388
+ firstCreatedSession.record.associateKeyIds(keyIds);
389
+ if (initializationData.content !== undefined) {
390
+ if (log.getLevel() === "DEBUG") {
391
+ const hexKids = keyIds
392
+ .reduce((acc, kid) => `${acc}, ${bytesToHex(kid)}`, "");
393
+ log.debug("DRM: Blacklisting new key ids", hexKids);
394
+ }
395
+ updateDecipherability(initializationData.content.manifest, [], keyIds);
396
+ }
397
+ return ;
398
+ }
399
+ } else if (options.singleLicensePer === "periods" &&
400
+ initializationData.content !== undefined)
401
+ {
402
+ const { period } = initializationData.content;
403
+ const createdSessions = this._currentSessions
404
+ .filter(x => x.source === MediaKeySessionLoadingType.Created);
405
+ const periodKeys = new Set<Uint8Array>();
406
+ addKeyIdsFromPeriod(periodKeys, period);
407
+ for (const createdSess of createdSessions) {
408
+ const periodKeysArr = Array.from(periodKeys);
409
+ for (const kid of periodKeysArr) {
410
+ if (createdSess.record.isAssociatedWithKeyId(kid)) {
411
+ createdSess.record.associateKeyIds(periodKeys.values());
412
+
413
+ // Re-loop through the Period's key ids to blacklist ones that are missing
414
+ // from `createdSess`'s `keyStatuses` and to update the content's
415
+ // decipherability.
416
+ for (const innerKid of periodKeysArr) {
417
+ if (!isKeyIdContainedIn(innerKid, createdSess.keyStatuses.whitelisted) &&
418
+ !isKeyIdContainedIn(innerKid, createdSess.keyStatuses.blacklisted))
419
+ {
420
+ createdSess.keyStatuses.blacklisted.push(innerKid);
421
+ }
422
+ }
423
+ updateDecipherability(initializationData.content.manifest,
424
+ createdSess.keyStatuses.whitelisted,
425
+ createdSess.keyStatuses.blacklisted);
426
+ return;
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ // /!\ Do not forget to unlock when done
433
+ // TODO this is error-prone and can lead to performance issue when loading
434
+ // persistent sessions.
435
+ // Can we find a better strategy?
436
+ this._lockInitDataQueue();
437
+
438
+ let wantedSessionType : MediaKeySessionType;
439
+ if (options.persistentLicense !== true) {
440
+ wantedSessionType = "temporary";
441
+ } else if (!canCreatePersistentSession(mediaKeySystemAccess)) {
442
+ log.warn("DRM: Cannot create \"persistent-license\" session: not supported");
443
+ wantedSessionType = "temporary";
444
+ } else {
445
+ wantedSessionType = "persistent-license";
446
+ }
447
+
448
+ const { EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS,
449
+ EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION } = config.getCurrent();
450
+
451
+ const maxSessionCacheSize = typeof options.maxSessionCacheSize === "number" ?
452
+ options.maxSessionCacheSize :
453
+ EME_DEFAULT_MAX_SIMULTANEOUS_MEDIA_KEY_SESSIONS;
454
+
455
+ const sessionRes = await createOrLoadSession(initializationData,
456
+ stores,
457
+ wantedSessionType,
458
+ maxSessionCacheSize,
459
+ this._canceller.signal);
460
+ if (this._isStopped()) {
461
+ return;
462
+ }
463
+
464
+ const sessionInfo : IActiveSessionInfo = {
465
+ record: sessionRes.value.keySessionRecord,
466
+ source: sessionRes.type,
467
+ keyStatuses: { whitelisted: [], blacklisted: [] },
468
+ blacklistedSessionError: null,
469
+ };
470
+ this._currentSessions.push(sessionInfo);
471
+
472
+ const { mediaKeySession, sessionType } = sessionRes.value;
473
+
474
+ /**
475
+ * We only store persistent sessions once its keys are known.
476
+ * This boolean allows to know if this session has already been
477
+ * persisted or not.
478
+ */
479
+ let isSessionPersisted = false;
480
+
481
+ const sub = SessionEventsListener(mediaKeySession,
482
+ options,
483
+ mediaKeySystemAccess.keySystem)
484
+ .subscribe({
485
+
486
+ next: (evt) : void => {
487
+ switch (evt.type) {
488
+ case "warning":
489
+ this.trigger("warning", evt.value);
490
+ return;
491
+ }
492
+
493
+ let linkedKeys;
494
+ if (sessionInfo.source === MediaKeySessionLoadingType.Created) {
495
+ // When the license has been fetched, there might be implicit key ids
496
+ // linked to the session depending on the `singleLicensePer` option.
497
+ linkedKeys = getFetchedLicenseKeysInfo(initializationData,
498
+ options.singleLicensePer,
499
+ evt.value.whitelistedKeyIds,
500
+ evt.value.blacklistedKeyIDs);
501
+ } else {
502
+ // When the MediaKeySession is just a cached/persisted one, we don't
503
+ // have any concept of "implicit key id".
504
+ linkedKeys = { whitelisted: evt.value.whitelistedKeyIds,
505
+ blacklisted: evt.value.blacklistedKeyIDs };
506
+ }
507
+
508
+ sessionInfo.record.associateKeyIds(linkedKeys.whitelisted);
509
+ sessionInfo.record.associateKeyIds(linkedKeys.blacklisted);
510
+ sessionInfo.keyStatuses = { whitelisted: linkedKeys.whitelisted,
511
+ blacklisted: linkedKeys.blacklisted };
512
+
513
+ if (sessionInfo.record.getAssociatedKeyIds().length !== 0 &&
514
+ sessionType === "persistent-license" &&
515
+ stores.persistentSessionsStore !== null &&
516
+ !isSessionPersisted)
517
+ {
518
+ const { persistentSessionsStore } = stores;
519
+ cleanOldStoredPersistentInfo(
520
+ persistentSessionsStore,
521
+ EME_MAX_STORED_PERSISTENT_SESSION_INFORMATION - 1);
522
+ persistentSessionsStore.add(initializationData,
523
+ sessionInfo.record.getAssociatedKeyIds(),
524
+ mediaKeySession);
525
+ isSessionPersisted = true;
526
+ }
527
+
528
+ if (initializationData.content !== undefined) {
529
+ updateDecipherability(initializationData.content.manifest,
530
+ linkedKeys.whitelisted,
531
+ linkedKeys.blacklisted);
532
+ }
533
+
534
+ this._unlockInitDataQueue();
535
+ },
536
+
537
+ error: (err) => {
538
+ if (!(err instanceof BlacklistedSessionError)) {
539
+ this._onFatalError(err);
540
+ return ;
541
+ }
542
+
543
+ sessionInfo.blacklistedSessionError = err;
544
+
545
+ if (initializationData.content !== undefined) {
546
+ const { manifest } = initializationData.content;
547
+ log.info("DRM: blacklisting Representations based on " +
548
+ "protection data.");
549
+ blackListProtectionData(manifest, initializationData);
550
+ }
551
+
552
+ this._unlockInitDataQueue();
553
+
554
+ // TODO warning for blacklisted session?
555
+ },
556
+ });
557
+ this._canceller.signal.register(() => {
558
+ sub.unsubscribe();
559
+ });
560
+
561
+ if (options.singleLicensePer === undefined ||
562
+ options.singleLicensePer === "init-data")
563
+ {
564
+ this._unlockInitDataQueue();
565
+ }
566
+
567
+ if (sessionRes.type === MediaKeySessionLoadingType.Created) {
568
+ const requestData = initializationData.values.constructRequestData();
569
+ try {
570
+ await generateKeyRequest(mediaKeySession,
571
+ initializationData.type,
572
+ requestData);
573
+ } catch (error) {
574
+ throw new EncryptedMediaError("KEY_GENERATE_REQUEST_ERROR",
575
+ error instanceof Error ? error.toString() :
576
+ "Unknown error");
577
+ }
578
+ }
579
+
580
+ return Promise.resolve();
581
+ }
582
+
583
+ private _tryToUseAlreadyCreatedSession(
584
+ initializationData : IProcessedProtectionData,
585
+ mediaKeysData : IAttachedMediaKeysData
586
+ ) : boolean {
587
+ const { stores, options } = mediaKeysData;
588
+
589
+ /**
590
+ * If set, a currently-used key session is already compatible to this
591
+ * initialization data.
592
+ */
593
+ const compatibleSessionInfo = arrayFind(
594
+ this._currentSessions,
595
+ (x) => x.record.isCompatibleWith(initializationData));
596
+
597
+ if (compatibleSessionInfo === undefined) {
598
+ return false;
599
+ }
600
+
601
+ // Check if the compatible session is blacklisted
602
+ const blacklistedSessionError = compatibleSessionInfo.blacklistedSessionError;
603
+ if (!isNullOrUndefined(blacklistedSessionError)) {
604
+ if (initializationData.type === undefined ||
605
+ initializationData.content === undefined)
606
+ {
607
+ log.error("DRM: This initialization data has already been blacklisted " +
608
+ "but the current content is not known.");
609
+ return true;
610
+ } else {
611
+ log.info("DRM: This initialization data has already been blacklisted. " +
612
+ "Blacklisting the related content.");
613
+ const { manifest } = initializationData.content;
614
+ blackListProtectionData(manifest, initializationData);
615
+ return true;
616
+ }
617
+ }
618
+
619
+ // Check if the current key id(s) has been blacklisted by this session
620
+ if (initializationData.keyIds !== undefined) {
621
+ /**
622
+ * If set to `true`, the Representation(s) linked to this
623
+ * initialization data's key id should be marked as "not decipherable".
624
+ */
625
+ let isUndecipherable : boolean;
626
+
627
+ if (options.singleLicensePer === undefined ||
628
+ options.singleLicensePer === "init-data")
629
+ {
630
+ // Note: In the default "init-data" mode, we only avoid a
631
+ // Representation if the key id was originally explicitely
632
+ // blacklisted (and not e.g. if its key was just not present in
633
+ // the license).
634
+ //
635
+ // This is to enforce v3.x.x retro-compatibility: we cannot
636
+ // fallback from a Representation unless some RxPlayer option
637
+ // documentating this behavior has been set.
638
+ const { blacklisted } = compatibleSessionInfo.keyStatuses;
639
+ isUndecipherable = areSomeKeyIdsContainedIn(initializationData.keyIds,
640
+ blacklisted);
641
+ } else {
642
+ // In any other mode, as soon as not all of this initialization
643
+ // data's linked key ids are explicitely whitelisted, we can mark
644
+ // the corresponding Representation as "not decipherable".
645
+ // This is because we've no such retro-compatibility guarantee to
646
+ // make there.
647
+ const { whitelisted } = compatibleSessionInfo.keyStatuses;
648
+ isUndecipherable = !areAllKeyIdsContainedIn(initializationData.keyIds,
649
+ whitelisted);
650
+ }
651
+
652
+ if (isUndecipherable) {
653
+ if (initializationData.content === undefined) {
654
+ log.error("DRM: Cannot forbid key id, the content is unknown.");
655
+ return true;
656
+ }
657
+ log.info("DRM: Current initialization data is linked to blacklisted keys. " +
658
+ "Marking Representations as not decipherable");
659
+ updateDecipherability(initializationData.content.manifest,
660
+ [],
661
+ initializationData.keyIds);
662
+ return true;
663
+ }
664
+ }
665
+
666
+ // If we reached here, it means that this initialization data is not
667
+ // blacklisted in any way.
668
+ // Search loaded session and put it on top of the cache if it exists.
669
+ const entry = stores.loadedSessionsStore.reuse(initializationData);
670
+ if (entry !== null) {
671
+ // TODO update decipherability to `true` if not?
672
+ log.debug("DRM: Init data already processed. Skipping it.");
673
+ return true;
674
+ }
675
+
676
+ // Session not found in `loadedSessionsStore`, it might have been closed
677
+ // since.
678
+ // Remove from `this._currentSessions` and start again.
679
+ const indexOf = this._currentSessions.indexOf(compatibleSessionInfo);
680
+ if (indexOf === -1) {
681
+ log.error("DRM: Unable to remove processed init data: not found.");
682
+ } else {
683
+ log.debug("DRM: A session from a processed init data is not available " +
684
+ "anymore. Re-processing it.");
685
+ this._currentSessions.splice(indexOf, 1);
686
+ }
687
+ return false;
688
+ }
689
+
690
+ private _onFatalError(err : unknown) {
691
+ if (this._canceller.isUsed) {
692
+ return;
693
+ }
694
+ const formattedErr = err instanceof Error ?
695
+ err :
696
+ new OtherError("NONE", "Unknown encryption error");
697
+ this.error = formattedErr;
698
+ this._initDataQueue.length = 0;
699
+ this._stateData = { state: ContentDecryptorState.Error,
700
+ isMediaKeysAttached: undefined,
701
+ isInitDataQueueLocked: undefined,
702
+ data: null };
703
+ this._canceller.cancel();
704
+ this.trigger("error", formattedErr);
705
+
706
+ // The previous trigger might have lead to a disposal of the `ContentDecryptor`.
707
+ if (this._stateData.state === ContentDecryptorState.Error) {
708
+ this.trigger("stateChange", this._stateData.state);
709
+ }
710
+ }
711
+
712
+ /**
713
+ * Return `true` if the `ContentDecryptor` has either been disposed or
714
+ * encountered a fatal error which made it stop.
715
+ * @returns {boolean}
716
+ */
717
+ private _isStopped() : boolean {
718
+ return this._stateData.state === ContentDecryptorState.Disposed ||
719
+ this._stateData.state === ContentDecryptorState.Error;
720
+ }
721
+
722
+ private _processCurrentInitDataQueue() {
723
+ while (this._stateData.isInitDataQueueLocked === false) {
724
+ const initData = this._initDataQueue.shift();
725
+ if (initData === undefined) {
726
+ return;
727
+ }
728
+ this.onInitializationData(initData);
729
+ }
730
+ }
731
+
732
+ private _lockInitDataQueue() {
733
+ if (this._stateData.isInitDataQueueLocked === false) {
734
+ this._stateData.isInitDataQueueLocked = true;
735
+ }
736
+ }
737
+
738
+ private _unlockInitDataQueue() {
739
+ if (this._stateData.isMediaKeysAttached !== true) {
740
+ log.error("DRM: Trying to unlock in the wrong state");
741
+ return;
742
+ }
743
+ this._stateData.isInitDataQueueLocked = false;
744
+ this._processCurrentInitDataQueue();
745
+ }
746
+ }
747
+
748
+ /**
749
+ * Returns `true` if the given MediaKeySystemAccess can create
750
+ * "persistent-license" MediaKeySessions.
751
+ * @param {MediaKeySystemAccess} mediaKeySystemAccess
752
+ * @returns {Boolean}
753
+ */
754
+ function canCreatePersistentSession(
755
+ mediaKeySystemAccess : MediaKeySystemAccess | ICustomMediaKeySystemAccess
756
+ ) : boolean {
757
+ const { sessionTypes } = mediaKeySystemAccess.getConfiguration();
758
+ return sessionTypes !== undefined &&
759
+ arrayIncludes(sessionTypes, "persistent-license");
760
+ }
761
+
762
+ function updateDecipherability(
763
+ manifest : Manifest,
764
+ whitelistedKeyIds : Uint8Array[],
765
+ blacklistedKeyIDs : Uint8Array[]
766
+ ) : void {
767
+ manifest.updateRepresentationsDeciperability((representation) => {
768
+ if (representation.contentProtections === undefined) {
769
+ return representation.decipherable;
770
+ }
771
+ const contentKIDs = representation.contentProtections.keyIds;
772
+ for (let i = 0; i < contentKIDs.length; i++) {
773
+ const elt = contentKIDs[i];
774
+ for (let j = 0; j < blacklistedKeyIDs.length; j++) {
775
+ if (areKeyIdsEqual(blacklistedKeyIDs[j], elt.keyId)) {
776
+ return false;
777
+ }
778
+ }
779
+ for (let j = 0; j < whitelistedKeyIds.length; j++) {
780
+ if (areKeyIdsEqual(whitelistedKeyIds[j], elt.keyId)) {
781
+ return true;
782
+ }
783
+ }
784
+ }
785
+ return representation.decipherable;
786
+ });
787
+ }
788
+
789
+ function blackListProtectionData(
790
+ manifest : Manifest,
791
+ initData : IProcessedProtectionData
792
+ ) : void {
793
+ manifest.updateRepresentationsDeciperability((representation) => {
794
+ if (representation.decipherable === false) {
795
+ return false;
796
+ }
797
+ const segmentProtections = representation.contentProtections?.initData ?? [];
798
+ for (let i = 0; i < segmentProtections.length; i++) {
799
+ if (initData.type === undefined ||
800
+ segmentProtections[i].type === initData.type)
801
+ {
802
+ const containedInitData = initData.values.getFormattedValues()
803
+ .every(undecipherableVal => {
804
+ return segmentProtections[i].values.some(currVal => {
805
+ return (undecipherableVal.systemId === undefined ||
806
+ currVal.systemId === undecipherableVal.systemId) &&
807
+ areArraysOfNumbersEqual(currVal.data,
808
+ undecipherableVal.data);
809
+ });
810
+ });
811
+ if (containedInitData) {
812
+ return false;
813
+ }
814
+ }
815
+ }
816
+ return representation.decipherable;
817
+ });
818
+ }
819
+
820
+ /** Events sent by the `ContentDecryptor`, in a `{ event: payload }` format. */
821
+ export interface IContentDecryptorEvent {
822
+ /**
823
+ * Event emitted when a major error occured which made the ContentDecryptor
824
+ * stopped.
825
+ * When that event is sent, the `ContentDecryptor` is in the `Error` state and
826
+ * cannot be used anymore.
827
+ */
828
+ error : Error;
829
+
830
+ /**
831
+ * Event emitted when a minor error occured which the ContentDecryptor can
832
+ * recover from.
833
+ */
834
+ warning : ICustomError;
835
+
836
+ /**
837
+ * Event emitted when the `ContentDecryptor`'s state changed.
838
+ * States are a central aspect of the `ContentDecryptor`, be sure to check the
839
+ * ContentDecryptorState type.
840
+ */
841
+ stateChange: ContentDecryptorState;
842
+ }
843
+
844
+ /** Enumeration of the various "state" the `ContentDecryptor` can be in. */
845
+ export enum ContentDecryptorState {
846
+ /**
847
+ * The `ContentDecryptor` is not yet ready to create key sessions and request
848
+ * licenses.
849
+ * This is is the initial state of the ContentDecryptor.
850
+ */
851
+ Initializing,
852
+
853
+ /**
854
+ * The `ContentDecryptor` has been initialized.
855
+ * You should now called the `attach` method when you want to add decryption
856
+ * capabilities to the HTMLMediaElement. The ContentDecryptor won't go to the
857
+ * `ReadyForContent` state until `attach` is called.
858
+ *
859
+ * For compatibility reasons, this should be done after the HTMLMediaElement's
860
+ * src attribute is set.
861
+ *
862
+ * It is also from when this state is reached that the `ContentDecryptor`'s
863
+ * `systemId` property may be known.
864
+ *
865
+ * This state is always coming after the `Initializing` state.
866
+ */
867
+ WaitingForAttachment,
868
+
869
+ /**
870
+ * Content (encrypted or not) can begin to be pushed on the HTMLMediaElement
871
+ * (this state was needed because some browser quirks sometimes forces us to
872
+ * call EME API before this can be done).
873
+ *
874
+ * This state is always coming after the `WaitingForAttachment` state.
875
+ */
876
+ ReadyForContent,
877
+
878
+ /**
879
+ * The `ContentDecryptor` has encountered a fatal error and has been stopped.
880
+ * It is now unusable.
881
+ */
882
+ Error,
883
+
884
+ /** The `ContentDecryptor` has been disposed of and is now unusable. */
885
+ Disposed,
886
+ }
887
+
888
+ /** Possible states the ContentDecryptor is in and associated data for each one. */
889
+ type IContentDecryptorStateData = IInitializingStateData |
890
+ IWaitingForAttachmentStateData |
891
+ IReadyForContentStateDataUnattached |
892
+ IReadyForContentStateDataAttached |
893
+ IDisposeStateData |
894
+ IErrorStateData;
895
+
896
+ /** Skeleton that all variants of `IContentDecryptorStateData` use. */
897
+ interface IContentDecryptorStateBase<
898
+ TStateName extends ContentDecryptorState,
899
+ TIsQueueLocked extends boolean | undefined,
900
+ TIsMediaKeyAttached extends boolean | undefined,
901
+ TData
902
+ > {
903
+ /** Identify the ContentDecryptor's state. */
904
+ state: TStateName;
905
+ /**
906
+ * If `true`, the `ContentDecryptor` will wait before processing
907
+ * newly-received initialization data.
908
+ * If `false`, it will process them right away.
909
+ * Set to undefined when it won't ever process them like for example in a
910
+ * disposed or errored state.
911
+ */
912
+ isInitDataQueueLocked: TIsQueueLocked;
913
+ /**
914
+ * If `true`, the `MediaKeys` instance has been attached to the HTMLMediaElement.
915
+ * If `false`, it hasn't happened yet.
916
+ * If uncertain or unimportant (for example if the `ContentDecryptor` is an
917
+ * disposed/errored state, set to `undefined`).
918
+ */
919
+ isMediaKeysAttached: TIsMediaKeyAttached;
920
+ /** Data stored relative to that state. */
921
+ data: TData;
922
+ }
923
+
924
+ /** ContentDecryptor's internal data when in the `Initializing` state. */
925
+ type IInitializingStateData = IContentDecryptorStateBase<
926
+ ContentDecryptorState.Initializing,
927
+ true, // isInitDataQueueLocked
928
+ false, // isMediaKeysAttached
929
+ null // data
930
+ >;
931
+
932
+ /** ContentDecryptor's internal data when in the `WaitingForAttachment` state. */
933
+ type IWaitingForAttachmentStateData = IContentDecryptorStateBase<
934
+ ContentDecryptorState.WaitingForAttachment,
935
+ true, // isInitDataQueueLocked
936
+ false, // isMediaKeysAttached
937
+ // data
938
+ { mediaKeysInfo : IMediaKeysInfos;
939
+ mediaElement : HTMLMediaElement; }
940
+ >;
941
+
942
+ /**
943
+ * ContentDecryptor's internal data when in the `ReadyForContent` state before
944
+ * it has attached the `MediaKeys` to the media element.
945
+ */
946
+ type IReadyForContentStateDataUnattached = IContentDecryptorStateBase<
947
+ ContentDecryptorState.ReadyForContent,
948
+ true, // isInitDataQueueLocked
949
+ false, // isMediaKeysAttached
950
+ null // data
951
+ >;
952
+
953
+ /**
954
+ * ContentDecryptor's internal data when in the `ReadyForContent` state once
955
+ * it has attached the `MediaKeys` to the media element.
956
+ */
957
+ type IReadyForContentStateDataAttached = IContentDecryptorStateBase<
958
+ ContentDecryptorState.ReadyForContent,
959
+ boolean, // isInitDataQueueLocked
960
+ true, // isMediaKeysAttached
961
+ {
962
+ /**
963
+ * MediaKeys-related information linked to this instance of the
964
+ * `ContentDecryptor`.
965
+ * Set to `null` until it is known.
966
+ * Should be always set when the `ContentDecryptor` has reached the
967
+ * Initialized state (@see ContentDecryptorState).
968
+ */
969
+ mediaKeysData : IAttachedMediaKeysData;
970
+ }
971
+ >;
972
+
973
+ /** ContentDecryptor's internal data when in the `Disposed` state. */
974
+ type IDisposeStateData = IContentDecryptorStateBase<
975
+ ContentDecryptorState.Disposed,
976
+ undefined, // isInitDataQueueLocked
977
+ undefined, // isMediaKeysAttached
978
+ null // data
979
+ >;
980
+
981
+ /** ContentDecryptor's internal data when in the `Error` state. */
982
+ type IErrorStateData = IContentDecryptorStateBase<
983
+ ContentDecryptorState.Error,
984
+ undefined, // isInitDataQueueLocked
985
+ undefined, // isMediaKeysAttached
986
+ null // data
987
+ >;
988
+
989
+ /** Information linked to a session created by the `ContentDecryptor`. */
990
+ interface IActiveSessionInfo {
991
+ /**
992
+ * Record associated to the session.
993
+ * Most notably, it allows both to identify the session as well as to
994
+ * anounce and find out which key ids are already handled.
995
+ */
996
+ record : KeySessionRecord;
997
+
998
+ /** Current keys' statuses linked that session. */
999
+ keyStatuses : {
1000
+ /** Key ids linked to keys that are "usable". */
1001
+ whitelisted : Uint8Array[];
1002
+ /**
1003
+ * Key ids linked to keys that are not considered "usable".
1004
+ * Content linked to those keys are not decipherable and may thus be
1005
+ * fallbacked from.
1006
+ */
1007
+ blacklisted : Uint8Array[];
1008
+ };
1009
+
1010
+ /** Source of the MediaKeySession linked to that record. */
1011
+ source : MediaKeySessionLoadingType;
1012
+
1013
+ /**
1014
+ * If different than `null`, all initialization data compatible with this
1015
+ * processed initialization data has been blacklisted with this corresponding
1016
+ * error.
1017
+ */
1018
+ blacklistedSessionError : BlacklistedSessionError | null;
1019
+ }
1020
+
1021
+ /**
1022
+ * Sent when the created (or already created) MediaKeys is attached to the
1023
+ * current HTMLMediaElement element.
1024
+ * On some peculiar devices, we have to wait for that step before the first
1025
+ * media segments are to be pushed to avoid issues.
1026
+ * Because this event is sent after a MediaKeys is created, you will always have
1027
+ * a "created-media-keys" event before an "attached-media-keys" event.
1028
+ */
1029
+ interface IAttachedMediaKeysData {
1030
+ /** The MediaKeySystemAccess which allowed to create the MediaKeys instance. */
1031
+ mediaKeySystemAccess: MediaKeySystemAccess |
1032
+ ICustomMediaKeySystemAccess;
1033
+ /** The MediaKeys instance. */
1034
+ mediaKeys : MediaKeys |
1035
+ ICustomMediaKeys;
1036
+ stores : IMediaKeySessionStores;
1037
+ options : IKeySystemOption;
1038
+ }
1039
+
1040
+ /**
1041
+ * Returns information on all keys - explicit or implicit - that are linked to
1042
+ * a loaded license.
1043
+ *
1044
+ * In the RxPlayer, there is a concept of "explicit" key ids, which are key ids
1045
+ * found in a license whose status can be known through the `keyStatuses`
1046
+ * property from a `MediaKeySession`, and of "implicit" key ids, which are key
1047
+ * ids which were expected to be in a fetched license, but apparently weren't.
1048
+ * @param {Object} initializationData
1049
+ * @param {string|undefined} singleLicensePer
1050
+ * @param {Array.<Uint8Array>} usableKeyIds
1051
+ * @param {Array.<Uint8Array>} unusableKeyIds
1052
+ * @returns {Object}
1053
+ */
1054
+ function getFetchedLicenseKeysInfo(
1055
+ initializationData : IProcessedProtectionData,
1056
+ singleLicensePer : undefined | "init-data" | "content" | "periods",
1057
+ usableKeyIds : Uint8Array[],
1058
+ unusableKeyIds : Uint8Array[]
1059
+ ) : { whitelisted : Uint8Array[];
1060
+ blacklisted : Uint8Array[]; }
1061
+ {
1062
+ /**
1063
+ * Every key id associated with the MediaKeySession, starting with
1064
+ * whitelisted ones.
1065
+ */
1066
+ const associatedKeyIds = [...usableKeyIds,
1067
+ ...unusableKeyIds];
1068
+
1069
+ if (singleLicensePer !== undefined && singleLicensePer !== "init-data") {
1070
+ // We want to add the current key ids in the blacklist if it is
1071
+ // not already there.
1072
+ //
1073
+ // We only do that when `singleLicensePer` is set to something
1074
+ // else than the default `"init-data"` because this logic:
1075
+ // 1. might result in a quality fallback, which is a v3.x.x
1076
+ // breaking change if some APIs (like `singleLicensePer`)
1077
+ // aren't used.
1078
+ // 2. Rely on the EME spec regarding key statuses being well
1079
+ // implemented on all supported devices, which we're not
1080
+ // sure yet. Because in any other `singleLicensePer`, we
1081
+ // need a good implementation anyway, it doesn't matter
1082
+ // there.
1083
+ const { keyIds: expectedKeyIds,
1084
+ content } = initializationData;
1085
+ if (expectedKeyIds !== undefined) {
1086
+ const missingKeyIds = expectedKeyIds.filter(expected => {
1087
+ return !associatedKeyIds.some(k => areKeyIdsEqual(k, expected));
1088
+ });
1089
+ if (missingKeyIds.length > 0) {
1090
+ associatedKeyIds.push(...missingKeyIds) ;
1091
+ }
1092
+ }
1093
+
1094
+ if (content !== undefined) {
1095
+ if (singleLicensePer === "content") {
1096
+ // Put it in a Set to automatically filter out duplicates (by ref)
1097
+ const contentKeys = new Set<Uint8Array>();
1098
+ const { manifest } = content;
1099
+ for (const period of manifest.periods) {
1100
+ addKeyIdsFromPeriod(contentKeys, period);
1101
+ }
1102
+ mergeKeyIdSetIntoArray(contentKeys, associatedKeyIds);
1103
+ } else if (singleLicensePer === "periods") {
1104
+ const { manifest } = content;
1105
+ for (const period of manifest.periods) {
1106
+ const periodKeys = new Set<Uint8Array>();
1107
+ addKeyIdsFromPeriod(periodKeys, period);
1108
+ if (initializationData.content?.period.id === period.id) {
1109
+ mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
1110
+ } else {
1111
+ const periodKeysArr = Array.from(periodKeys);
1112
+ for (const kid of periodKeysArr) {
1113
+ const isFound = associatedKeyIds.some(k => areKeyIdsEqual(k, kid));
1114
+ if (isFound) {
1115
+ mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
1116
+ break;
1117
+ }
1118
+ }
1119
+ }
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ return { whitelisted: usableKeyIds,
1125
+ /** associatedKeyIds starts with the whitelisted one. */
1126
+ blacklisted: associatedKeyIds.slice(usableKeyIds.length) };
1127
+ }
1128
+
1129
+ function mergeKeyIdSetIntoArray(
1130
+ set : Set<Uint8Array>,
1131
+ arr : Uint8Array[]
1132
+ ) {
1133
+ const setArr = Array.from(set.values());
1134
+ for (const kid of setArr) {
1135
+ const isFound = arr.some(k => areKeyIdsEqual(k, kid));
1136
+ if (!isFound) {
1137
+ arr.push(kid);
1138
+ }
1139
+ }
1140
+ }
1141
+
1142
+ function addKeyIdsFromPeriod(
1143
+ set : Set<Uint8Array>,
1144
+ period : Period
1145
+ ) {
1146
+ for (const adaptation of period.getAdaptations()) {
1147
+ for (const representation of adaptation.representations) {
1148
+ if (representation.contentProtections !== undefined &&
1149
+ representation.contentProtections.keyIds.length >= - 1)
1150
+ {
1151
+ for (const kidInf of representation.contentProtections.keyIds) {
1152
+ set.add(kidInf.keyId);
1153
+ }
1154
+ }
1155
+ }
1156
+ }
1157
+ }