Security update for Core, with self-updated composer
[yaffs-website] / node_modules / video.js / es5 / tech / flash.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _tech = require('./tech');
6
7 var _tech2 = _interopRequireDefault(_tech);
8
9 var _dom = require('../utils/dom.js');
10
11 var Dom = _interopRequireWildcard(_dom);
12
13 var _url = require('../utils/url.js');
14
15 var Url = _interopRequireWildcard(_url);
16
17 var _timeRanges = require('../utils/time-ranges.js');
18
19 var _flashRtmp = require('./flash-rtmp');
20
21 var _flashRtmp2 = _interopRequireDefault(_flashRtmp);
22
23 var _component = require('../component');
24
25 var _component2 = _interopRequireDefault(_component);
26
27 var _window = require('global/window');
28
29 var _window2 = _interopRequireDefault(_window);
30
31 var _obj = require('../utils/obj');
32
33 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; } }
34
35 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
36
37 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38
39 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; }
40
41 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; } /**
42                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file flash.js
43                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * VideoJS-SWF - Custom Flash Player with HTML5-ish API
44                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * https://github.com/zencoder/video-js-swf
45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * Not using setupTriggers. Using global onEvent func to distribute events
46                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
47
48 var navigator = _window2['default'].navigator;
49
50 /**
51  * Flash Media Controller - Wrapper for Flash Media API
52  *
53  * @mixes FlashRtmpDecorator
54  * @mixes Tech~SouceHandlerAdditions
55  * @extends Tech
56  */
57
58 var Flash = function (_Tech) {
59   _inherits(Flash, _Tech);
60
61   /**
62    * Create an instance of this Tech.
63    *
64    * @param {Object} [options]
65    *        The key/value store of player options.
66    *
67    * @param {Component~ReadyCallback} ready
68    *        Callback function to call when the `Flash` Tech is ready.
69    */
70   function Flash(options, ready) {
71     _classCallCheck(this, Flash);
72
73     // Set the source when ready
74     var _this = _possibleConstructorReturn(this, _Tech.call(this, options, ready));
75
76     if (options.source) {
77       _this.ready(function () {
78         this.setSource(options.source);
79       }, true);
80     }
81
82     // Having issues with Flash reloading on certain page actions (hide/resize/fullscreen) in certain browsers
83     // This allows resetting the playhead when we catch the reload
84     if (options.startTime) {
85       _this.ready(function () {
86         this.load();
87         this.play();
88         this.currentTime(options.startTime);
89       }, true);
90     }
91
92     // Add global window functions that the swf expects
93     // A 4.x workflow we weren't able to solve for in 5.0
94     // because of the need to hard code these functions
95     // into the swf for security reasons
96     _window2['default'].videojs = _window2['default'].videojs || {};
97     _window2['default'].videojs.Flash = _window2['default'].videojs.Flash || {};
98     _window2['default'].videojs.Flash.onReady = Flash.onReady;
99     _window2['default'].videojs.Flash.onEvent = Flash.onEvent;
100     _window2['default'].videojs.Flash.onError = Flash.onError;
101
102     _this.on('seeked', function () {
103       this.lastSeekTarget_ = undefined;
104     });
105
106     return _this;
107   }
108
109   /**
110    * Create the `Flash` Tech's DOM element.
111    *
112    * @return {Element}
113    *         The element that gets created.
114    */
115
116
117   Flash.prototype.createEl = function createEl() {
118     var options = this.options_;
119
120     // If video.js is hosted locally you should also set the location
121     // for the hosted swf, which should be relative to the page (not video.js)
122     // Otherwise this adds a CDN url.
123     // The CDN also auto-adds a swf URL for that specific version.
124     if (!options.swf) {
125       var ver = '5.3.0';
126
127       options.swf = '//vjs.zencdn.net/swf/' + ver + '/video-js.swf';
128     }
129
130     // Generate ID for swf object
131     var objId = options.techId;
132
133     // Merge default flashvars with ones passed in to init
134     var flashVars = (0, _obj.assign)({
135
136       // SWF Callback Functions
137       readyFunction: 'videojs.Flash.onReady',
138       eventProxyFunction: 'videojs.Flash.onEvent',
139       errorEventProxyFunction: 'videojs.Flash.onError',
140
141       // Player Settings
142       autoplay: options.autoplay,
143       preload: options.preload,
144       loop: options.loop,
145       muted: options.muted
146
147     }, options.flashVars);
148
149     // Merge default parames with ones passed in
150     var params = (0, _obj.assign)({
151       // Opaque is needed to overlay controls, but can affect playback performance
152       wmode: 'opaque',
153       // Using bgcolor prevents a white flash when the object is loading
154       bgcolor: '#000000'
155     }, options.params);
156
157     // Merge default attributes with ones passed in
158     var attributes = (0, _obj.assign)({
159       // Both ID and Name needed or swf to identify itself
160       id: objId,
161       name: objId,
162       'class': 'vjs-tech'
163     }, options.attributes);
164
165     this.el_ = Flash.embed(options.swf, flashVars, params, attributes);
166     this.el_.tech = this;
167
168     return this.el_;
169   };
170
171   /**
172    * Called by {@link Player#play} to play using the `Flash` `Tech`.
173    */
174
175
176   Flash.prototype.play = function play() {
177     if (this.ended()) {
178       this.setCurrentTime(0);
179     }
180     this.el_.vjs_play();
181   };
182
183   /**
184    * Called by {@link Player#pause} to pause using the `Flash` `Tech`.
185    */
186
187
188   Flash.prototype.pause = function pause() {
189     this.el_.vjs_pause();
190   };
191
192   /**
193    * A getter/setter for the `Flash` Tech's source object.
194    * > Note: Please use {@link Flash#setSource}
195    *
196    * @param {Tech~SourceObject} [src]
197    *        The source object you want to set on the `Flash` techs.
198    *
199    * @return {Tech~SourceObject|undefined}
200    *         - The current source object when a source is not passed in.
201    *         - undefined when setting
202    *
203    * @deprecated Since version 5.
204    */
205
206
207   Flash.prototype.src = function src(_src) {
208     if (_src === undefined) {
209       return this.currentSrc();
210     }
211
212     // Setting src through `src` not `setSrc` will be deprecated
213     return this.setSrc(_src);
214   };
215
216   /**
217    * A getter/setter for the `Flash` Tech's source object.
218    *
219    * @param {Tech~SourceObject} [src]
220    *        The source object you want to set on the `Flash` techs.
221    *
222    * @return {Tech~SourceObject|undefined}
223    *         - The current source object when a source is not passed in.
224    *         - undefined when setting
225    */
226
227
228   Flash.prototype.setSrc = function setSrc(src) {
229     var _this2 = this;
230
231     // Make sure source URL is absolute.
232     src = Url.getAbsoluteURL(src);
233     this.el_.vjs_src(src);
234
235     // Currently the SWF doesn't autoplay if you load a source later.
236     // e.g. Load player w/ no source, wait 2s, set src.
237     if (this.autoplay()) {
238       this.setTimeout(function () {
239         return _this2.play();
240       }, 0);
241     }
242   };
243
244   /**
245    * Indicates whether the media is currently seeking to a new position or not.
246    *
247    * @return {boolean}
248    *         - True if seeking to a new position
249    *         - False otherwise
250    */
251
252
253   Flash.prototype.seeking = function seeking() {
254     return this.lastSeekTarget_ !== undefined;
255   };
256
257   /**
258    * Returns the current time in seconds that the media is at in playback.
259    *
260    * @param {number} time
261    *        Current playtime of the media in seconds.
262    */
263
264
265   Flash.prototype.setCurrentTime = function setCurrentTime(time) {
266     var seekable = this.seekable();
267
268     if (seekable.length) {
269       // clamp to the current seekable range
270       time = time > seekable.start(0) ? time : seekable.start(0);
271       time = time < seekable.end(seekable.length - 1) ? time : seekable.end(seekable.length - 1);
272
273       this.lastSeekTarget_ = time;
274       this.trigger('seeking');
275       this.el_.vjs_setProperty('currentTime', time);
276       _Tech.prototype.setCurrentTime.call(this);
277     }
278   };
279
280   /**
281    * Get the current playback time in seconds
282    *
283    * @return {number}
284    *         The current time of playback in seconds.
285    */
286
287
288   Flash.prototype.currentTime = function currentTime() {
289     // when seeking make the reported time keep up with the requested time
290     // by reading the time we're seeking to
291     if (this.seeking()) {
292       return this.lastSeekTarget_ || 0;
293     }
294     return this.el_.vjs_getProperty('currentTime');
295   };
296
297   /**
298    * Get the current source
299    *
300    * @method currentSrc
301    * @return {Tech~SourceObject}
302    *         The current source
303    */
304
305
306   Flash.prototype.currentSrc = function currentSrc() {
307     if (this.currentSource_) {
308       return this.currentSource_.src;
309     }
310     return this.el_.vjs_getProperty('currentSrc');
311   };
312
313   /**
314    * Get the total duration of the current media.
315    *
316    * @return {number}
317    8          The total duration of the current media.
318    */
319
320
321   Flash.prototype.duration = function duration() {
322     if (this.readyState() === 0) {
323       return NaN;
324     }
325     var duration = this.el_.vjs_getProperty('duration');
326
327     return duration >= 0 ? duration : Infinity;
328   };
329
330   /**
331    * Load media into Tech.
332    */
333
334
335   Flash.prototype.load = function load() {
336     this.el_.vjs_load();
337   };
338
339   /**
340    * Get the poster image that was set on the tech.
341    */
342
343
344   Flash.prototype.poster = function poster() {
345     this.el_.vjs_getProperty('poster');
346   };
347
348   /**
349    * Poster images are not handled by the Flash tech so make this is a no-op.
350    */
351
352
353   Flash.prototype.setPoster = function setPoster() {};
354
355   /**
356    * Determine the time ranges that can be seeked to in the media.
357    *
358    * @return {TimeRange}
359    *         Returns the time ranges that can be seeked to.
360    */
361
362
363   Flash.prototype.seekable = function seekable() {
364     var duration = this.duration();
365
366     if (duration === 0) {
367       return (0, _timeRanges.createTimeRange)();
368     }
369     return (0, _timeRanges.createTimeRange)(0, duration);
370   };
371
372   /**
373    * Get and create a `TimeRange` object for buffering.
374    *
375    * @return {TimeRange}
376    *         The time range object that was created.
377    */
378
379
380   Flash.prototype.buffered = function buffered() {
381     var ranges = this.el_.vjs_getProperty('buffered');
382
383     if (ranges.length === 0) {
384       return (0, _timeRanges.createTimeRange)();
385     }
386     return (0, _timeRanges.createTimeRange)(ranges[0][0], ranges[0][1]);
387   };
388
389   /**
390    * Get fullscreen support -
391    *
392    * Flash does not allow fullscreen through javascript
393    * so this always returns false.
394    *
395    * @return {boolean}
396    *         The Flash tech does not support fullscreen, so it will always return false.
397    */
398
399
400   Flash.prototype.supportsFullScreen = function supportsFullScreen() {
401     // Flash does not allow fullscreen through javascript
402     return false;
403   };
404
405   /**
406    * Flash does not allow fullscreen through javascript
407    * so this always returns false.
408    *
409    * @return {boolean}
410    *         The Flash tech does not support fullscreen, so it will always return false.
411    */
412
413
414   Flash.prototype.enterFullScreen = function enterFullScreen() {
415     return false;
416   };
417
418   return Flash;
419 }(_tech2['default']);
420
421 // Create setters and getters for attributes
422
423
424 var _api = Flash.prototype;
425 var _readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(',');
426 var _readOnly = 'networkState,readyState,initialTime,startOffsetTime,paused,ended,videoWidth,videoHeight'.split(',');
427
428 function _createSetter(attr) {
429   var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
430
431   _api['set' + attrUpper] = function (val) {
432     return this.el_.vjs_setProperty(attr, val);
433   };
434 }
435
436 function _createGetter(attr) {
437   _api[attr] = function () {
438     return this.el_.vjs_getProperty(attr);
439   };
440 }
441
442 // Create getter and setters for all read/write attributes
443 for (var i = 0; i < _readWrite.length; i++) {
444   _createGetter(_readWrite[i]);
445   _createSetter(_readWrite[i]);
446 }
447
448 // Create getters for read-only attributes
449 for (var _i = 0; _i < _readOnly.length; _i++) {
450   _createGetter(_readOnly[_i]);
451 }
452
453 /** ------------------------------ Getters ------------------------------ **/
454 /**
455  * Get the value of `rtmpConnection` from the swf.
456  *
457  * @method Flash#rtmpConnection
458  * @return {string}
459  *         The current value of `rtmpConnection` on the swf.
460  */
461
462 /**
463  * Get the value of `rtmpStream` from the swf.
464  *
465  * @method Flash#rtmpStream
466  * @return {string}
467  *         The current value of `rtmpStream` on the swf.
468  */
469
470 /**
471  * Get the value of `preload` from the swf. `preload` indicates
472  * what should download before the media is interacted with. It can have the following
473  * values:
474  * - none: nothing should be downloaded
475  * - metadata: poster and the first few frames of the media may be downloaded to get
476  *   media dimensions and other metadata
477  * - auto: allow the media and metadata for the media to be downloaded before
478  *    interaction
479  *
480  * @method Flash#preload
481  * @return {string}
482  *         The value of `preload` from the swf. Will be 'none', 'metadata',
483  *         or 'auto'.
484  */
485
486 /**
487  * Get the value of `defaultPlaybackRate` from the swf.
488  *
489  * @method Flash#defaultPlaybackRate
490  * @return {number}
491  *         The current value of `defaultPlaybackRate` on the swf.
492  */
493
494 /**
495  * Get the value of `playbackRate` from the swf. `playbackRate` indicates
496  * the rate at which the media is currently playing back. Examples:
497  *   - if playbackRate is set to 2, media will play twice as fast.
498  *   - if playbackRate is set to 0.5, media will play half as fast.
499  *
500  * @method Flash#playbackRate
501  * @return {number}
502  *         The value of `playbackRate` from the swf. A number indicating
503  *         the current playback speed of the media, where 1 is normal speed.
504  */
505
506 /**
507  * Get the value of `autoplay` from the swf. `autoplay` indicates
508  * that the media should start to play as soon as the page is ready.
509  *
510  * @method Flash#autoplay
511  * @return {boolean}
512  *         - The value of `autoplay` from the swf.
513  *         - True indicates that the media ashould start as soon as the page loads.
514  *         - False indicates that the media should not start as soon as the page loads.
515  */
516
517 /**
518  * Get the value of `loop` from the swf. `loop` indicates
519  * that the media should return to the start of the media and continue playing once
520  * it reaches the end.
521  *
522  * @method Flash#loop
523  * @return {boolean}
524  *         - The value of `loop` from the swf.
525  *         - True indicates that playback should seek back to start once
526  *           the end of a media is reached.
527  *         - False indicates that playback should not loop back to the start when the
528  *           end of the media is reached.
529  */
530
531 /**
532  * Get the value of `mediaGroup` from the swf.
533  *
534  * @method Flash#mediaGroup
535  * @return {string}
536  *         The current value of `mediaGroup` on the swf.
537  */
538
539 /**
540  * Get the value of `controller` from the swf.
541  *
542  * @method Flash#controller
543  * @return {string}
544  *         The current value of `controller` on the swf.
545  */
546
547 /**
548  * Get the value of `controls` from the swf. `controls` indicates
549  * whether the native flash controls should be shown or hidden.
550  *
551  * @method Flash#controls
552  * @return {boolean}
553  *         - The value of `controls` from the swf.
554  *         - True indicates that native controls should be showing.
555  *         - False indicates that native controls should be hidden.
556  */
557
558 /**
559  * Get the value of the `volume` from the swf. `volume` indicates the current
560  * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
561  * so on.
562  *
563  * @method Flash#volume
564  * @return {number}
565  *         The volume percent as a decimal. Value will be between 0-1.
566  */
567
568 /**
569  * Get the value of the `muted` from the swf. `muted` indicates the current
570  * audio level should be silent.
571  *
572  * @method Flash#muted
573  * @return {boolean}
574  *         - True if the audio should be set to silent
575  *         - False otherwise
576  */
577
578 /**
579  * Get the value of `defaultMuted` from the swf. `defaultMuted` indicates
580  * whether the media should start muted or not. Only changes the default state of the
581  * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
582  * current state.
583  *
584  * @method Flash#defaultMuted
585  * @return {boolean}
586  *         - The value of `defaultMuted` from the swf.
587  *         - True indicates that the media should start muted.
588  *         - False indicates that the media should not start muted.
589  */
590
591 /**
592  * Get the value of `networkState` from the swf. `networkState` indicates
593  * the current network state. It returns an enumeration from the following list:
594  * - 0: NETWORK_EMPTY
595  * - 1: NEWORK_IDLE
596  * - 2: NETWORK_LOADING
597  * - 3: NETWORK_NO_SOURCE
598  *
599  * @method Flash#networkState
600  * @return {number}
601  *         The value of `networkState` from the swf. This will be a number
602  *         from the list in the description.
603  */
604
605 /**
606  * Get the value of `readyState` from the swf. `readyState` indicates
607  * the current state of the media element. It returns an enumeration from the
608  * following list:
609  * - 0: HAVE_NOTHING
610  * - 1: HAVE_METADATA
611  * - 2: HAVE_CURRENT_DATA
612  * - 3: HAVE_FUTURE_DATA
613  * - 4: HAVE_ENOUGH_DATA
614  *
615  * @method Flash#readyState
616  * @return {number}
617  *         The value of `readyState` from the swf. This will be a number
618  *         from the list in the description.
619  */
620
621 /**
622  * Get the value of `readyState` from the swf. `readyState` indicates
623  * the current state of the media element. It returns an enumeration from the
624  * following list:
625  * - 0: HAVE_NOTHING
626  * - 1: HAVE_METADATA
627  * - 2: HAVE_CURRENT_DATA
628  * - 3: HAVE_FUTURE_DATA
629  * - 4: HAVE_ENOUGH_DATA
630  *
631  * @method Flash#readyState
632  * @return {number}
633  *         The value of `readyState` from the swf. This will be a number
634  *         from the list in the description.
635  */
636
637 /**
638  * Get the value of `initialTime` from the swf.
639  *
640  * @method Flash#initialTime
641  * @return {number}
642  *         The `initialTime` proprety on the swf.
643  */
644
645 /**
646  * Get the value of `startOffsetTime` from the swf.
647  *
648  * @method Flash#startOffsetTime
649  * @return {number}
650  *         The `startOffsetTime` proprety on the swf.
651  */
652
653 /**
654  * Get the value of `paused` from the swf. `paused` indicates whether the swf
655  * is current paused or not.
656  *
657  * @method Flash#paused
658  * @return {boolean}
659  *         The value of `paused` from the swf.
660  */
661
662 /**
663  * Get the value of `ended` from the swf. `ended` indicates whether
664  * the media has reached the end or not.
665  *
666  * @method Flash#ended
667  * @return {boolean}
668  *         - True indicates that the media has ended.
669  *         - False indicates that the media has not ended.
670  *
671  * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
672  */
673
674 /**
675  * Get the value of `videoWidth` from the swf. `videoWidth` indicates
676  * the current width of the media in css pixels.
677  *
678  * @method Flash#videoWidth
679  * @return {number}
680  *         The value of `videoWidth` from the swf. This will be a number
681  *         in css pixels.
682  */
683
684 /**
685  * Get the value of `videoHeight` from the swf. `videoHeigth` indicates
686  * the current height of the media in css pixels.
687  *
688  * @method Flassh.prototype.videoHeight
689  * @return {number}
690  *         The value of `videoHeight` from the swf. This will be a number
691  *         in css pixels.
692  */
693 /** ------------------------------ Setters ------------------------------ **/
694
695 /**
696  * Set the value of `rtmpConnection` on the swf.
697  *
698  * @method Flash#setRtmpConnection
699  * @param {string} rtmpConnection
700  *        New value to set the `rtmpConnection` property to.
701  */
702
703 /**
704  * Set the value of `rtmpStream` on the swf.
705  *
706  * @method Flash#setRtmpStream
707  * @param {string} rtmpStream
708  *        New value to set the `rtmpStream` property to.
709  */
710
711 /**
712  * Set the value of `preload` on the swf. `preload` indicates
713  * what should download before the media is interacted with. It can have the following
714  * values:
715  * - none: nothing should be downloaded
716  * - metadata: poster and the first few frames of the media may be downloaded to get
717  *   media dimensions and other metadata
718  * - auto: allow the media and metadata for the media to be downloaded before
719  *    interaction
720  *
721  * @method Flash#setPreload
722  * @param {string} preload
723  *        The value of `preload` to set on the swf. Should be 'none', 'metadata',
724  *        or 'auto'.
725  */
726
727 /**
728  * Set the value of `defaultPlaybackRate` on the swf.
729  *
730  * @method Flash#setDefaultPlaybackRate
731  * @param {number} defaultPlaybackRate
732  *        New value to set the `defaultPlaybackRate` property to.
733  */
734
735 /**
736  * Set the value of `playbackRate` on the swf. `playbackRate` indicates
737  * the rate at which the media is currently playing back. Examples:
738  *   - if playbackRate is set to 2, media will play twice as fast.
739  *   - if playbackRate is set to 0.5, media will play half as fast.
740  *
741  * @method Flash#setPlaybackRate
742  * @param {number} playbackRate
743  *        New value of `playbackRate` on the swf. A number indicating
744  *        the current playback speed of the media, where 1 is normal speed.
745  */
746
747 /**
748  * Set the value of `autoplay` on the swf. `autoplay` indicates
749  * that the media should start to play as soon as the page is ready.
750  *
751  * @method Flash#setAutoplay
752  * @param {boolean} autoplay
753  *        - The value of `autoplay` from the swf.
754  *        - True indicates that the media ashould start as soon as the page loads.
755  *        - False indicates that the media should not start as soon as the page loads.
756  */
757
758 /**
759  * Set the value of `loop` on the swf. `loop` indicates
760  * that the media should return to the start of the media and continue playing once
761  * it reaches the end.
762  *
763  * @method Flash#setLoop
764  * @param {boolean} loop
765  *        - True indicates that playback should seek back to start once
766  *          the end of a media is reached.
767  *        - False indicates that playback should not loop back to the start when the
768  *          end of the media is reached.
769  */
770
771 /**
772  * Set the value of `mediaGroup` on the swf.
773  *
774  * @method Flash#setMediaGroup
775  * @param {string} mediaGroup
776  *        New value of `mediaGroup` to set on the swf.
777  */
778
779 /**
780  * Set the value of `controller` on the swf.
781  *
782  * @method Flash#setController
783  * @param {string} controller
784  *        New value the current value of `controller` on the swf.
785  */
786
787 /**
788  * Get the value of `controls` from the swf. `controls` indicates
789  * whether the native flash controls should be shown or hidden.
790  *
791  * @method Flash#controls
792  * @return {boolean}
793  *         - The value of `controls` from the swf.
794  *         - True indicates that native controls should be showing.
795  *         - False indicates that native controls should be hidden.
796  */
797
798 /**
799  * Set the value of the `volume` on the swf. `volume` indicates the current
800  * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
801  * so on.
802  *
803  * @method Flash#setVolume
804  * @param {number} percentAsDecimal
805  *         The volume percent as a decimal. Value will be between 0-1.
806  */
807
808 /**
809  * Set the value of the `muted` on the swf. `muted` indicates that the current
810  * audio level should be silent.
811  *
812  * @method Flash#setMuted
813  * @param {boolean} muted
814  *         - True if the audio should be set to silent
815  *         - False otherwise
816  */
817
818 /**
819  * Set the value of `defaultMuted` on the swf. `defaultMuted` indicates
820  * whether the media should start muted or not. Only changes the default state of the
821  * media. `muted` and `defaultMuted` can have different values. `muted` indicates the
822  * current state.
823  *
824  * @method Flash#setDefaultMuted
825  * @param {boolean} defaultMuted
826  *         - True indicates that the media should start muted.
827  *         - False indicates that the media should not start muted.
828  */
829
830 /* Flash Support Testing -------------------------------------------------------- */
831
832 /**
833  * Check if the Flash tech is currently supported.
834  *
835  * @return {boolean}
836  *          - True if the flash tech is supported.
837  *          - False otherwise.
838  */
839 Flash.isSupported = function () {
840   return Flash.version()[0] >= 10;
841   // return swfobject.hasFlashPlayerVersion('10');
842 };
843
844 // Add Source Handler pattern functions to this tech
845 _tech2['default'].withSourceHandlers(Flash);
846
847 /*
848  * Native source handler for flash,  simply passes the source to the swf element.
849  *
850  * @property {Tech~SourceObject} source
851  *           The source object
852  *
853  * @property {Flash} tech
854  *           The instance of the Flash tech
855  */
856 Flash.nativeSourceHandler = {};
857
858 /**
859  * Check if the Flash can play the given mime type.
860  *
861  * @param {string} type
862  *        The mimetype to check
863  *
864  * @return {string}
865  *         'maybe', or '' (empty string)
866  */
867 Flash.nativeSourceHandler.canPlayType = function (type) {
868   if (type in Flash.formats) {
869     return 'maybe';
870   }
871
872   return '';
873 };
874
875 /**
876  * Check if the media element can handle a source natively.
877  *
878  * @param {Tech~SourceObject} source
879  *         The source object
880  *
881  * @param {Object} [options]
882  *         Options to be passed to the tech.
883  *
884  * @return {string}
885  *         'maybe', or '' (empty string).
886  */
887 Flash.nativeSourceHandler.canHandleSource = function (source, options) {
888   var type = void 0;
889
890   function guessMimeType(src) {
891     var ext = Url.getFileExtension(src);
892
893     if (ext) {
894       return 'video/' + ext;
895     }
896     return '';
897   }
898
899   if (!source.type) {
900     type = guessMimeType(source.src);
901   } else {
902     // Strip code information from the type because we don't get that specific
903     type = source.type.replace(/;.*/, '').toLowerCase();
904   }
905
906   return Flash.nativeSourceHandler.canPlayType(type);
907 };
908
909 /**
910  * Pass the source to the swf.
911  *
912  * @param {Tech~SourceObject} source
913  *        The source object
914  *
915  * @param {Flash} tech
916  *        The instance of the Flash tech
917  *
918  * @param {Object} [options]
919  *        The options to pass to the source
920  */
921 Flash.nativeSourceHandler.handleSource = function (source, tech, options) {
922   tech.setSrc(source.src);
923 };
924
925 /**
926  * noop for native source handler dispose, as cleanup will happen automatically.
927  */
928 Flash.nativeSourceHandler.dispose = function () {};
929
930 // Register the native source handler
931 Flash.registerSourceHandler(Flash.nativeSourceHandler);
932
933 /**
934  * Flash supported mime types.
935  *
936  * @constant {Object}
937  */
938 Flash.formats = {
939   'video/flv': 'FLV',
940   'video/x-flv': 'FLV',
941   'video/mp4': 'MP4',
942   'video/m4v': 'MP4'
943 };
944
945 /**
946  * Called when the the swf is "ready", and makes sure that the swf is really
947  * ready using {@link Flash#checkReady}
948  */
949 Flash.onReady = function (currSwf) {
950   var el = Dom.getEl(currSwf);
951   var tech = el && el.tech;
952
953   // if there is no el then the tech has been disposed
954   // and the tech element was removed from the player div
955   if (tech && tech.el()) {
956     // check that the flash object is really ready
957     Flash.checkReady(tech);
958   }
959 };
960
961 /**
962  * The SWF isn't always ready when it says it is. Sometimes the API functions still
963  * need to be added to the object. If it's not ready, we set a timeout to check again
964  * shortly.
965  *
966  * @param {Flash} tech
967  *        The instance of the flash tech to check.
968  */
969 Flash.checkReady = function (tech) {
970   // stop worrying if the tech has been disposed
971   if (!tech.el()) {
972     return;
973   }
974
975   // check if API property exists
976   if (tech.el().vjs_getProperty) {
977     // tell tech it's ready
978     tech.triggerReady();
979   } else {
980     // wait longer
981     this.setTimeout(function () {
982       Flash.checkReady(tech);
983     }, 50);
984   }
985 };
986
987 /**
988  * Trigger events from the swf on the Flash Tech.
989  *
990  * @param {number} swfID
991  *        The id of the swf that had the event
992  *
993  * @param {string} eventName
994  *        The name of the event to trigger
995  */
996 Flash.onEvent = function (swfID, eventName) {
997   var tech = Dom.getEl(swfID).tech;
998   var args = Array.prototype.slice.call(arguments, 2);
999
1000   // dispatch Flash events asynchronously for two reasons:
1001   // - Flash swallows any exceptions generated by javascript it
1002   //   invokes
1003   // - Flash is suspended until the javascript returns which may cause
1004   //   playback performance issues
1005   tech.setTimeout(function () {
1006     tech.trigger(eventName, args);
1007   }, 1);
1008 };
1009
1010 /**
1011  * Log errors from the swf on the Flash tech.
1012  *
1013  * @param {number} swfID
1014  *        The id of the swf that had an error.
1015  *
1016  * @param {string} The error string
1017  *        The error to set on the Flash Tech.
1018  *
1019  * @return {MediaError|undefined}
1020  *          - Returns a MediaError when err is 'srcnotfound'
1021  *          - Returns undefined otherwise.
1022  */
1023 Flash.onError = function (swfID, err) {
1024   var tech = Dom.getEl(swfID).tech;
1025
1026   // trigger MEDIA_ERR_SRC_NOT_SUPPORTED
1027   if (err === 'srcnotfound') {
1028     return tech.error(4);
1029   }
1030
1031   // trigger a custom error
1032   tech.error('FLASH: ' + err);
1033 };
1034
1035 /**
1036  * Get the current version of Flash that is in use on the page.
1037  *
1038  * @return {Array}
1039  *          an array of versions that are available.
1040  */
1041 Flash.version = function () {
1042   var version = '0,0,0';
1043
1044   // IE
1045   try {
1046     version = new _window2['default'].ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
1047
1048     // other browsers
1049   } catch (e) {
1050     try {
1051       if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
1052         version = (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']).description.replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
1053       }
1054     } catch (err) {
1055       // satisfy linter
1056     }
1057   }
1058   return version.split(',');
1059 };
1060
1061 /**
1062  * Only use for non-iframe embeds.
1063  *
1064  * @param {Object} swf
1065  *        The videojs-swf object.
1066  *
1067  * @param {Object} flashVars
1068  *        Names and values to use as flash option variables.
1069  *
1070  * @param {Object} params
1071  *        Style parameters to set on the object.
1072  *
1073  * @param {Object} attributes
1074  *        Attributes to set on the element.
1075  *
1076  * @return {Element}
1077  *          The embeded Flash DOM element.
1078  */
1079 Flash.embed = function (swf, flashVars, params, attributes) {
1080   var code = Flash.getEmbedCode(swf, flashVars, params, attributes);
1081
1082   // Get element by embedding code and retrieving created element
1083   var obj = Dom.createEl('div', { innerHTML: code }).childNodes[0];
1084
1085   return obj;
1086 };
1087
1088 /**
1089  * Only use for non-iframe embeds.
1090  *
1091  * @param {Object} swf
1092  *        The videojs-swf object.
1093  *
1094  * @param {Object} flashVars
1095  *        Names and values to use as flash option variables.
1096  *
1097  * @param {Object} params
1098  *        Style parameters to set on the object.
1099  *
1100  * @param {Object} attributes
1101  *        Attributes to set on the element.
1102  *
1103  * @return {Element}
1104  *          The embeded Flash DOM element.
1105  */
1106 Flash.getEmbedCode = function (swf, flashVars, params, attributes) {
1107   var objTag = '<object type="application/x-shockwave-flash" ';
1108   var flashVarsString = '';
1109   var paramsString = '';
1110   var attrsString = '';
1111
1112   // Convert flash vars to string
1113   if (flashVars) {
1114     Object.getOwnPropertyNames(flashVars).forEach(function (key) {
1115       flashVarsString += key + '=' + flashVars[key] + '&amp;';
1116     });
1117   }
1118
1119   // Add swf, flashVars, and other default params
1120   params = (0, _obj.assign)({
1121     movie: swf,
1122     flashvars: flashVarsString,
1123     // Required to talk to swf
1124     allowScriptAccess: 'always',
1125     // All should be default, but having security issues.
1126     allowNetworking: 'all'
1127   }, params);
1128
1129   // Create param tags string
1130   Object.getOwnPropertyNames(params).forEach(function (key) {
1131     paramsString += '<param name="' + key + '" value="' + params[key] + '" />';
1132   });
1133
1134   attributes = (0, _obj.assign)({
1135     // Add swf to attributes (need both for IE and Others to work)
1136     data: swf,
1137
1138     // Default to 100% width/height
1139     width: '100%',
1140     height: '100%'
1141
1142   }, attributes);
1143
1144   // Create Attributes string
1145   Object.getOwnPropertyNames(attributes).forEach(function (key) {
1146     attrsString += key + '="' + attributes[key] + '" ';
1147   });
1148
1149   return '' + objTag + attrsString + '>' + paramsString + '</object>';
1150 };
1151
1152 // Run Flash through the RTMP decorator
1153 (0, _flashRtmp2['default'])(Flash);
1154
1155 _component2['default'].registerComponent('Flash', Flash);
1156 _tech2['default'].registerTech('Flash', Flash);
1157 exports['default'] = Flash;