shaka-player 3.3.2 → 4.0.0

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 (389) hide show
  1. package/.csslintrc +11 -1
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  3. package/.github/pull_request_template.md +6 -34
  4. package/.github/workflows/build-and-test.yaml +129 -0
  5. package/.github/workflows/custom-actions/prep-for-appspot/action.yaml +56 -0
  6. package/.github/workflows/custom-actions/set-commit-status/action.yaml +41 -0
  7. package/.github/workflows/demo-version-index.yaml +37 -0
  8. package/.github/workflows/nightly-demo.yaml +42 -0
  9. package/.github/workflows/release-please.yaml +168 -0
  10. package/.github/workflows/safari-homedir-launcher.sh +18 -0
  11. package/.github/workflows/selenium-lab-tests.yaml +92 -0
  12. package/.github/workflows/sync-labels.yaml +33 -0
  13. package/.github/workflows/update-issues.yaml +29 -0
  14. package/.github/workflows/validate-pr-title.yaml +35 -0
  15. package/AUTHORS +3 -0
  16. package/CHANGELOG.md +1866 -1675
  17. package/CONTRIBUTING.md +2 -2
  18. package/CONTRIBUTORS +3 -0
  19. package/README.md +16 -13
  20. package/app-engine/README.md +9 -0
  21. package/app-engine/demo-version-index/README.md +14 -0
  22. package/app-engine/demo-version-index/app.yaml +28 -0
  23. package/app-engine/demo-version-index/generate.py +164 -0
  24. package/app-engine/demo-version-index/main.py +11 -0
  25. package/app-engine/demo-version-index/requirements.txt +5 -0
  26. package/app-engine/demo-version-index/templates/index.html +114 -0
  27. package/app-engine/shaka-player-demo/README.md +18 -0
  28. package/app-engine/shaka-player-demo/app.yaml +61 -0
  29. package/app-engine/shaka-player-demo/main.py +95 -0
  30. package/app-engine/shaka-player-demo/posters/10yo.png +0 -0
  31. package/app-engine/shaka-player-demo/posters/10yo.xcf +0 -0
  32. package/app-engine/shaka-player-demo/posters/1yo.jpg +0 -0
  33. package/app-engine/shaka-player-demo/posters/2yo.png +0 -0
  34. package/app-engine/shaka-player-demo/posters/2yo.xcf +0 -0
  35. package/app-engine/shaka-player-demo/posters/3yo.png +0 -0
  36. package/app-engine/shaka-player-demo/posters/3yo.xcf +0 -0
  37. package/app-engine/shaka-player-demo/posters/4yo.png +0 -0
  38. package/app-engine/shaka-player-demo/posters/4yo.xcf +0 -0
  39. package/app-engine/shaka-player-demo/posters/5yo.png +0 -0
  40. package/app-engine/shaka-player-demo/posters/5yo.xcf +0 -0
  41. package/app-engine/shaka-player-demo/posters/6yo.png +0 -0
  42. package/app-engine/shaka-player-demo/posters/6yo.xcf +0 -0
  43. package/app-engine/shaka-player-demo/posters/7yo.png +0 -0
  44. package/app-engine/shaka-player-demo/posters/7yo.xcf +0 -0
  45. package/app-engine/shaka-player-demo/posters/8yo.png +0 -0
  46. package/app-engine/shaka-player-demo/posters/8yo.xcf +0 -0
  47. package/app-engine/shaka-player-demo/posters/9yo.png +0 -0
  48. package/app-engine/shaka-player-demo/posters/9yo.xcf +0 -0
  49. package/app-engine/shaka-player-demo/posters/audioOnly.gif +0 -0
  50. package/app-engine/shaka-player-demo/posters/audioRickRoll.gif +0 -0
  51. package/app-engine/shaka-player-demo/posters/colorbars.gif +0 -0
  52. package/app-engine/shaka-player-demo/posters/fireworks.jpg +0 -0
  53. package/app-engine/shaka-player-demo/posters/party-hat.png +0 -0
  54. package/app-engine/shaka-player-demo/posters/sources.txt +46 -0
  55. package/app-engine/shaka-player-demo/posters/standard.png +0 -0
  56. package/app-engine/shaka-player-demo/posters/trek.jpg +0 -0
  57. package/app-engine/shaka-player-demo/posters/valentines.png +0 -0
  58. package/app-engine/shaka-player-demo/posters/zombie.jpg +0 -0
  59. package/app-engine/shaka-player-demo/posters.py +110 -0
  60. package/app-engine/shaka-player-demo/requirements.txt +5 -0
  61. package/app-engine/shaka-player-demo/time.txt +1 -0
  62. package/build/README.md +3 -3
  63. package/build/checkversion.py +1 -1
  64. package/build/compiler.py +1 -1
  65. package/build/conformance.textproto +13 -0
  66. package/build/docker/Dockerfile +20 -0
  67. package/build/docker/docker-compose.yml +10 -0
  68. package/build/gendeps.py +18 -15
  69. package/build/shaka-lab.yaml +161 -0
  70. package/build/shakaBuildHelpers.py +4 -29
  71. package/build/test.py +94 -29
  72. package/build/types/core +0 -1
  73. package/build/types/polyfill +1 -3
  74. package/build/wrapper.template.js +2 -2
  75. package/demo/TengwarTelcontar.woff2 +0 -0
  76. package/demo/asset_card.js +1 -2
  77. package/demo/cast_receiver/index.html +1 -1
  78. package/demo/cast_receiver/receiver_app.css +14 -14
  79. package/demo/common/asset.js +17 -1
  80. package/demo/common/assets.js +31 -0
  81. package/demo/common/message_ids.js +6 -3
  82. package/demo/config.js +10 -12
  83. package/demo/custom.js +39 -1
  84. package/demo/customWarning.txt +2 -2
  85. package/demo/demo.less +29 -18
  86. package/demo/demo_uncompiled.js +1 -13
  87. package/demo/demo_utils.js +0 -1
  88. package/demo/index.html +1 -1
  89. package/demo/locales/en.json +6 -3
  90. package/demo/locales/source.json +22 -10
  91. package/demo/main.js +12 -9
  92. package/demo/search.js +2 -1
  93. package/dist/controls.css +3 -3
  94. package/dist/controls.css.map +1 -1
  95. package/dist/demo.compiled.debug.js +236 -232
  96. package/dist/demo.compiled.debug.map +4 -4
  97. package/dist/demo.compiled.js +236 -232
  98. package/dist/demo.compiled.map +4 -4
  99. package/dist/demo.css +1 -1
  100. package/dist/demo.css.map +1 -1
  101. package/dist/deps.js +229 -226
  102. package/dist/locales.js +34 -32
  103. package/dist/receiver.compiled.debug.js +75 -73
  104. package/dist/receiver.compiled.debug.map +4 -4
  105. package/dist/receiver.compiled.js +75 -73
  106. package/dist/receiver.compiled.map +4 -4
  107. package/dist/shaka-player.compiled.d.ts +321 -314
  108. package/dist/shaka-player.compiled.debug.d.ts +321 -314
  109. package/dist/shaka-player.compiled.debug.externs.js +140 -129
  110. package/dist/shaka-player.compiled.debug.js +527 -592
  111. package/dist/shaka-player.compiled.debug.map +4 -4
  112. package/dist/shaka-player.compiled.externs.js +140 -129
  113. package/dist/shaka-player.compiled.js +836 -860
  114. package/dist/shaka-player.compiled.map +4 -4
  115. package/dist/shaka-player.ui.d.ts +367 -358
  116. package/dist/shaka-player.ui.debug.d.ts +367 -358
  117. package/dist/shaka-player.ui.debug.externs.js +148 -129
  118. package/dist/shaka-player.ui.debug.js +586 -649
  119. package/dist/shaka-player.ui.debug.map +4 -4
  120. package/dist/shaka-player.ui.externs.js +148 -129
  121. package/dist/shaka-player.ui.js +1008 -1028
  122. package/dist/shaka-player.ui.map +4 -4
  123. package/docs/design/REDESIGN.md +33 -33
  124. package/docs/design/bg-fetch.md +2 -2
  125. package/docs/design/codec_preferences.md +1 -1
  126. package/docs/design/dash-audio-channels.md +3 -3
  127. package/docs/design/dash-manifests.md +1 -1
  128. package/docs/design/gap-jumping.md +3 -3
  129. package/docs/design/preload.md +2 -2
  130. package/docs/tutorials/config.md +0 -2
  131. package/docs/tutorials/drm-config.md +5 -0
  132. package/docs/tutorials/fairplay.md +7 -22
  133. package/docs/tutorials/faq.md +8 -19
  134. package/docs/tutorials/index.json +3 -8
  135. package/docs/tutorials/plugins.md +4 -6
  136. package/docs/tutorials/selenium-grid-config.md +122 -0
  137. package/docs/tutorials/upgrade.md +83 -11
  138. package/docs/tutorials/welcome.md +10 -2
  139. package/externs/cmcd.js +1 -1
  140. package/externs/polyfill.js +15 -0
  141. package/externs/shaka/manifest.js +5 -1
  142. package/externs/shaka/net.js +12 -0
  143. package/externs/shaka/offline.js +5 -1
  144. package/externs/shaka/player.js +39 -32
  145. package/externs/shaka/text.js +12 -12
  146. package/externs/sourcebuffer.js +15 -0
  147. package/karma.conf.js +137 -30
  148. package/lib/abr/simple_abr_manager.js +12 -6
  149. package/lib/ads/client_side_ad.js +13 -2
  150. package/lib/ads/client_side_ad_manager.js +22 -4
  151. package/lib/cast/cast_proxy.js +3 -4
  152. package/lib/cast/cast_utils.js +0 -1
  153. package/lib/cea/cea608_data_channel.js +2 -2
  154. package/lib/cea/cea708_service.js +5 -4
  155. package/lib/cea/mp4_cea_parser.js +11 -5
  156. package/lib/cea/sei_processor.js +6 -3
  157. package/lib/dash/content_protection.js +85 -5
  158. package/lib/dash/dash_parser.js +10 -12
  159. package/lib/dash/mpd_utils.js +4 -5
  160. package/lib/dash/segment_list.js +1 -2
  161. package/lib/dash/segment_template.js +3 -3
  162. package/lib/hls/hls_parser.js +386 -749
  163. package/lib/hls/manifest_text_parser.js +5 -6
  164. package/lib/media/adaptation_set.js +1 -2
  165. package/lib/media/content_workarounds.js +2 -2
  166. package/lib/media/drm_engine.js +105 -55
  167. package/lib/media/gap_jumping_controller.js +10 -45
  168. package/lib/media/media_source_engine.js +90 -17
  169. package/lib/media/mp4_segment_index_parser.js +1 -4
  170. package/lib/media/playhead.js +4 -7
  171. package/lib/media/presentation_timeline.js +19 -10
  172. package/lib/media/segment_index.js +13 -46
  173. package/lib/media/segment_reference.js +47 -1
  174. package/lib/media/streaming_engine.js +35 -17
  175. package/lib/media/time_ranges_utils.js +5 -12
  176. package/lib/media/video_wrapper.js +1 -1
  177. package/lib/net/networking_engine.js +4 -1
  178. package/lib/offline/indexeddb/v1_storage_cell.js +1 -0
  179. package/lib/offline/indexeddb/v2_storage_cell.js +1 -0
  180. package/lib/offline/manifest_converter.js +1 -0
  181. package/lib/offline/storage.js +104 -136
  182. package/lib/player.js +50 -216
  183. package/lib/polyfill/all.js +2 -3
  184. package/lib/polyfill/encryption_scheme.js +1 -1
  185. package/lib/polyfill/media_capabilities.js +15 -9
  186. package/lib/polyfill/mediasource.js +0 -28
  187. package/lib/polyfill/patchedmediakeys_nop.js +2 -0
  188. package/lib/polyfill/patchedmediakeys_webkit.js +2 -0
  189. package/lib/polyfill/symbol.js +46 -0
  190. package/lib/text/cue.js +1 -7
  191. package/lib/text/lrc_text_parser.js +8 -0
  192. package/lib/text/mp4_ttml_parser.js +8 -0
  193. package/lib/text/mp4_vtt_parser.js +8 -0
  194. package/lib/text/sbv_text_parser.js +8 -0
  195. package/lib/text/simple_text_displayer.js +3 -8
  196. package/lib/text/srt_text_parser.js +8 -0
  197. package/lib/text/ssa_text_parser.js +8 -0
  198. package/lib/text/text_engine.js +19 -3
  199. package/lib/text/ttml_text_parser.js +16 -5
  200. package/lib/text/ui_text_displayer.js +2 -8
  201. package/lib/text/vtt_text_parser.js +24 -2
  202. package/lib/text/web_vtt_generator.js +1 -7
  203. package/lib/util/buffer_utils.js +1 -3
  204. package/lib/util/ebml_parser.js +3 -3
  205. package/lib/util/error.js +10 -14
  206. package/lib/util/fairplay_utils.js +109 -0
  207. package/lib/util/functional.js +0 -42
  208. package/lib/util/iterables.js +0 -46
  209. package/lib/util/mime_utils.js +2 -0
  210. package/lib/util/mp4_box_parsers.js +1 -4
  211. package/lib/util/mp4_parser.js +5 -7
  212. package/lib/util/periods.js +10 -11
  213. package/lib/util/platform.js +48 -3
  214. package/lib/util/player_configuration.js +12 -6
  215. package/lib/util/pssh.js +24 -8
  216. package/lib/util/stream_utils.js +96 -25
  217. package/lib/util/string_utils.js +3 -5
  218. package/lib/util/uint8array_utils.js +3 -21
  219. package/lib/util/xml_utils.js +16 -8
  220. package/package.json +61 -36
  221. package/roadmap.md +27 -27
  222. package/shaka-player.uncompiled.js +1 -3
  223. package/test/abr/simple_abr_manager_unit.js +3 -8
  224. package/test/ads/ad_manager_unit.js +0 -6
  225. package/test/cast/cast_proxy_unit.js +0 -8
  226. package/test/cast/cast_receiver_integration.js +1 -18
  227. package/test/cast/cast_receiver_unit.js +1 -9
  228. package/test/cast/cast_sender_unit.js +0 -6
  229. package/test/cast/cast_utils_unit.js +1 -13
  230. package/test/cea/cea608_memory_unit.js +0 -5
  231. package/test/cea/cea708_service_unit.js +0 -7
  232. package/test/cea/cea708_window_unit.js +0 -5
  233. package/test/cea/cea_decoder_unit.js +0 -6
  234. package/test/cea/dtvcc_packet_builder_unit.js +0 -3
  235. package/test/cea/dtvcc_packet_unit.js +0 -5
  236. package/test/cea/mp4_cea_parser_unit.js +0 -4
  237. package/test/dash/dash_parser_content_protection_unit.js +45 -10
  238. package/test/dash/dash_parser_live_unit.js +2 -15
  239. package/test/dash/dash_parser_manifest_unit.js +2 -40
  240. package/test/dash/dash_parser_segment_base_unit.js +1 -8
  241. package/test/dash/dash_parser_segment_list_unit.js +1 -7
  242. package/test/dash/dash_parser_segment_template_unit.js +3 -13
  243. package/test/dash/mpd_utils_unit.js +3 -11
  244. package/test/demo/demo_unit.js +2 -6
  245. package/test/deprecate/enforcer_unit.js +0 -4
  246. package/test/deprecate/version_unit.js +0 -2
  247. package/test/hls/hls_live_unit.js +101 -234
  248. package/test/hls/hls_parser_unit.js +517 -447
  249. package/test/hls/manifest_text_parser_unit.js +0 -10
  250. package/test/media/adaptation_set_criteria_unit.js +3 -7
  251. package/test/media/adaptation_set_unit.js +0 -2
  252. package/test/media/buffering_observer_unit.js +1 -4
  253. package/test/media/closed_caption_parser_unit.js +0 -3
  254. package/test/media/drm_engine_integration.js +2 -15
  255. package/test/media/drm_engine_unit.js +90 -144
  256. package/test/media/manifest_parser_unit.js +0 -4
  257. package/test/media/media_source_engine_integration.js +26 -10
  258. package/test/media/media_source_engine_unit.js +8 -20
  259. package/test/media/mp4_segment_index_parser_unit.js +0 -4
  260. package/test/media/play_rate_controller_unit.js +0 -4
  261. package/test/media/playhead_unit.js +35 -207
  262. package/test/media/presentation_timeline_unit.js +4 -7
  263. package/test/media/quality_observer_unit.js +0 -4
  264. package/test/media/region_observer_unit.js +1 -6
  265. package/test/media/region_timeline_unit.js +0 -3
  266. package/test/media/segment_index_unit.js +15 -31
  267. package/test/media/segment_reference_unit.js +0 -3
  268. package/test/media/stall_detector_unit.js +0 -5
  269. package/test/media/streaming_engine_integration.js +13 -75
  270. package/test/media/streaming_engine_unit.js +14 -37
  271. package/test/media/time_ranges_utils_unit.js +0 -7
  272. package/test/media/transmuxer_integration.js +0 -6
  273. package/test/media/webm_segment_index_parser_unit.js +0 -4
  274. package/test/net/data_uri_plugin_unit.js +0 -7
  275. package/test/net/http_plugin_unit.js +0 -9
  276. package/test/net/networking_engine_unit.js +0 -11
  277. package/test/offline/download_progress_estimator_unit.js +0 -2
  278. package/test/offline/indexeddb_storage_unit.js +0 -6
  279. package/test/offline/manifest_convert_unit.js +34 -12
  280. package/test/offline/offline_integration.js +1 -10
  281. package/test/offline/offline_manifest_parser_unit.js +1 -6
  282. package/test/offline/offline_scheme_unit.js +0 -8
  283. package/test/offline/offline_uri_unit.js +0 -2
  284. package/test/offline/storage_compatibility_unit.js +1 -14
  285. package/test/offline/storage_integration.js +6 -31
  286. package/test/player_external.js +1 -15
  287. package/test/player_integration.js +38 -28
  288. package/test/player_load_graph_integration.js +1 -6
  289. package/test/player_src_equals_external.js +3 -9
  290. package/test/player_src_equals_integration.js +0 -7
  291. package/test/player_unit.js +78 -37
  292. package/test/routing/walker_unit.js +0 -8
  293. package/test/test/assets/large_file.mpd +1 -1
  294. package/test/test/boot.js +75 -22
  295. package/test/test/externs/jasmine.js +2 -2
  296. package/test/test/externs/karma.js +4 -0
  297. package/test/test/namespace.js +10 -0
  298. package/test/test/util/canned_idb.js +0 -8
  299. package/test/test/util/cea_utils.js +0 -6
  300. package/test/test/util/dash_parser_util.js +0 -13
  301. package/test/test/util/fake_ad.js +0 -3
  302. package/test/test/util/fake_ad_manager.js +0 -9
  303. package/test/test/util/fake_demo_main.js +0 -5
  304. package/test/test/util/fake_drm_engine.js +0 -6
  305. package/test/test/util/fake_media_source_engine.js +11 -11
  306. package/test/test/util/fake_networking_engine.js +0 -5
  307. package/test/test/util/fake_text_displayer.js +0 -5
  308. package/test/test/util/indexeddb_utils.js +1 -10
  309. package/test/test/util/jasmine_fetch.js +0 -1
  310. package/test/test/util/loader.js +0 -18
  311. package/test/test/util/manifest_generator.js +12 -15
  312. package/test/test/util/manifest_parser_util.js +4 -7
  313. package/test/test/util/offline_utils.js +1 -5
  314. package/test/test/util/simple_fakes.js +9 -26
  315. package/test/test/util/stream_generator.js +0 -14
  316. package/test/test/util/streaming_engine_util.js +1 -15
  317. package/test/test/util/test_scheme.js +25 -20
  318. package/test/test/util/ttml_utils.js +0 -2
  319. package/test/test/util/ui_utils.js +0 -9
  320. package/test/test/util/util.js +9 -23
  321. package/test/test/util/waiter.js +84 -43
  322. package/test/text/cue_integration.js +2 -6
  323. package/test/text/lrc_text_parser_unit.js +6 -11
  324. package/test/text/mp4_ttml_parser_unit.js +6 -10
  325. package/test/text/mp4_vtt_parser_unit.js +7 -12
  326. package/test/text/sbv_text_parser_unit.js +5 -10
  327. package/test/text/simple_text_displayer_unit.js +1 -8
  328. package/test/text/srt_text_parser_unit.js +5 -10
  329. package/test/text/ssa_text_parser_unit.js +17 -34
  330. package/test/text/text_engine_unit.js +47 -12
  331. package/test/text/text_track_integration.js +0 -2
  332. package/test/text/ttml_text_parser_unit.js +79 -88
  333. package/test/text/ui_text_displayer_unit.js +44 -41
  334. package/test/text/vtt_text_parser_unit.js +55 -66
  335. package/test/text/web_vtt_generator_unit.js +0 -3
  336. package/test/ui/ad_ui_unit.js +0 -11
  337. package/test/ui/localization_unit.js +0 -3
  338. package/test/ui/text_displayer_layout_unit.js +1 -12
  339. package/test/ui/ui_customization_unit.js +0 -6
  340. package/test/ui/ui_integration.js +0 -32
  341. package/test/ui/ui_unit.js +28 -17
  342. package/test/util/abortable_operation_unit.js +4 -9
  343. package/test/util/array_utils_unit.js +0 -2
  344. package/test/util/buffer_utils_unit.js +0 -2
  345. package/test/util/cmcd_manager_unit.js +3 -3
  346. package/test/util/data_view_reader_unit.js +0 -4
  347. package/test/util/ebml_parser_unit.js +0 -4
  348. package/test/util/event_manager_unit.js +0 -3
  349. package/test/util/fake_event_target_unit.js +0 -5
  350. package/test/util/iterables_unit.js +0 -64
  351. package/test/util/language_utils_unit.js +0 -3
  352. package/test/util/manifest_parser_utils_unit.js +0 -2
  353. package/test/util/mp4_box_parsers_unit.js +0 -5
  354. package/test/util/mp4_parser_unit.js +0 -4
  355. package/test/util/multi_map_unit.js +0 -3
  356. package/test/util/object_utils_unit.js +0 -2
  357. package/test/util/periods_unit.js +14 -7
  358. package/test/util/pssh_unit.js +0 -5
  359. package/test/util/state_history_unit.js +0 -2
  360. package/test/util/stream_utils_unit.js +26 -15
  361. package/test/util/string_utils_unit.js +0 -6
  362. package/test/util/text_parser_unit.js +0 -2
  363. package/test/util/xml_utils_unit.js +0 -4
  364. package/ui/controls.js +65 -40
  365. package/ui/fullscreen_button.js +26 -6
  366. package/ui/less/ad_controls.less +6 -6
  367. package/ui/less/buttons.less +6 -6
  368. package/ui/less/containers.less +10 -12
  369. package/ui/less/overflow_menu.less +4 -4
  370. package/ui/less/range_elements.less +7 -2
  371. package/ui/less/tooltip.less +4 -4
  372. package/ui/locales/en.json +1 -0
  373. package/ui/locales/sjn-translations.yaml +257 -0
  374. package/ui/locales/sjn.json +42 -0
  375. package/ui/locales/source.json +5 -0
  376. package/ui/resolution_selection.js +31 -33
  377. package/ui/seek_bar.js +2 -1
  378. package/ui/ui.js +0 -17
  379. package/.github/workflows/build_and_test.yaml +0 -73
  380. package/.github/workflows/release.yaml +0 -53
  381. package/docs/tutorials/upgrade-v2-5.md +0 -441
  382. package/docs/tutorials/upgrade-v3.md +0 -38
  383. package/externs/svgelement.js +0 -18
  384. package/externs/webcrypto.js +0 -18
  385. package/lib/polyfill/mathround.js +0 -49
  386. package/lib/polyfill/patchedmediakeys_apple.js +0 -744
  387. package/lib/polyfill/patchedmediakeys_ms.js +0 -698
  388. package/lib/util/mutex.js +0 -52
  389. package/test/util/functional_unit.js +0 -82
