1. 1 : import {VideoTrackKind} from './track-enums';
  2. 2 : import Track from './track';
  3. 3 : import merge from '../utils/merge-options';
  4. 4 :
  5. 5 : /**
  6. 6 : * A representation of a single `VideoTrack`.
  7. 7 : *
  8. 8 : * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack}
  9. 9 : * @extends Track
  10. 10 : */
  11. 11 : class VideoTrack extends Track {
  12. 12 :
  13. 13 : /**
  14. 14 : * Create an instance of this class.
  15. 15 : *
  16. 16 : * @param {Object} [options={}]
  17. 17 : * Object of option names and values
  18. 18 : *
  19. 19 : * @param {string} [options.kind='']
  20. 20 : * A valid {@link VideoTrack~Kind}
  21. 21 : *
  22. 22 : * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  23. 23 : * A unique id for this AudioTrack.
  24. 24 : *
  25. 25 : * @param {string} [options.label='']
  26. 26 : * The menu label for this track.
  27. 27 : *
  28. 28 : * @param {string} [options.language='']
  29. 29 : * A valid two character language code.
  30. 30 : *
  31. 31 : * @param {boolean} [options.selected]
  32. 32 : * If this track is the one that is currently playing.
  33. 33 : */
  34. 34 : constructor(options = {}) {
  35. 35 : const settings = merge(options, {
  36. 36 : kind: VideoTrackKind[options.kind] || ''
  37. 37 : });
  38. 38 :
  39. 39 : super(settings);
  40. 40 :
  41. 41 : let selected = false;
  42. 42 :
  43. 43 : /**
  44. 44 : * @memberof VideoTrack
  45. 45 : * @member {boolean} selected
  46. 46 : * If this `VideoTrack` is selected or not. When setting this will
  47. 47 : * fire {@link VideoTrack#selectedchange} if the state of selected changed.
  48. 48 : * @instance
  49. 49 : *
  50. 50 : * @fires VideoTrack#selectedchange
  51. 51 : */
  52. 52 : Object.defineProperty(this, 'selected', {
  53. 53 : get() {
  54. 54 : return selected;
  55. 55 : },
  56. 56 : set(newSelected) {
  57. 57 : // an invalid or unchanged value
  58. 58 : if (typeof newSelected !== 'boolean' || newSelected === selected) {
  59. 59 : return;
  60. 60 : }
  61. 61 : selected = newSelected;
  62. 62 :
  63. 63 : /**
  64. 64 : * An event that fires when selected changes on this track. This allows
  65. 65 : * the VideoTrackList that holds this track to act accordingly.
  66. 66 : *
  67. 67 : * > Note: This is not part of the spec! Native tracks will do
  68. 68 : * this internally without an event.
  69. 69 : *
  70. 70 : * @event VideoTrack#selectedchange
  71. 71 : * @type {EventTarget~Event}
  72. 72 : */
  73. 73 : this.trigger('selectedchange');
  74. 74 : }
  75. 75 : });
  76. 76 :
  77. 77 : // if the user sets this track to selected then
  78. 78 : // set selected to that true value otherwise
  79. 79 : // we keep it false
  80. 80 : if (settings.selected) {
  81. 81 : this.selected = settings.selected;
  82. 82 : }
  83. 83 : }
  84. 84 : }
  85. 85 :
  86. 86 : export default VideoTrack;