e7644f7ef4bbf365e9f7c2df17d77eb9a5df23d1
[yaffs-website] / node_modules / video.js / es5 / tracks / audio-track-list.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _trackList = require('./track-list');
6
7 var _trackList2 = _interopRequireDefault(_trackList);
8
9 var _browser = require('../utils/browser.js');
10
11 var browser = _interopRequireWildcard(_browser);
12
13 var _document = require('global/document');
14
15 var _document2 = _interopRequireDefault(_document);
16
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; } }
18
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
20
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
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; }
24
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 audio-track-list.js
27                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
28
29
30 /**
31  * Anywhere we call this function we diverge from the spec
32  * as we only support one enabled audiotrack at a time
33  *
34  * @param {AudioTrackList} list
35  *        list to work on
36  *
37  * @param {AudioTrack} track
38  *        The track to skip
39  *
40  * @private
41  */
42 var disableOthers = function disableOthers(list, track) {
43   for (var i = 0; i < list.length; i++) {
44     if (track.id === list[i].id) {
45       continue;
46     }
47     // another audio track is enabled, disable it
48     list[i].enabled = false;
49   }
50 };
51
52 /**
53  * The current list of {@link AudioTrack} for a media file.
54  *
55  * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist}
56  * @extends TrackList
57  */
58
59 var AudioTrackList = function (_TrackList) {
60   _inherits(AudioTrackList, _TrackList);
61
62   /**
63    * Create an instance of this class.
64    *
65    * @param {AudioTrack[]} [tracks=[]]
66    *        A list of `AudioTrack` to instantiate the list with.
67    */
68   function AudioTrackList() {
69     var _this, _ret;
70
71     var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
72
73     _classCallCheck(this, AudioTrackList);
74
75     var list = void 0;
76
77     // make sure only 1 track is enabled
78     // sorted from last index to first index
79     for (var i = tracks.length - 1; i >= 0; i--) {
80       if (tracks[i].enabled) {
81         disableOthers(tracks, tracks[i]);
82         break;
83       }
84     }
85
86     // IE8 forces us to implement inheritance ourselves
87     // as it does not support Object.defineProperty properly
88     if (browser.IS_IE8) {
89       list = _document2['default'].createElement('custom');
90       for (var prop in _trackList2['default'].prototype) {
91         if (prop !== 'constructor') {
92           list[prop] = _trackList2['default'].prototype[prop];
93         }
94       }
95       for (var _prop in AudioTrackList.prototype) {
96         if (_prop !== 'constructor') {
97           list[_prop] = AudioTrackList.prototype[_prop];
98         }
99       }
100     }
101
102     list = (_this = _possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
103     list.changing_ = false;
104
105     return _ret = list, _possibleConstructorReturn(_this, _ret);
106   }
107
108   /**
109    * Add an {@link AudioTrack} to the `AudioTrackList`.
110    *
111    * @param {AudioTrack} track
112    *        The AudioTrack to add to the list
113    *
114    * @fires Track#addtrack
115    * @private
116    */
117
118
119   AudioTrackList.prototype.addTrack_ = function addTrack_(track) {
120     var _this2 = this;
121
122     if (track.enabled) {
123       disableOthers(this, track);
124     }
125
126     _TrackList.prototype.addTrack_.call(this, track);
127     // native tracks don't have this
128     if (!track.addEventListener) {
129       return;
130     }
131
132     /**
133      * @listens AudioTrack#enabledchange
134      * @fires TrackList#change
135      */
136     track.addEventListener('enabledchange', function () {
137       // when we are disabling other tracks (since we don't support
138       // more than one track at a time) we will set changing_
139       // to true so that we don't trigger additional change events
140       if (_this2.changing_) {
141         return;
142       }
143       _this2.changing_ = true;
144       disableOthers(_this2, track);
145       _this2.changing_ = false;
146       _this2.trigger('change');
147     });
148   };
149
150   /**
151    * Add an {@link AudioTrack} to the `AudioTrackList`.
152    *
153    * @param {AudioTrack} track
154    *        The AudioTrack to add to the list
155    *
156    * @fires Track#addtrack
157    */
158
159
160   AudioTrackList.prototype.addTrack = function addTrack(track) {
161     this.addTrack_(track);
162   };
163
164   /**
165    * Remove an {@link AudioTrack} from the `AudioTrackList`.
166    *
167    * @param {AudioTrack} track
168    *        The AudioTrack to remove from the list
169    *
170    * @fires Track#removetrack
171    */
172
173
174   AudioTrackList.prototype.removeTrack = function removeTrack(track) {
175     _TrackList.prototype.removeTrack_.call(this, track);
176   };
177
178   return AudioTrackList;
179 }(_trackList2['default']);
180
181 exports['default'] = AudioTrackList;