@@ -1,744 +0,0 @@
1
- /*! @license
2
- * Shaka Player
3
- * Copyright 2016 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- goog.provide('shaka.polyfill.PatchedMediaKeysApple');
8
-
9
- goog.require('goog.asserts');
10
- goog.require('shaka.log');
11
- goog.require('shaka.media.DrmEngine');
12
- goog.require('shaka.polyfill');
13
- goog.require('shaka.util.BufferUtils');
14
- goog.require('shaka.util.EventManager');
15
- goog.require('shaka.util.FakeEvent');
16
- goog.require('shaka.util.FakeEventTarget');
17
- goog.require('shaka.util.MediaReadyState');
18
- goog.require('shaka.util.PublicPromise');
19
- goog.require('shaka.util.StringUtils');
20
-
21
-
22
- /**
23
- * @summary A polyfill to implement modern, standardized EME on top of Apple's
24
- * prefixed EME in Safari.
25
- * @export
26
- */
27
- shaka.polyfill.PatchedMediaKeysApple = class {
28
- /**
29
- * Installs the polyfill if needed.
30
- * @export
31
- */
32
- static install() {
33
- if (!window.HTMLVideoElement || !window.WebKitMediaKeys) {
34
- // No HTML5 video or no prefixed EME.
35
- return;
36
- }
37
-
38
- /* Unprefixed EME disabled. See:
39
- https://github.com/google/shaka-player/pull/3021#issuecomment-766999811
40
-
41
- // Only tested in Safari 14.
42
- const safariVersion = shaka.util.Platform.safariVersion();
43
- if (navigator.requestMediaKeySystemAccess &&
44
- // eslint-disable-next-line no-restricted-syntax
45
- MediaKeySystemAccess.prototype.getConfiguration &&
46
- safariVersion && safariVersion >= 14) {
47
- // Unprefixed EME is preferable.
48
- return;
49
- }
50
- */
51
-
52
- shaka.log.info('Using Apple-prefixed EME');
53
-
54
- // Alias
55
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
56
-
57
- // Delete mediaKeys to work around strict mode compatibility issues.
58
- // eslint-disable-next-line no-restricted-syntax
59
- delete HTMLMediaElement.prototype['mediaKeys'];
60
- // Work around read-only declaration for mediaKeys by using a string.
61
- // eslint-disable-next-line no-restricted-syntax
62
- HTMLMediaElement.prototype['mediaKeys'] = null;
63
- // eslint-disable-next-line no-restricted-syntax
64
- HTMLMediaElement.prototype.setMediaKeys =
65
- PatchedMediaKeysApple.setMediaKeys;
66
-
67
- // Install patches
68
- window.MediaKeys = PatchedMediaKeysApple.MediaKeys;
69
- window.MediaKeySystemAccess = PatchedMediaKeysApple.MediaKeySystemAccess;
70
- navigator.requestMediaKeySystemAccess =
71
- PatchedMediaKeysApple.requestMediaKeySystemAccess;
72
- }
73
-
74
- /**
75
- * An implementation of navigator.requestMediaKeySystemAccess.
76
- * Retrieves a MediaKeySystemAccess object.
77
- *
78
- * @this {!Navigator}
79
- * @param {string} keySystem
80
- * @param {!Array.<!MediaKeySystemConfiguration>} supportedConfigurations
81
- * @return {!Promise.<!MediaKeySystemAccess>}
82
- */
83
- static requestMediaKeySystemAccess(keySystem, supportedConfigurations) {
84
- shaka.log.debug('PatchedMediaKeysApple.requestMediaKeySystemAccess');
85
- goog.asserts.assert(this == navigator,
86
- 'bad "this" for requestMediaKeySystemAccess');
87
-
88
- // Alias.
89
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
90
- try {
91
- const access = new PatchedMediaKeysApple.MediaKeySystemAccess(
92
- keySystem, supportedConfigurations);
93
- return Promise.resolve(/** @type {!MediaKeySystemAccess} */ (access));
94
- } catch (exception) {
95
- return Promise.reject(exception);
96
- }
97
- }
98
-
99
- /**
100
- * An implementation of HTMLMediaElement.prototype.setMediaKeys.
101
- * Attaches a MediaKeys object to the media element.
102
- *
103
- * @this {!HTMLMediaElement}
104
- * @param {MediaKeys} mediaKeys
105
- * @return {!Promise}
106
- */
107
- static setMediaKeys(mediaKeys) {
108
- shaka.log.debug('PatchedMediaKeysApple.setMediaKeys');
109
- goog.asserts.assert(this instanceof HTMLMediaElement,
110
- 'bad "this" for setMediaKeys');
111
-
112
- // Alias
113
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
114
-
115
- const newMediaKeys =
116
- /** @type {shaka.polyfill.PatchedMediaKeysApple.MediaKeys} */ (
117
- mediaKeys);
118
- const oldMediaKeys =
119
- /** @type {shaka.polyfill.PatchedMediaKeysApple.MediaKeys} */ (
120
- this.mediaKeys);
121
-
122
- if (oldMediaKeys && oldMediaKeys != newMediaKeys) {
123
- goog.asserts.assert(
124
- oldMediaKeys instanceof PatchedMediaKeysApple.MediaKeys,
125
- 'non-polyfill instance of oldMediaKeys');
126
- // Have the old MediaKeys stop listening to events on the video tag.
127
- oldMediaKeys.setMedia(null);
128
- }
129
-
130
- delete this['mediaKeys']; // in case there is an existing getter
131
- this['mediaKeys'] = mediaKeys; // work around read-only declaration
132
-
133
- if (newMediaKeys) {
134
- goog.asserts.assert(
135
- newMediaKeys instanceof PatchedMediaKeysApple.MediaKeys,
136
- 'non-polyfill instance of newMediaKeys');
137
- return newMediaKeys.setMedia(this);
138
- }
139
-
140
- return Promise.resolve();
141
- }
142
-
143
- /**
144
- * Handler for the native media elements webkitneedkey event.
145
- *
146
- * @this {!HTMLMediaElement}
147
- * @param {!MediaKeyEvent} event
148
- * @suppress {constantProperty} We reassign what would be const on a real
149
- * MediaEncryptedEvent, but in our look-alike event.
150
- * @private
151
- */
152
- static onWebkitNeedKey_(event) {
153
- shaka.log.debug('PatchedMediaKeysApple.onWebkitNeedKey_', event);
154
-
155
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
156
- const mediaKeys =
157
- /** @type {shaka.polyfill.PatchedMediaKeysApple.MediaKeys} */(
158
- this.mediaKeys);
159
- goog.asserts.assert(mediaKeys instanceof PatchedMediaKeysApple.MediaKeys,
160
- 'non-polyfill instance of newMediaKeys');
161
-
162
- goog.asserts.assert(event.initData != null, 'missing init data!');
163
-
164
- // Convert the prefixed init data to match the native 'encrypted' event.
165
- const uint8 = shaka.util.BufferUtils.toUint8(event.initData);
166
- const dataview = shaka.util.BufferUtils.toDataView(uint8);
167
- // The first part is a 4 byte little-endian int, which is the length of
168
- // the second part.
169
- const length = dataview.getUint32(
170
- /* position= */ 0, /* littleEndian= */ true);
171
- if (length + 4 != uint8.byteLength) {
172
- throw new RangeError('Malformed FairPlay init data');
173
- }
174
- // The remainder is a UTF-16 skd URL. Convert this to UTF-8 and pass on.
175
- const str = shaka.util.StringUtils.fromUTF16(
176
- uint8.subarray(4), /* littleEndian= */ true);
177
- const initData = shaka.util.StringUtils.toUTF8(str);
178
-
179
- // NOTE: Because "this" is a real EventTarget, the event we dispatch here
180
- // must also be a real Event.
181
- const event2 = new Event('encrypted');
182
-
183
- const encryptedEvent =
184
- /** @type {!MediaEncryptedEvent} */(/** @type {?} */(event2));
185
- encryptedEvent.initDataType = 'skd';
186
- encryptedEvent.initData = shaka.util.BufferUtils.toArrayBuffer(initData);
187
-
188
- this.dispatchEvent(event2);
189
- }
190
- };
191
-
192
-
193
- /**
194
- * An implementation of MediaKeySystemAccess.
195
- *
196
- * @implements {MediaKeySystemAccess}
197
- */
198
- shaka.polyfill.PatchedMediaKeysApple.MediaKeySystemAccess = class {
199
- /**
200
- * @param {string} keySystem
201
- * @param {!Array.<!MediaKeySystemConfiguration>} supportedConfigurations
202
- */
203
- constructor(keySystem, supportedConfigurations) {
204
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySystemAccess');
205
-
206
- /** @type {string} */
207
- this.keySystem = keySystem;
208
-
209
- /** @private {!MediaKeySystemConfiguration} */
210
- this.configuration_;
211
-
212
- // Optimization: WebKitMediaKeys.isTypeSupported delays responses by a
213
- // significant amount of time, possibly to discourage fingerprinting.
214
- // Since we know only FairPlay is supported here, let's skip queries for
215
- // anything else to speed up the process.
216
- if (keySystem.startsWith('com.apple.fps')) {
217
- for (const cfg of supportedConfigurations) {
218
- const newCfg = this.checkConfig_(cfg);
219
- if (newCfg) {
220
- this.configuration_ = newCfg;
221
- return;
222
- }
223
- }
224
- }
225
-
226
- // According to the spec, this should be a DOMException, but there is not a
227
- // public constructor for that. So we make this look-alike instead.
228
- const unsupportedKeySystemError = new Error('Unsupported keySystem');
229
- unsupportedKeySystemError.name = 'NotSupportedError';
230
- unsupportedKeySystemError['code'] = DOMException.NOT_SUPPORTED_ERR;
231
- throw unsupportedKeySystemError;
232
- }
233
-
234
- /**
235
- * Check a single config for MediaKeySystemAccess.
236
- *
237
- * @param {MediaKeySystemConfiguration} cfg The requested config.
238
- * @return {?MediaKeySystemConfiguration} A matching config we can support, or
239
- * null if the input is not supportable.
240
- * @private
241
- */
242
- checkConfig_(cfg) {
243
- if (cfg.persistentState == 'required') {
244
- // Not supported by the prefixed API.
245
- return null;
246
- }
247
-
248
- // Create a new config object and start adding in the pieces which we find
249
- // support for. We will return this from getConfiguration() later if
250
- // asked.
251
-
252
- /** @type {!MediaKeySystemConfiguration} */
253
- const newCfg = {
254
- 'audioCapabilities': [],
255
- 'videoCapabilities': [],
256
- // It is technically against spec to return these as optional, but we
257
- // don't truly know their values from the prefixed API:
258
- 'persistentState': 'optional',
259
- 'distinctiveIdentifier': 'optional',
260
- // Pretend the requested init data types are supported, since we don't
261
- // really know that either:
262
- 'initDataTypes': cfg.initDataTypes,
263
- 'sessionTypes': ['temporary'],
264
- 'label': cfg.label,
265
- };
266
-
267
- // PatchedMediaKeysApple tests for key system availability through
268
- // WebKitMediaKeys.isTypeSupported.
269
- let ranAnyTests = false;
270
- let success = false;
271
-
272
- if (cfg.audioCapabilities) {
273
- for (const cap of cfg.audioCapabilities) {
274
- if (cap.contentType) {
275
- ranAnyTests = true;
276
-
277
- const contentType = cap.contentType.split(';')[0];
278
- if (WebKitMediaKeys.isTypeSupported(this.keySystem, contentType)) {
279
- newCfg.audioCapabilities.push(cap);
280
- success = true;
281
- }
282
- }
283
- }
284
- }
285
-
286
- if (cfg.videoCapabilities) {
287
- for (const cap of cfg.videoCapabilities) {
288
- if (cap.contentType) {
289
- ranAnyTests = true;
290
-
291
- const contentType = cap.contentType.split(';')[0];
292
- if (WebKitMediaKeys.isTypeSupported(this.keySystem, contentType)) {
293
- newCfg.videoCapabilities.push(cap);
294
- success = true;
295
- }
296
- }
297
- }
298
- }
299
-
300
- if (!ranAnyTests) {
301
- // If no specific types were requested, we check all common types to
302
- // find out if the key system is present at all.
303
- success = WebKitMediaKeys.isTypeSupported(this.keySystem, 'video/mp4');
304
- }
305
-
306
- if (success) {
307
- return newCfg;
308
- }
309
- return null;
310
- }
311
-
312
- /** @override */
313
- createMediaKeys() {
314
- shaka.log.debug(
315
- 'PatchedMediaKeysApple.MediaKeySystemAccess.createMediaKeys');
316
-
317
- // Alias
318
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
319
-
320
- const mediaKeys = new PatchedMediaKeysApple.MediaKeys(this.keySystem);
321
- return Promise.resolve(/** @type {!MediaKeys} */ (mediaKeys));
322
- }
323
-
324
- /** @override */
325
- getConfiguration() {
326
- shaka.log.debug(
327
- 'PatchedMediaKeysApple.MediaKeySystemAccess.getConfiguration');
328
- return this.configuration_;
329
- }
330
- };
331
-
332
-
333
- /**
334
- * An implementation of MediaKeys.
335
- *
336
- * @implements {MediaKeys}
337
- */
338
- shaka.polyfill.PatchedMediaKeysApple.MediaKeys = class {
339
- /** @param {string} keySystem */
340
- constructor(keySystem) {
341
- shaka.log.debug('PatchedMediaKeysApple.MediaKeys');
342
-
343
- /** @private {!WebKitMediaKeys} */
344
- this.nativeMediaKeys_ = new WebKitMediaKeys(keySystem);
345
-
346
- /** @private {!shaka.util.EventManager} */
347
- this.eventManager_ = new shaka.util.EventManager();
348
- }
349
-
350
- /** @override */
351
- createSession(sessionType) {
352
- shaka.log.debug('PatchedMediaKeysApple.MediaKeys.createSession');
353
-
354
- sessionType = sessionType || 'temporary';
355
- // For now, only the 'temporary' type is supported.
356
- if (sessionType != 'temporary') {
357
- throw new TypeError('Session type ' + sessionType +
358
- ' is unsupported on this platform.');
359
- }
360
-
361
- // Alias
362
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
363
-
364
- return new PatchedMediaKeysApple.MediaKeySession(
365
- this.nativeMediaKeys_, sessionType);
366
- }
367
-
368
- /** @override */
369
- setServerCertificate(serverCertificate) {
370
- shaka.log.debug('PatchedMediaKeysApple.MediaKeys.setServerCertificate');
371
- return Promise.resolve(false);
372
- }
373
-
374
- /**
375
- * @param {HTMLMediaElement} media
376
- * @protected
377
- * @return {!Promise}
378
- */
379
- setMedia(media) {
380
- // Alias
381
- const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple;
382
-
383
- // Remove any old listeners.
384
- this.eventManager_.removeAll();
385
-
386
- // It is valid for media to be null; null is used to flag that event
387
- // handlers need to be cleaned up.
388
- if (!media) {
389
- return Promise.resolve();
390
- }
391
-
392
- // Intercept and translate these prefixed EME events.
393
- this.eventManager_.listen(media, 'webkitneedkey',
394
- /** @type {shaka.util.EventManager.ListenerType} */
395
- (PatchedMediaKeysApple.onWebkitNeedKey_));
396
-
397
- // Wrap native HTMLMediaElement.webkitSetMediaKeys with a Promise.
398
- try {
399
- // Some browsers require that readyState >=1 before mediaKeys can be
400
- // set, so check this and wait for loadedmetadata if we are not in the
401
- // correct state
402
- shaka.util.MediaReadyState.waitForReadyState(media,
403
- HTMLMediaElement.HAVE_METADATA,
404
- this.eventManager_, () => {
405
- media.webkitSetMediaKeys(this.nativeMediaKeys_);
406
- });
407
-
408
- return Promise.resolve();
409
- } catch (exception) {
410
- return Promise.reject(exception);
411
- }
412
- }
413
- };
414
-
415
-
416
- /**
417
- * An implementation of MediaKeySession.
418
- *
419
- * @implements {MediaKeySession}
420
- */
421
- shaka.polyfill.PatchedMediaKeysApple.MediaKeySession =
422
- class extends shaka.util.FakeEventTarget {
423
- /**
424
- * @param {WebKitMediaKeys} nativeMediaKeys
425
- * @param {string} sessionType
426
- */
427
- constructor(nativeMediaKeys, sessionType) {
428
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySession');
429
- super();
430
-
431
- /**
432
- * The native MediaKeySession, which will be created in generateRequest.
433
- * @private {WebKitMediaKeySession}
434
- */
435
- this.nativeMediaKeySession_ = null;
436
-
437
- /** @private {WebKitMediaKeys} */
438
- this.nativeMediaKeys_ = nativeMediaKeys;
439
-
440
- // Promises that are resolved later
441
- /** @private {shaka.util.PublicPromise} */
442
- this.generateRequestPromise_ = null;
443
-
444
- /** @private {shaka.util.PublicPromise} */
445
- this.updatePromise_ = null;
446
-
447
- /** @private {!shaka.util.EventManager} */
448
- this.eventManager_ = new shaka.util.EventManager();
449
-
450
- /** @type {string} */
451
- this.sessionId = '';
452
-
453
- /** @type {number} */
454
- this.expiration = NaN;
455
-
456
- /** @type {!shaka.util.PublicPromise} */
457
- this.closed = new shaka.util.PublicPromise();
458
-
459
- /** @type {!shaka.polyfill.PatchedMediaKeysApple.MediaKeyStatusMap} */
460
- this.keyStatuses =
461
- new shaka.polyfill.PatchedMediaKeysApple.MediaKeyStatusMap();
462
- }
463
-
464
- /** @override */
465
- generateRequest(initDataType, initData) {
466
- shaka.log.debug(
467
- 'PatchedMediaKeysApple.MediaKeySession.generateRequest');
468
-
469
- this.generateRequestPromise_ = new shaka.util.PublicPromise();
470
-
471
- try {
472
- // This EME spec version requires a MIME content type as the 1st param to
473
- // createSession, but doesn't seem to matter what the value is.
474
- // It also only accepts Uint8Array, not ArrayBuffer, so explicitly make
475
- // initData into a Uint8Array.
476
- const session = this.nativeMediaKeys_.createSession(
477
- 'video/mp4', shaka.util.BufferUtils.toUint8(initData));
478
- this.nativeMediaKeySession_ = session;
479
- this.sessionId = session.sessionId || '';
480
-
481
- // Attach session event handlers here.
482
- this.eventManager_.listen(
483
- this.nativeMediaKeySession_, 'webkitkeymessage',
484
- /** @type {shaka.util.EventManager.ListenerType} */
485
- ((event) => this.onWebkitKeyMessage_(event)));
486
- this.eventManager_.listen(session, 'webkitkeyadded',
487
- /** @type {shaka.util.EventManager.ListenerType} */
488
- ((event) => this.onWebkitKeyAdded_(event)));
489
- this.eventManager_.listen(session, 'webkitkeyerror',
490
- /** @type {shaka.util.EventManager.ListenerType} */
491
- ((event) => this.onWebkitKeyError_(event)));
492
-
493
- this.updateKeyStatus_('status-pending');
494
- } catch (exception) {
495
- this.generateRequestPromise_.reject(exception);
496
- }
497
-
498
- return this.generateRequestPromise_;
499
- }
500
-
501
- /** @override */
502
- load() {
503
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySession.load');
504
-
505
- return Promise.reject(new Error('MediaKeySession.load not yet supported'));
506
- }
507
-
508
- /** @override */
509
- update(response) {
510
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySession.update');
511
-
512
- this.updatePromise_ = new shaka.util.PublicPromise();
513
-
514
- try {
515
- // Pass through to the native session.
516
- this.nativeMediaKeySession_.update(
517
- shaka.util.BufferUtils.toUint8(response));
518
- } catch (exception) {
519
- this.updatePromise_.reject(exception);
520
- }
521
-
522
- return this.updatePromise_;
523
- }
524
-
525
- /** @override */
526
- close() {
527
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySession.close');
528
-
529
- try {
530
- // Pass through to the native session.
531
- this.nativeMediaKeySession_.close();
532
-
533
- this.closed.resolve();
534
- this.eventManager_.removeAll();
535
- } catch (exception) {
536
- this.closed.reject(exception);
537
- }
538
-
539
- return this.closed;
540
- }
541
-
542
- /** @override */
543
- remove() {
544
- shaka.log.debug('PatchedMediaKeysApple.MediaKeySession.remove');
545
-
546
- return Promise.reject(new Error(
547
- 'MediaKeySession.remove is only applicable for persistent licenses, ' +
548
- 'which are not supported on this platform'));
549
- }
550
-
551
- /**
552
- * Handler for the native keymessage event on WebKitMediaKeySession.
553
- *
554
- * @param {!MediaKeyEvent} event
555
- * @private
556
- */
557
- onWebkitKeyMessage_(event) {
558
- shaka.log.debug('PatchedMediaKeysApple.onWebkitKeyMessage_', event);
559
-
560
- // We can now resolve this.generateRequestPromise, which should be non-null.
561
- goog.asserts.assert(this.generateRequestPromise_,
562
- 'generateRequestPromise_ should be set before now!');
563
- if (this.generateRequestPromise_) {
564
- this.generateRequestPromise_.resolve();
565
- this.generateRequestPromise_ = null;
566
- }
567
-
568
- const isNew = this.keyStatuses.getStatus() == undefined;
569
-
570
- const data = new Map()
571
- .set('messageType', isNew ? 'license-request' : 'license-renewal')
572
- .set('message', shaka.util.BufferUtils.toArrayBuffer(event.message));
573
- const event2 = new shaka.util.FakeEvent('message', data);
574
-
575
- this.dispatchEvent(event2);
576
- }
577
-
578
- /**
579
- * Handler for the native keyadded event on WebKitMediaKeySession.
580
- *
581
- * @param {!MediaKeyEvent} event
582
- * @private
583
- */
584
- onWebkitKeyAdded_(event) {
585
- shaka.log.debug('PatchedMediaKeysApple.onWebkitKeyAdded_', event);
586
-
587
- // This shouldn't fire while we're in the middle of generateRequest,
588
- // but if it does, we will need to change the logic to account for it.
589
- goog.asserts.assert(!this.generateRequestPromise_,
590
- 'Key added during generate!');
591
-
592
- // We can now resolve this.updatePromise, which should be non-null.
593
- goog.asserts.assert(this.updatePromise_,
594
- 'updatePromise_ should be set before now!');
595
- if (this.updatePromise_) {
596
- this.updateKeyStatus_('usable');
597
- this.updatePromise_.resolve();
598
- this.updatePromise_ = null;
599
- }
600
- }
601
-
602
- /**
603
- * Handler for the native keyerror event on WebKitMediaKeySession.
604
- *
605
- * @param {!MediaKeyEvent} event
606
- * @private
607
- */
608
- onWebkitKeyError_(event) {
609
- shaka.log.debug('PatchedMediaKeysApple.onWebkitKeyError_', event);
610
-
611
- const error = new Error('EME PatchedMediaKeysApple key error');
612
- error['errorCode'] = this.nativeMediaKeySession_.error;
613
-
614
- if (this.generateRequestPromise_ != null) {
615
- this.generateRequestPromise_.reject(error);
616
- this.generateRequestPromise_ = null;
617
- } else if (this.updatePromise_ != null) {
618
- this.updatePromise_.reject(error);
619
- this.updatePromise_ = null;
620
- } else {
621
- // Unexpected error - map native codes to standardised key statuses.
622
- // Possible values of this.nativeMediaKeySession_.error.code:
623
- // MEDIA_KEYERR_UNKNOWN = 1
624
- // MEDIA_KEYERR_CLIENT = 2
625
- // MEDIA_KEYERR_SERVICE = 3
626
- // MEDIA_KEYERR_OUTPUT = 4
627
- // MEDIA_KEYERR_HARDWARECHANGE = 5
628
- // MEDIA_KEYERR_DOMAIN = 6
629
-
630
- switch (this.nativeMediaKeySession_.error.code) {
631
- case WebKitMediaKeyError.MEDIA_KEYERR_OUTPUT:
632
- case WebKitMediaKeyError.MEDIA_KEYERR_HARDWARECHANGE:
633
- this.updateKeyStatus_('output-not-allowed');
634
- break;
635
- default:
636
- this.updateKeyStatus_('internal-error');
637
- break;
638
- }
639
- }
640
- }
641
-
642
- /**
643
- * Updates key status and dispatch a 'keystatuseschange' event.
644
- *
645
- * @param {string} status
646
- * @private
647
- */
648
- updateKeyStatus_(status) {
649
- this.keyStatuses.setStatus(status);
650
- const event = new shaka.util.FakeEvent('keystatuseschange');
651
- this.dispatchEvent(event);
652
- }
653
- };
654
-
655
-
656
- /**
657
- * @summary An implementation of MediaKeyStatusMap.
658
- * This fakes a map with a single key ID.
659
- *
660
- * @todo Consolidate the MediaKeyStatusMap types in these polyfills.
661
- * @implements {MediaKeyStatusMap}
662
- */
663
- shaka.polyfill.PatchedMediaKeysApple.MediaKeyStatusMap = class {
664
- /** */
665
- constructor() {
666
- /**
667
- * @type {number}
668
- */
669
- this.size = 0;
670
-
671
- /**
672
- * @private {string|undefined}
673
- */
674
- this.status_ = undefined;
675
- }
676
-
677
- /**
678
- * An internal method used by the session to set key status.
679
- * @param {string|undefined} status
680
- */
681
- setStatus(status) {
682
- this.size = status == undefined ? 0 : 1;
683
- this.status_ = status;
684
- }
685
-
686
- /**
687
- * An internal method used by the session to get key status.
688
- * @return {string|undefined}
689
- */
690
- getStatus() {
691
- return this.status_;
692
- }
693
-
694
- /** @override */
695
- forEach(fn) {
696
- if (this.status_) {
697
- fn(this.status_, shaka.media.DrmEngine.DUMMY_KEY_ID.value());
698
- }
699
- }
700
-
701
- /** @override */
702
- get(keyId) {
703
- if (this.has(keyId)) {
704
- return this.status_;
705
- }
706
- return undefined;
707
- }
708
-
709
- /** @override */
710
- has(keyId) {
711
- const fakeKeyId = shaka.media.DrmEngine.DUMMY_KEY_ID.value();
712
- if (this.status_ && shaka.util.BufferUtils.equal(keyId, fakeKeyId)) {
713
- return true;
714
- }
715
- return false;
716
- }
717
-
718
- /**
719
- * @suppress {missingReturn}
720
- * @override
721
- */
722
- entries() {
723
- goog.asserts.assert(false, 'Not used! Provided only for the compiler.');
724
- }
725
-
726
- /**
727
- * @suppress {missingReturn}
728
- * @override
729
- */
730
- keys() {
731
- goog.asserts.assert(false, 'Not used! Provided only for the compiler.');
732
- }
733
-
734
- /**
735
- * @suppress {missingReturn}
736
- * @override
737
- */
738
- values() {
739
- goog.asserts.assert(false, 'Not used! Provided only for the compiler.');
740
- }
741
- };
742
-
743
-
744
- shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysApple.install);