Source: ui/element.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ui.Element');
  7. goog.require('shaka.ads.Utils');
  8. goog.require('shaka.util.EventManager');
  9. goog.requireType('shaka.Player');
  10. goog.requireType('shaka.ui.Controls');
  11. goog.requireType('shaka.ui.Localization');
  12. /**
  13. * @implements {shaka.extern.IUIElement}
  14. * @abstract
  15. * @export
  16. */
  17. shaka.ui.Element = class {
  18. /**
  19. * @param {!HTMLElement} parent
  20. * @param {!shaka.ui.Controls} controls
  21. */
  22. constructor(parent, controls) {
  23. /**
  24. * @protected {HTMLElement}
  25. * @exportInterface
  26. */
  27. this.parent = parent;
  28. /**
  29. * @protected {shaka.ui.Controls}
  30. * @exportInterface
  31. */
  32. this.controls = controls;
  33. /**
  34. * @protected {shaka.util.EventManager}
  35. * @exportInterface
  36. */
  37. this.eventManager = new shaka.util.EventManager();
  38. /**
  39. * @protected {shaka.ui.Localization}
  40. * @exportInterface
  41. */
  42. this.localization = this.controls.getLocalization();
  43. /**
  44. * @protected {shaka.Player}
  45. * @exportInterface
  46. */
  47. this.player = this.controls.getPlayer();
  48. /**
  49. * @protected {HTMLMediaElement}
  50. * @exportInterface
  51. */
  52. this.video = this.controls.getVideo();
  53. /**
  54. * @protected {shaka.extern.IAdManager}
  55. * @exportInterface
  56. */
  57. this.adManager = this.player.getAdManager();
  58. /**
  59. * @protected {?shaka.extern.IAd}
  60. * @exportInterface
  61. */
  62. this.ad = controls.getAd();
  63. const AD_STARTED = shaka.ads.Utils.AD_STARTED;
  64. this.eventManager.listen(this.adManager, AD_STARTED, (e) => {
  65. this.ad = (/** @type {!Object} */ (e))['ad'];
  66. });
  67. const AD_STOPPED = shaka.ads.Utils.AD_STOPPED;
  68. this.eventManager.listen(this.adManager, AD_STOPPED, () => {
  69. this.ad = null;
  70. });
  71. }
  72. /**
  73. * @override
  74. * @export
  75. */
  76. release() {
  77. this.eventManager.release();
  78. this.parent = null;
  79. this.controls = null;
  80. this.eventManager = null;
  81. this.localization = null;
  82. this.player = null;
  83. this.video = null;
  84. this.adManager = null;
  85. this.ad = null;
  86. }
  87. };