wotnot-video-react
Version:
Video-React is a web video player built from the ground up for an HTML5 world using React library.
1,777 lines (1,534 loc) • 154 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('redux')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'redux'], factory) :
(global = global || self, factory(global['video-react'] = {}, global.React, global.Redux));
}(this, (function (exports, React, redux) { 'use strict';
var React__default = 'default' in React ? React['default'] : React;
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var b = "function" === typeof Symbol && Symbol.for,
c = b ? Symbol.for("react.element") : 60103,
d = b ? Symbol.for("react.portal") : 60106,
e = b ? Symbol.for("react.fragment") : 60107,
f = b ? Symbol.for("react.strict_mode") : 60108,
g = b ? Symbol.for("react.profiler") : 60114,
h = b ? Symbol.for("react.provider") : 60109,
k = b ? Symbol.for("react.context") : 60110,
l = b ? Symbol.for("react.async_mode") : 60111,
m = b ? Symbol.for("react.concurrent_mode") : 60111,
n = b ? Symbol.for("react.forward_ref") : 60112,
p = b ? Symbol.for("react.suspense") : 60113,
q = b ? Symbol.for("react.suspense_list") : 60120,
r = b ? Symbol.for("react.memo") : 60115,
t = b ? Symbol.for("react.lazy") : 60116,
v = b ? Symbol.for("react.block") : 60121,
w = b ? Symbol.for("react.fundamental") : 60117,
x = b ? Symbol.for("react.responder") : 60118,
y = b ? Symbol.for("react.scope") : 60119;
function z(a) {
if ("object" === typeof a && null !== a) {
var u = a.$$typeof;
switch (u) {
case c:
switch (a = a.type, a) {
case l:
case m:
case e:
case g:
case f:
case p:
return a;
default:
switch (a = a && a.$$typeof, a) {
case k:
case n:
case t:
case r:
case h:
return a;
default:
return u;
}
}
case d:
return u;
}
}
}
function A(a) {
return z(a) === m;
}
var AsyncMode = l;
var ConcurrentMode = m;
var ContextConsumer = k;
var ContextProvider = h;
var Element = c;
var ForwardRef = n;
var Fragment = e;
var Lazy = t;
var Memo = r;
var Portal = d;
var Profiler = g;
var StrictMode = f;
var Suspense = p;
var isAsyncMode = function isAsyncMode(a) {
return A(a) || z(a) === l;
};
var isConcurrentMode = A;
var isContextConsumer = function isContextConsumer(a) {
return z(a) === k;
};
var isContextProvider = function isContextProvider(a) {
return z(a) === h;
};
var isElement = function isElement(a) {
return "object" === typeof a && null !== a && a.$$typeof === c;
};
var isForwardRef = function isForwardRef(a) {
return z(a) === n;
};
var isFragment = function isFragment(a) {
return z(a) === e;
};
var isLazy = function isLazy(a) {
return z(a) === t;
};
var isMemo = function isMemo(a) {
return z(a) === r;
};
var isPortal = function isPortal(a) {
return z(a) === d;
};
var isProfiler = function isProfiler(a) {
return z(a) === g;
};
var isStrictMode = function isStrictMode(a) {
return z(a) === f;
};
var isSuspense = function isSuspense(a) {
return z(a) === p;
};
var isValidElementType = function isValidElementType(a) {
return "string" === typeof a || "function" === typeof a || a === e || a === m || a === g || a === f || a === p || a === q || "object" === typeof a && null !== a && (a.$$typeof === t || a.$$typeof === r || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n || a.$$typeof === w || a.$$typeof === x || a.$$typeof === y || a.$$typeof === v);
};
var typeOf = z;
var reactIs_production_min = {
AsyncMode: AsyncMode,
ConcurrentMode: ConcurrentMode,
ContextConsumer: ContextConsumer,
ContextProvider: ContextProvider,
Element: Element,
ForwardRef: ForwardRef,
Fragment: Fragment,
Lazy: Lazy,
Memo: Memo,
Portal: Portal,
Profiler: Profiler,
StrictMode: StrictMode,
Suspense: Suspense,
isAsyncMode: isAsyncMode,
isConcurrentMode: isConcurrentMode,
isContextConsumer: isContextConsumer,
isContextProvider: isContextProvider,
isElement: isElement,
isForwardRef: isForwardRef,
isFragment: isFragment,
isLazy: isLazy,
isMemo: isMemo,
isPortal: isPortal,
isProfiler: isProfiler,
isStrictMode: isStrictMode,
isSuspense: isSuspense,
isValidElementType: isValidElementType,
typeOf: typeOf
};
var reactIs_development = createCommonjsModule(function (module, exports) {
});
var reactIs_development_1 = reactIs_development.AsyncMode;
var reactIs_development_2 = reactIs_development.ConcurrentMode;
var reactIs_development_3 = reactIs_development.ContextConsumer;
var reactIs_development_4 = reactIs_development.ContextProvider;
var reactIs_development_5 = reactIs_development.Element;
var reactIs_development_6 = reactIs_development.ForwardRef;
var reactIs_development_7 = reactIs_development.Fragment;
var reactIs_development_8 = reactIs_development.Lazy;
var reactIs_development_9 = reactIs_development.Memo;
var reactIs_development_10 = reactIs_development.Portal;
var reactIs_development_11 = reactIs_development.Profiler;
var reactIs_development_12 = reactIs_development.StrictMode;
var reactIs_development_13 = reactIs_development.Suspense;
var reactIs_development_14 = reactIs_development.isAsyncMode;
var reactIs_development_15 = reactIs_development.isConcurrentMode;
var reactIs_development_16 = reactIs_development.isContextConsumer;
var reactIs_development_17 = reactIs_development.isContextProvider;
var reactIs_development_18 = reactIs_development.isElement;
var reactIs_development_19 = reactIs_development.isForwardRef;
var reactIs_development_20 = reactIs_development.isFragment;
var reactIs_development_21 = reactIs_development.isLazy;
var reactIs_development_22 = reactIs_development.isMemo;
var reactIs_development_23 = reactIs_development.isPortal;
var reactIs_development_24 = reactIs_development.isProfiler;
var reactIs_development_25 = reactIs_development.isStrictMode;
var reactIs_development_26 = reactIs_development.isSuspense;
var reactIs_development_27 = reactIs_development.isValidElementType;
var reactIs_development_28 = reactIs_development.typeOf;
var reactIs = createCommonjsModule(function (module) {
{
module.exports = reactIs_production_min;
}
});
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
} // Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
} // https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
} // https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
var has = Function.call.bind(Object.prototype.hasOwnProperty);
function emptyFunction() {}
function emptyFunctionWithReset() {}
emptyFunctionWithReset.resetWarningCache = emptyFunction;
var factoryWithThrowingShims = function factoryWithThrowingShims() {
function shim(props, propName, componentName, location, propFullName, secret) {
if (secret === ReactPropTypesSecret_1) {
// It is still safe when called from React.
return;
}
var err = new Error('Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use PropTypes.checkPropTypes() to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
err.name = 'Invariant Violation';
throw err;
}
shim.isRequired = shim;
function getShim() {
return shim;
}
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,
any: shim,
arrayOf: getShim,
element: shim,
elementType: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim,
exact: getShim,
checkPropTypes: emptyFunctionWithReset,
resetWarningCache: emptyFunction
};
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
var propTypes = createCommonjsModule(function (module) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
{
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = factoryWithThrowingShims();
}
});
var classnames = createCommonjsModule(function (module) {
/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/* global define */
(function () {
var hasOwn = {}.hasOwnProperty;
function classNames() {
var classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;
var argType = typeof arg;
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg) && arg.length) {
var inner = classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
} else if (argType === 'object') {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}
if ( module.exports) {
classNames.default = classNames;
module.exports = classNames;
} else {
window.classNames = classNames;
}
})();
});
var LOAD_START = 'video-react/LOAD_START';
var CAN_PLAY = 'video-react/CAN_PLAY';
var WAITING = 'video-react/WAITING';
var CAN_PLAY_THROUGH = 'video-react/CAN_PLAY_THROUGH';
var PLAYING = 'video-react/PLAYING';
var PLAY = 'video-react/PLAY';
var PAUSE = 'video-react/PAUSE';
var END = 'video-react/END';
var SEEKING = 'video-react/SEEKING';
var SEEKED = 'video-react/SEEKED';
var SEEKING_TIME = 'video-react/SEEKING_TIME';
var END_SEEKING = 'video-react/END_SEEKING';
var DURATION_CHANGE = 'video-react/DURATION_CHANGE';
var TIME_UPDATE = 'video-react/TIME_UPDATE';
var VOLUME_CHANGE = 'video-react/VOLUME_CHANGE';
var PROGRESS_CHANGE = 'video-react/PROGRESS_CHANGE';
var RATE_CHANGE = 'video-react/RATE_CHANGE';
var SUSPEND = 'video-react/SUSPEND';
var ABORT = 'video-react/ABORT';
var EMPTIED = 'video-react/EMPTIED';
var STALLED = 'video-react/STALLED';
var LOADED_META_DATA = 'video-react/LOADED_META_DATA';
var LOADED_DATA = 'video-react/LOADED_DATA';
var RESIZE = 'video-react/RESIZE';
var ERROR = 'video-react/ERROR';
var ACTIVATE_TEXT_TRACK = 'video-react/ACTIVATE_TEXT_TRACK';
function handleLoadStart(videoProps) {
return {
type: LOAD_START,
videoProps: videoProps
};
}
function handleCanPlay(videoProps) {
return {
type: CAN_PLAY,
videoProps: videoProps
};
}
function handleWaiting(videoProps) {
return {
type: WAITING,
videoProps: videoProps
};
}
function handleCanPlayThrough(videoProps) {
return {
type: CAN_PLAY_THROUGH,
videoProps: videoProps
};
}
function handlePlaying(videoProps) {
return {
type: PLAYING,
videoProps: videoProps
};
}
function handlePlay(videoProps) {
return {
type: PLAY,
videoProps: videoProps
};
}
function handlePause(videoProps) {
return {
type: PAUSE,
videoProps: videoProps
};
}
function handleEnd(videoProps) {
return {
type: END,
videoProps: videoProps
};
}
function handleSeeking(videoProps) {
return {
type: SEEKING,
videoProps: videoProps
};
}
function handleSeeked(videoProps) {
return {
type: SEEKED,
videoProps: videoProps
};
}
function handleDurationChange(videoProps) {
return {
type: DURATION_CHANGE,
videoProps: videoProps
};
}
function handleTimeUpdate(videoProps) {
return {
type: TIME_UPDATE,
videoProps: videoProps
};
}
function handleVolumeChange(videoProps) {
return {
type: VOLUME_CHANGE,
videoProps: videoProps
};
}
function handleProgressChange(videoProps) {
return {
type: PROGRESS_CHANGE,
videoProps: videoProps
};
}
function handleRateChange(videoProps) {
return {
type: RATE_CHANGE,
videoProps: videoProps
};
}
function handleSuspend(videoProps) {
return {
type: SUSPEND,
videoProps: videoProps
};
}
function handleAbort(videoProps) {
return {
type: ABORT,
videoProps: videoProps
};
}
function handleEmptied(videoProps) {
return {
type: EMPTIED,
videoProps: videoProps
};
}
function handleStalled(videoProps) {
return {
type: STALLED,
videoProps: videoProps
};
}
function handleLoadedMetaData(videoProps) {
return {
type: LOADED_META_DATA,
videoProps: videoProps
};
}
function handleLoadedData(videoProps) {
return {
type: LOADED_DATA,
videoProps: videoProps
};
}
function handleResize(videoProps) {
return {
type: RESIZE,
videoProps: videoProps
};
}
function handleError(videoProps) {
return {
type: ERROR,
videoProps: videoProps
};
}
function handleSeekingTime(time) {
return {
type: SEEKING_TIME,
time: time
};
}
function handleEndSeeking(time) {
return {
type: END_SEEKING,
time: time
};
}
function activateTextTrack(textTrack) {
return {
type: ACTIVATE_TEXT_TRACK,
textTrack: textTrack
};
}
var videoActions = /*#__PURE__*/Object.freeze({
__proto__: null,
LOAD_START: LOAD_START,
CAN_PLAY: CAN_PLAY,
WAITING: WAITING,
CAN_PLAY_THROUGH: CAN_PLAY_THROUGH,
PLAYING: PLAYING,
PLAY: PLAY,
PAUSE: PAUSE,
END: END,
SEEKING: SEEKING,
SEEKED: SEEKED,
SEEKING_TIME: SEEKING_TIME,
END_SEEKING: END_SEEKING,
DURATION_CHANGE: DURATION_CHANGE,
TIME_UPDATE: TIME_UPDATE,
VOLUME_CHANGE: VOLUME_CHANGE,
PROGRESS_CHANGE: PROGRESS_CHANGE,
RATE_CHANGE: RATE_CHANGE,
SUSPEND: SUSPEND,
ABORT: ABORT,
EMPTIED: EMPTIED,
STALLED: STALLED,
LOADED_META_DATA: LOADED_META_DATA,
LOADED_DATA: LOADED_DATA,
RESIZE: RESIZE,
ERROR: ERROR,
ACTIVATE_TEXT_TRACK: ACTIVATE_TEXT_TRACK,
handleLoadStart: handleLoadStart,
handleCanPlay: handleCanPlay,
handleWaiting: handleWaiting,
handleCanPlayThrough: handleCanPlayThrough,
handlePlaying: handlePlaying,
handlePlay: handlePlay,
handlePause: handlePause,
handleEnd: handleEnd,
handleSeeking: handleSeeking,
handleSeeked: handleSeeked,
handleDurationChange: handleDurationChange,
handleTimeUpdate: handleTimeUpdate,
handleVolumeChange: handleVolumeChange,
handleProgressChange: handleProgressChange,
handleRateChange: handleRateChange,
handleSuspend: handleSuspend,
handleAbort: handleAbort,
handleEmptied: handleEmptied,
handleStalled: handleStalled,
handleLoadedMetaData: handleLoadedMetaData,
handleLoadedData: handleLoadedData,
handleResize: handleResize,
handleError: handleError,
handleSeekingTime: handleSeekingTime,
handleEndSeeking: handleEndSeeking,
activateTextTrack: activateTextTrack
});
var Fullscreen = /*#__PURE__*/function () {
function Fullscreen() {}
var _proto = Fullscreen.prototype;
_proto.request = function request(elm) {
if (elm.requestFullscreen) {
elm.requestFullscreen();
} else if (elm.webkitRequestFullscreen) {
elm.webkitRequestFullscreen();
} else if (elm.mozRequestFullScreen) {
elm.mozRequestFullScreen();
} else if (elm.msRequestFullscreen) {
elm.msRequestFullscreen();
}
};
_proto.exit = function exit() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
};
_proto.addEventListener = function addEventListener(handler, domRef) {
domRef.addEventListener('fullscreenchange', handler);
domRef.addEventListener('webkitfullscreenchange', handler);
domRef.addEventListener('mozfullscreenchange', handler);
domRef.addEventListener('MSFullscreenChange', handler);
};
_proto.removeEventListener = function removeEventListener(handler, domRef) {
domRef.removeEventListener('fullscreenchange', handler);
domRef.removeEventListener('webkitfullscreenchange', handler);
domRef.removeEventListener('mozfullscreenchange', handler);
domRef.removeEventListener('MSFullscreenChange', handler);
};
_createClass(Fullscreen, [{
key: "isFullscreen",
get: function get() {
return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
}
}, {
key: "enabled",
get: function get() {
return document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled;
}
}]);
return Fullscreen;
}();
var fullscreen = new Fullscreen();
var OPERATE = 'video-react/OPERATE';
var FULLSCREEN_CHANGE = 'video-react/FULLSCREEN_CHANGE';
var PLAYER_ACTIVATE = 'video-react/PLAYER_ACTIVATE';
var USER_ACTIVATE = 'video-react/USER_ACTIVATE';
function handleFullscreenChange(isFullscreen) {
return {
type: FULLSCREEN_CHANGE,
isFullscreen: isFullscreen
};
}
function activate(activity) {
return {
type: PLAYER_ACTIVATE,
activity: activity
};
}
function userActivate(activity) {
return {
type: USER_ACTIVATE,
activity: activity
};
}
function play(operation) {
if (operation === void 0) {
operation = {
action: 'play',
source: ''
};
}
this.video.play();
return {
type: OPERATE,
operation: operation
};
}
function pause(operation) {
if (operation === void 0) {
operation = {
action: 'pause',
source: ''
};
}
this.video.pause();
return {
type: OPERATE,
operation: operation
};
}
function togglePlay(operation) {
if (operation === void 0) {
operation = {
action: 'toggle-play',
source: ''
};
}
this.video.togglePlay();
return {
type: OPERATE,
operation: operation
};
} // seek video by time
function seek(time, operation) {
if (operation === void 0) {
operation = {
action: 'seek',
source: ''
};
}
this.video.seek(time);
return {
type: OPERATE,
operation: operation
};
} // jump forward x seconds
function forward(seconds, operation) {
if (operation === void 0) {
operation = {
action: "forward-" + seconds,
source: ''
};
}
this.video.forward(seconds);
return {
type: OPERATE,
operation: operation
};
} // jump back x seconds
function replay(seconds, operation) {
if (operation === void 0) {
operation = {
action: "replay-" + seconds,
source: ''
};
}
this.video.replay(seconds);
return {
type: OPERATE,
operation: operation
};
}
function changeRate(rate, operation) {
if (operation === void 0) {
operation = {
action: 'change-rate',
source: ''
};
}
this.video.playbackRate = rate;
return {
type: OPERATE,
operation: operation
};
}
function changeVolume(volume, operation) {
if (operation === void 0) {
operation = {
action: 'change-volume',
source: ''
};
}
var v = volume;
if (volume < 0) {
v = 0;
}
if (volume > 1) {
v = 1;
}
this.video.volume = v;
return {
type: OPERATE,
operation: operation
};
}
function mute(muted, operation) {
if (operation === void 0) {
operation = {
action: muted ? 'muted' : 'unmuted',
source: ''
};
}
this.video.muted = muted;
return {
type: OPERATE,
operation: operation
};
}
function toggleFullscreen(player) {
if (fullscreen.enabled) {
if (fullscreen.isFullscreen) {
fullscreen.exit();
} else {
fullscreen.request(this.rootElement);
}
return {
type: OPERATE,
operation: {
action: 'toggle-fullscreen',
source: ''
}
};
}
return {
type: FULLSCREEN_CHANGE,
isFullscreen: !player.isFullscreen
};
}
var playerActions = /*#__PURE__*/Object.freeze({
__proto__: null,
OPERATE: OPERATE,
FULLSCREEN_CHANGE: FULLSCREEN_CHANGE,
PLAYER_ACTIVATE: PLAYER_ACTIVATE,
USER_ACTIVATE: USER_ACTIVATE,
handleFullscreenChange: handleFullscreenChange,
activate: activate,
userActivate: userActivate,
play: play,
pause: pause,
togglePlay: togglePlay,
seek: seek,
forward: forward,
replay: replay,
changeRate: changeRate,
changeVolume: changeVolume,
mute: mute,
toggleFullscreen: toggleFullscreen
});
var initialState = {
currentSrc: null,
duration: 0,
currentTime: 0,
seekingTime: 0,
buffered: null,
waiting: false,
seeking: false,
paused: true,
autoPaused: false,
ended: false,
playbackRate: 1,
muted: false,
volume: 1,
readyState: 0,
networkState: 0,
videoWidth: 0,
videoHeight: 0,
hasStarted: false,
userActivity: true,
isActive: false,
isFullscreen: false,
activeTextTrack: null
};
function player(state, action) {
if (state === void 0) {
state = initialState;
}
switch (action.type) {
case USER_ACTIVATE:
return _extends({}, state, {
userActivity: action.activity
});
case PLAYER_ACTIVATE:
return _extends({}, state, {
isActive: action.activity
});
case FULLSCREEN_CHANGE:
return _extends({}, state, {
isFullscreen: !!action.isFullscreen
});
case SEEKING_TIME:
return _extends({}, state, {
seekingTime: action.time
});
case END_SEEKING:
return _extends({}, state, {
seekingTime: 0
});
case LOAD_START:
return _extends({}, state, action.videoProps, {
hasStarted: false,
ended: false
});
case CAN_PLAY:
return _extends({}, state, action.videoProps, {
waiting: false
});
case WAITING:
return _extends({}, state, action.videoProps, {
waiting: true
});
case CAN_PLAY_THROUGH:
case PLAYING:
return _extends({}, state, action.videoProps, {
waiting: false
});
case PLAY:
return _extends({}, state, action.videoProps, {
ended: false,
paused: false,
autoPaused: false,
waiting: false,
hasStarted: true
});
case PAUSE:
return _extends({}, state, action.videoProps, {
paused: true
});
case END:
return _extends({}, state, action.videoProps, {
ended: true
});
case SEEKING:
return _extends({}, state, action.videoProps, {
seeking: true
});
case SEEKED:
return _extends({}, state, action.videoProps, {
seeking: false
});
case ERROR:
return _extends({}, state, action.videoProps, {
error: 'UNKNOWN ERROR',
ended: true
});
case DURATION_CHANGE:
case TIME_UPDATE:
case VOLUME_CHANGE:
case PROGRESS_CHANGE:
case RATE_CHANGE:
case SUSPEND:
case ABORT:
case EMPTIED:
case STALLED:
case LOADED_META_DATA:
case LOADED_DATA:
case RESIZE:
return _extends({}, state, action.videoProps);
case ACTIVATE_TEXT_TRACK:
return _extends({}, state, {
activeTextTrack: action.textTrack
});
default:
return state;
}
}
var initialState$1 = {
count: 0,
operation: {
action: '',
source: ''
}
};
function operation(state, action) {
if (state === void 0) {
state = initialState$1;
}
switch (action.type) {
case OPERATE:
return _extends({}, state, {
count: state.count + 1,
operation: _extends({}, state.operation, action.operation)
});
default:
return state;
}
}
function reducer (state, action) {
if (state === void 0) {
state = {};
}
return {
player: player(state.player, action),
operation: operation(state.operation, action)
};
}
var playerReducer = player;
var operationReducer = operation;
var Manager = /*#__PURE__*/function () {
function Manager(store) {
this.store = store || redux.createStore(reducer);
this.video = null;
this.rootElement = null;
}
var _proto = Manager.prototype;
_proto.getActions = function getActions() {
var manager = this;
var dispatch = this.store.dispatch;
var actions = _extends({}, playerActions, videoActions);
function bindActionCreator(actionCreator) {
return function bindAction() {
// eslint-disable-next-line prefer-rest-params
var action = actionCreator.apply(manager, arguments);
if (typeof action !== 'undefined') {
dispatch(action);
}
};
}
return Object.keys(actions).filter(function (key) {
return typeof actions[key] === 'function';
}).reduce(function (boundActions, key) {
boundActions[key] = bindActionCreator(actions[key]);
return boundActions;
}, {});
};
_proto.getState = function getState() {
return this.store.getState();
} // subscribe state change
;
_proto.subscribeToStateChange = function subscribeToStateChange(listener, getState) {
if (!getState) {
getState = this.getState.bind(this);
}
var prevState = getState();
var handleChange = function handleChange() {
var state = getState();
if (state === prevState) {
return;
}
var prevStateCopy = prevState;
prevState = state;
listener(state, prevStateCopy);
};
return this.store.subscribe(handleChange);
} // subscribe to operation state change
;
_proto.subscribeToOperationStateChange = function subscribeToOperationStateChange(listener) {
var _this = this;
return this.subscribeToStateChange(listener, function () {
return _this.getState().operation;
});
} // subscribe to player state change
;
_proto.subscribeToPlayerStateChange = function subscribeToPlayerStateChange(listener) {
var _this2 = this;
return this.subscribeToStateChange(listener, function () {
return _this2.getState().player;
});
};
return Manager;
}();
var propTypes$1 = {
actions: propTypes.object,
player: propTypes.object,
position: propTypes.string,
className: propTypes.string
};
var defaultProps = {
position: 'left'
};
var BigPlayButton = /*#__PURE__*/function (_Component) {
_inheritsLoose(BigPlayButton, _Component);
function BigPlayButton(props, context) {
var _this;
_this = _Component.call(this, props, context) || this;
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
return _this;
}
var _proto = BigPlayButton.prototype;
_proto.componentDidMount = function componentDidMount() {};
_proto.handleClick = function handleClick() {
var actions = this.props.actions;
actions.play();
};
_proto.render = function render() {
var _this$props = this.props,
player = _this$props.player,
position = _this$props.position;
return /*#__PURE__*/React__default.createElement("button", {
className: classnames('video-react-button', 'video-react-big-play-button', "video-react-big-play-button-" + position, this.props.className, {
'big-play-button-hide': player.hasStarted || !player.currentSrc
}),
type: "button",
"aria-live": "polite",
tabIndex: "0",
onClick: this.handleClick
}, /*#__PURE__*/React__default.createElement("span", {
className: "video-react-control-text"
}, "Play Video"));
};
return BigPlayButton;
}(React.Component);
BigPlayButton.propTypes = propTypes$1;
BigPlayButton.defaultProps = defaultProps;
BigPlayButton.displayName = 'BigPlayButton';
var propTypes$2 = {
player: propTypes.object,
className: propTypes.string
};
function LoadingSpinner(_ref) {
var player = _ref.player,
className = _ref.className;
if (player.error) {
return null;
}
return /*#__PURE__*/React__default.createElement("div", {
className: classnames('video-react-loading-spinner', className)
});
}
LoadingSpinner.propTypes = propTypes$2;
LoadingSpinner.displayName = 'LoadingSpinner';
var propTypes$3 = {
poster: propTypes.string,
player: propTypes.object,
actions: propTypes.object,
className: propTypes.string
};
function PosterImage(_ref) {
var poster = _ref.poster,
player = _ref.player,
actions = _ref.actions,
className = _ref.className;
if (!poster || player.hasStarted) {
return null;
}
return /*#__PURE__*/React__default.createElement("div", {
className: classnames('video-react-poster', className),
style: {
backgroundImage: "url(\"" + poster + "\")"
},
onClick: function onClick() {
if (player.paused) {
actions.play();
}
}
});
}
PosterImage.propTypes = propTypes$3;
PosterImage.displayName = 'PosterImage';
// eslint-disable-next-line no-self-compare
var isNaN = Number.isNaN || function (value) {
return value !== value;
};
/**
* @file format-time.js
*
* Format seconds as a time string, H:MM:SS or M:SS
* Supplying a guide (in seconds) will force a number of leading zeros
* to cover the length of the guide
*
* @param {Number} seconds Number of seconds to be turned into a string
* @param {Number} guide Number (in seconds) to model the string after
* @return {String} Time formatted as H:MM:SS or M:SS
* @private
* @function formatTime
*/
function formatTime(seconds, guide) {
if (seconds === void 0) {
seconds = 0;
}
if (guide === void 0) {
guide = seconds;
}
var s = Math.floor(seconds % 60);
var m = Math.floor(seconds / 60 % 60);
var h = Math.floor(seconds / 3600);
var gm = Math.floor(guide / 60 % 60);
var gh = Math.floor(guide / 3600); // handle invalid times
if (isNaN(seconds) || seconds === Infinity) {
// '-' is false for all relational operators (e.g. <, >=) so this setting
// will add the minimum number of fields specified by the guide
h = '-';
m = '-';
s = '-';
} // Check if we need to show hours
h = h > 0 || gh > 0 ? h + ":" : ''; // If hours are showing, we may need to add a leading zero.
// Always show at least one digit of minutes.
m = ((h || gm >= 10) && m < 10 ? "0" + m : m) + ":"; // Check if leading zero is need for seconds
s = s < 10 ? "0" + s : s;
return h + m + s;
} // Check if the element belongs to a video element
// only accept <source />, <track />,
// <MyComponent isVideoChild />
// elements
function isVideoChild(c) {
if (c.props && c.props.isVideoChild) {
return true;
}
return c.type === 'source' || c.type === 'track';
}
var find = function find(elements, func) {
return elements.filter(func)[0];
}; // check if two components are the same type
var isTypeEqual = function isTypeEqual(component1, component2) {
var type1 = component1.type;
var type2 = component2.type;
if (typeof type1 === 'string' || typeof type2 === 'string') {
return type1 === type2;
}
if (typeof type1 === 'function' && typeof type2 === 'function') {
return type1.displayName === type2.displayName;
}
return false;
}; // merge default children
// sort them by `order` property
// filter them by `disabled` property
function mergeAndSortChildren(defaultChildren, _children, _parentProps, defaultOrder) {
if (defaultOrder === void 0) {
defaultOrder = 1;
}
var children = React__default.Children.toArray(_children);
var order = _parentProps.order,
parentProps = _objectWithoutPropertiesLoose(_parentProps, ["order"]); // ignore order from parent
return children.filter(function (e) {
return !e.props.disabled;
}) // filter the disabled components
.concat(defaultChildren.filter(function (c) {
return !find(children, function (component) {
return isTypeEqual(component, c);
});
})).map(function (element) {
var defaultComponent = find(defaultChildren, function (c) {
return isTypeEqual(c, element);
});
var defaultProps = defaultComponent ? defaultComponent.props : {};
var props = _extends({}, parentProps, defaultProps, element.props);
var e = /*#__PURE__*/React__default.cloneElement(element, props, element.props.children);
return e;
}).sort(function (a, b) {
return (a.props.order || defaultOrder) - (b.props.order || defaultOrder);
});
}
/**
* Temporary utility for generating the warnings
*/
function deprecatedWarning(oldMethodCall, newMethodCall) {
// eslint-disable-next-line no-console
console.warn("WARNING: " + oldMethodCall + " will be deprecated soon! Please use " + newMethodCall + " instead.");
}
function throttle(callback, limit) {
var _arguments = arguments;
var wait = false;
return function () {
if (!wait) {
// eslint-disable-next-line prefer-rest-params
callback.apply(void 0, _arguments);
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
};
}
var mediaProperties = ['error', 'src', 'srcObject', 'currentSrc', 'crossOrigin', 'networkState', 'preload', 'buffered', 'readyState', 'seeking', 'currentTime', 'duration', 'paused', 'defaultPlaybackRate', 'playbackRate', 'played', 'seekable', 'ended', 'autoplay', 'loop', 'mediaGroup', 'controller', 'controls', 'volume', 'muted', 'defaultMuted', 'audioTracks', 'videoTracks', 'textTracks', 'width', 'height', 'videoWidth', 'videoHeight', 'poster'];
var propTypes$4 = {
actions: propTypes.object,
player: propTypes.object,
children: propTypes.any,
startTime: propTypes.number,
loop: propTypes.bool,
muted: propTypes.bool,
autoPlay: propTypes.bool,
playsInline: propTypes.bool,
src: propTypes.string,
poster: propTypes.string,
className: propTypes.string,
preload: propTypes.oneOf(['auto', 'metadata', 'none']),
crossOrigin: propTypes.string,
onLoadStart: propTypes.func,
onWaiting: propTypes.func,
onCanPlay: propTypes.func,
onCanPlayThrough: propTypes.func,
onPlaying: propTypes.func,
onEnded: propTypes.func,
onSeeking: propTypes.func,
onSeeked: propTypes.func,
onPlay: propTypes.func,
onPause: propTypes.func,
onProgress: propTypes.func,
onDurationChange: propTypes.func,
onError: propTypes.func,
onSuspend: propTypes.func,
onAbort: propTypes.func,
onEmptied: propTypes.func,
onStalled: propTypes.func,
onLoadedMetadata: propTypes.func,
onLoadedData: propTypes.func,
onTimeUpdate: propTypes.func,
onRateChange: propTypes.func,
onVolumeChange: propTypes.func,
onResize: propTypes.func
};
var Video = /*#__PURE__*/function (_Component) {
_inheritsLoose(Video, _Component);
function Video(props) {
var _this;
_this = _Component.call(this, props) || this;
_this.video = null; // the html5 video
_this.play = _this.play.bind(_assertThisInitialized(_this));
_this.pause = _this.pause.bind(_assertThisInitialized(_this));
_this.seek = _this.seek.bind(_assertThisInitialized(_this));
_this.forward = _this.forward.bind(_assertThisInitialized(_this));
_this.replay = _this.replay.bind(_assertThisInitialized(_this));
_this.toggleFullscreen = _this.toggleFullscreen.bind(_assertThisInitialized(_this));
_this.getProperties = _this.getProperties.bind(_assertThisInitialized(_this));
_this.renderChildren = _this.renderChildren.bind(_assertThisInitialized(_this));
_this.handleLoadStart = _this.handleLoadStart.bind(_assertThisInitialized(_this));
_this.handleCanPlay = _this.handleCanPlay.bind(_assertThisInitialized(_this));
_this.handleCanPlayThrough = _this.handleCanPlayThrough.bind(_assertThisInitialized(_this));
_this.handlePlay = _this.handlePlay.bind(_assertThisInitialized(_this));
_this.handlePlaying = _this.handlePlaying.bind(_assertThisInitialized(_this));
_this.handlePause = _this.handlePause.bind(_assertThisInitialized(_this));
_this.handleEnded = _this.handleEnded.bind(_assertThisInitialized(_this));
_this.handleWaiting = _this.handleWaiting.bind(_assertThisInitialized(_this));
_this.handleSeeking = _this.handleSeeking.bind(_assertThisInitialized(_this));
_this.handleSeeked = _this.handleSeeked.bind(_assertThisInitialized(_this));
_this.handleFullscreenChange = _this.handleFullscreenChange.bind(_assertThisInitialized(_this));
_this.handleError = _this.handleError.bind(_assertThisInitialized(_this));
_this.handleSuspend = _this.handleSuspend.bind(_assertThisInitialized(_this));
_this.handleAbort = _this.handleAbort.bind(_assertThisInitialized(_this));
_this.handleEmptied = _this.handleEmptied.bind(_assertThisInitialized(_this));
_this.handleStalled = _this.handleStalled.bind(_assertThisInitialized(_this));
_this.handleLoadedMetaData = _this.handleLoadedMetaData.bind(_assertThisInitialized(_this));
_this.handleLoadedData = _this.handleLoadedData.bind(_assertThisInitialized(_this));
_this.handleTimeUpdate = _this.handleTimeUpdate.bind(_assertThisInitialized(_this));
_this.handleRateChange = _this.handleRateChange.bind(_assertThisInitialized(_this));
_this.handleVolumeChange = _this.handleVolumeChange.bind(_assertThisInitialized(_this));
_this.handleDurationChange = _this.handleDurationChange.bind(_assertThisInitialized(_this));
_this.handleProgress = throttle(_this.handleProgress.bind(_assertThisInitialized(_this)), 250);
_this.handleKeypress = _this.handleKeypress.bind(_assertThisInitialized(_this));
_this.handleTextTrackChange = _this.handleTextTrackChange.bind(_assertThisInitialized(_this));
return _this;
}
var _proto = Video.prototype;
_proto.componentDidMount = function componentDidMount() {
this.forceUpdate(); // make sure the children can get the video property
if (this.video && this.video.textTracks) {
this.video.textTracks.onaddtrack = this.handleTextTrackChange;
this.video.textTracks.onremovetrack = this.handleTextTrackChange;
}
} // get all video properties
;
_proto.getProperties = function getProperties() {
var _this2 = this;
if (!this.video) {
return null;
}
return mediaProperties.reduce(function (properties, key) {
properties[key] = _this2.video[key];
return properties;
}, {});
} // get playback rate
;
_proto.handleTextTrackChange = function handleTextTrackChange() {
var _this$props = this.props,
actions = _this$props.actions,
player = _this$props.player;
if (this.video && this.video.textTracks) {
var activeTextTrack = Array.from(this.video.textTracks).find(function (textTrack) {
return textTrack.mode === 'showing';
});
if (activeTextTrack !== player.activeTextTrack) {
actions.activateTextTrack(activeTextTrack);
}
}
} // play the video
;
_proto.play = function play() {
var promise = this.video.play();
if (promise !== undefined) {
promise.catch(function () {}).then(function () {});
}
} // pause the video
;
_proto.pause = function pause() {
var promise = this.video.pause();
if (promise !== undefined) {
promise.catch(function () {}).then(function () {});
}
} // Change the video source and re-load the video:
;
_proto.load = function load() {
this.video.load();
} // Add a new text track to the video
;
_proto.addTextTrack = function addTextTrack() {
var _this$video;
(_this$video = this.video).addTextTrack.apply(_this$video, arguments);
} // Check if your browser can play different types of video:
;
_proto.canPlayType = function canPlayType() {
var _this$video2;
(_this$video2 = this.video).canPlayType.apply(_this$video2, arguments);
} // toggle play
;
_proto.togglePlay = function togglePlay() {
if (this.video.paused) {
this.play();
} else {
this.pause();
}
} // seek video by time
;
_proto.seek = function seek(time) {
try {
this.video.currentTime = time;
} catch (e) {// console.log(e, 'Video is not ready.')
}
} // jump forward x seconds
;
_proto.forward = function forward(seconds) {
this.seek(this.video.currentTime + seconds);
} // jump back x seconds
;
_proto.replay = function replay(seconds) {
this.forward(-seconds);
} // enter or exist full screen
;
_proto.toggleFullscreen = function toggleFullscreen() {
var _this$props2 = this.props,
player = _this$props2.player,
actions = _this$props2.actions;
actions.toggleFullscreen(player);
} // Fired when the user agent
// begins looking for media data
;
_proto.handleLoadStart = function handleLoadStart() {
var _this$props3 = this.props,
actions = _this$props3.actions,
onLoadStart = _this$props3.onLoadStart;
actions.handleLoadStart(this.getProperties());
if (onLoadStart) {
onLoadStart.apply(void 0, arguments);
}
} // A handler for events that
// signal that waiting has ended
;
_proto.handleCanPlay = function handleCanPlay() {
var _this$props4 = this.props,
actions = _this$props4.actions,
onCanPlay = _this$props4.onCanPlay;
actions.handleCanPlay(this.getProperties());
if (onCanPlay) {
onCanPlay.apply(void 0, arguments);
}
} // A handler for events that
// signal that waiting has ended
;
_proto.handleCanPlayThrough = function handleCanPlayThrough() {
var _this$props5 = this.props,
actions = _this$props5.actions,
onCanPlayThrough = _this$props5.onCanPlayThrough;
actions.handleCanPlayThrough(this.getProperties());
if (onCanPlayThrough) {
onCanPlayThrough.apply(void 0, arguments);
}
} // A handler for events that
// signal that waiting has ended
;
_proto.handlePlaying = function handlePlaying() {
var _this$props6 = this.props,
actions = _this$props6.actions,
onPlaying = _this$props6.onPlaying;
actions.handlePlaying(this.getProperties());
if (onPlaying) {
onPlaying.apply(void 0, arguments);
}
} // Fired whenever the media has been started
;
_proto.handlePlay = function handlePlay() {
var _this$props7 = this.props,
actions = _this$props7.actions,
onPlay = _this$props7.onPlay;
actions.handlePlay(this.getProperties());
if (onPlay) {
onPlay.apply(void 0, arguments);
}
} // Fired whenever the media has been paused
;
_proto.handlePause = function handlePause() {
var _this$props8 = this.props,
actions = _this$props8.actions,
onPause = _this$props8.onPause;
actions.handlePause(this.getProp