3 exports.__esModule = true;
5 var _trackList = require('./track-list');
7 var _trackList2 = _interopRequireDefault(_trackList);
9 var _browser = require('../utils/browser.js');
11 var browser = _interopRequireWildcard(_browser);
13 var _document = require('global/document');
15 var _document2 = _interopRequireDefault(_document);
17 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
26 * @file video-track-list.js
31 * Un-select all other {@link VideoTrack}s that are selected.
33 * @param {VideoTrackList} list
36 * @param {VideoTrack} track
41 var disableOthers = function disableOthers(list, track) {
42 for (var i = 0; i < list.length; i++) {
43 if (track.id === list[i].id) {
46 // another video track is enabled, disable it
47 list[i].selected = false;
52 * The current list of {@link VideoTrack} for a video.
54 * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist}
58 var VideoTrackList = function (_TrackList) {
59 _inherits(VideoTrackList, _TrackList);
62 * Create an instance of this class.
64 * @param {VideoTrack[]} [tracks=[]]
65 * A list of `VideoTrack` to instantiate the list with.
67 function VideoTrackList() {
70 var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
72 _classCallCheck(this, VideoTrackList);
76 // make sure only 1 track is enabled
77 // sorted from last index to first index
78 for (var i = tracks.length - 1; i >= 0; i--) {
79 if (tracks[i].selected) {
80 disableOthers(tracks, tracks[i]);
85 // IE8 forces us to implement inheritance ourselves
86 // as it does not support Object.defineProperty properly
88 list = _document2['default'].createElement('custom');
89 for (var prop in _trackList2['default'].prototype) {
90 if (prop !== 'constructor') {
91 list[prop] = _trackList2['default'].prototype[prop];
94 for (var _prop in VideoTrackList.prototype) {
95 if (_prop !== 'constructor') {
96 list[_prop] = VideoTrackList.prototype[_prop];
101 list = (_this = _possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
102 list.changing_ = false;
105 * @member {number} VideoTrackList#selectedIndex
106 * The current index of the selected {@link VideoTrack`}.
108 Object.defineProperty(list, 'selectedIndex', {
109 get: function get() {
110 for (var _i = 0; _i < this.length; _i++) {
111 if (this[_i].selected) {
117 set: function set() {}
120 return _ret = list, _possibleConstructorReturn(_this, _ret);
124 * Add a {@link VideoTrack} to the `VideoTrackList`.
126 * @param {VideoTrack} track
127 * The VideoTrack to add to the list
129 * @fires TrackList#addtrack
134 VideoTrackList.prototype.addTrack_ = function addTrack_(track) {
137 if (track.selected) {
138 disableOthers(this, track);
141 _TrackList.prototype.addTrack_.call(this, track);
142 // native tracks don't have this
143 if (!track.addEventListener) {
148 * @listens VideoTrack#selectedchange
149 * @fires TrackList#change
151 track.addEventListener('selectedchange', function () {
152 if (_this2.changing_) {
155 _this2.changing_ = true;
156 disableOthers(_this2, track);
157 _this2.changing_ = false;
158 _this2.trigger('change');
163 * Add a {@link VideoTrack} to the `VideoTrackList`.
165 * @param {VideoTrack} track
166 * The VideoTrack to add to the list
168 * @fires TrackList#addtrack
172 VideoTrackList.prototype.addTrack = function addTrack(track) {
173 this.addTrack_(track);
177 * Remove a {@link VideoTrack} to the `VideoTrackList`.
179 * @param {VideoTrack} track
180 * The VideoTrack to remove from the list.
182 * @fires TrackList#removetrack
186 VideoTrackList.prototype.removeTrack = function removeTrack(track) {
187 _TrackList.prototype.removeTrack_.call(this, track);
190 return VideoTrackList;
191 }(_trackList2['default']);
193 exports['default'] = VideoTrackList;