Version 1
[yaffs-website] / node_modules / video.js / es5 / tech / loader.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _component = require('../component.js');
6
7 var _component2 = _interopRequireDefault(_component);
8
9 var _tech = require('./tech.js');
10
11 var _tech2 = _interopRequireDefault(_tech);
12
13 var _toTitleCase = require('../utils/to-title-case.js');
14
15 var _toTitleCase2 = _interopRequireDefault(_toTitleCase);
16
17 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
18
19 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
21 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; }
22
23 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; } /**
24                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file loader.js
25                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
26
27
28 /**
29  * The `MediaLoader` is the `Component` that decides which playback technology to load
30  * when a player is initialized.
31  *
32  * @extends Component
33  */
34 var MediaLoader = function (_Component) {
35   _inherits(MediaLoader, _Component);
36
37   /**
38    * Create an instance of this class.
39    *
40    * @param {Player} player
41    *        The `Player` that this class should attach to.
42    *
43    * @param {Object} [options]
44    *        The key/value stroe of player options.
45    *
46    * @param {Component~ReadyCallback} [ready]
47    *        The function that is run when this component is ready.
48    */
49   function MediaLoader(player, options, ready) {
50     _classCallCheck(this, MediaLoader);
51
52     // If there are no sources when the player is initialized,
53     // load the first supported playback technology.
54
55     var _this = _possibleConstructorReturn(this, _Component.call(this, player, options, ready));
56
57     if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
58       for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
59         var techName = (0, _toTitleCase2['default'])(j[i]);
60         var tech = _tech2['default'].getTech(techName);
61
62         // Support old behavior of techs being registered as components.
63         // Remove once that deprecated behavior is removed.
64         if (!techName) {
65           tech = _component2['default'].getComponent(techName);
66         }
67
68         // Check if the browser supports this technology
69         if (tech && tech.isSupported()) {
70           player.loadTech_(techName);
71           break;
72         }
73       }
74     } else {
75       // Loop through playback technologies (HTML5, Flash) and check for support.
76       // Then load the best source.
77       // A few assumptions here:
78       //   All playback technologies respect preload false.
79       player.src(options.playerOptions.sources);
80     }
81     return _this;
82   }
83
84   return MediaLoader;
85 }(_component2['default']);
86
87 _component2['default'].registerComponent('MediaLoader', MediaLoader);
88 exports['default'] = MediaLoader;