Source: lib/dependencies/all.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.dependencies');
  7. goog.require('shaka.Deprecate');
  8. /**
  9. * @export
  10. */
  11. shaka.dependencies = class {
  12. /**
  13. * Registers a new dependency.
  14. *
  15. * @param {shaka.dependencies.Allowed} key which is used for retrieving a
  16. * dependency
  17. * @param {?} dep a dependency
  18. * @export
  19. */
  20. static add(key, dep) {
  21. if (!shaka.dependencies.Allowed[key]) {
  22. throw new Error(`${key} is not supported`);
  23. }
  24. if (key == shaka.dependencies.Allowed.muxjs) {
  25. shaka.Deprecate.deprecateFeature(5,
  26. 'mux.js',
  27. 'mux.js is no longer used in Shaka Player.');
  28. return;
  29. }
  30. shaka.dependencies.dependencies_.set(key, () => dep);
  31. }
  32. /**
  33. * Check if we have a dependency for the key.
  34. *
  35. * @param {shaka.dependencies.Allowed} key key
  36. * @return {boolean}
  37. * @export
  38. */
  39. static has(key) {
  40. return shaka.dependencies.dependencies_.has(key);
  41. }
  42. /** @return {?ISOBoxer} */
  43. static isoBoxer() {
  44. return /** @type {?ISOBoxer} */ (shaka.dependencies.dependencies_.get(
  45. shaka.dependencies.Allowed.ISOBoxer)());
  46. }
  47. };
  48. /**
  49. * @export
  50. * @enum {string}
  51. */
  52. shaka.dependencies.Allowed = {
  53. muxjs: 'muxjs',
  54. ISOBoxer: 'ISOBoxer',
  55. };
  56. // eslint-disable-next-line jsdoc/require-returns
  57. /**
  58. * Contains accessor functions to shared dependencies that could be used by
  59. * other components. The default accessors can be overridden.
  60. *
  61. * @private {!Map<shaka.dependencies.Allowed, function(): ?>}
  62. */
  63. shaka.dependencies.dependencies_ = new Map([
  64. [shaka.dependencies.Allowed.ISOBoxer, () => window.ISOBoxer],
  65. ]);