UNPKG

wotnot-video-react

Version:

Video-React is a web video player built from the ground up for an HTML5 world using React library.

1,775 lines (1,536 loc) 166 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : (global = global || self, factory(global['video-react'] = {}, global.React)); }(this, (function (exports, React) { '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; } })(); }); function symbolObservablePonyfill(root) { var result; var Symbol = root.Symbol; if (typeof Symbol === 'function') { if (Symbol.observable) { result = Symbol.observable; } else { result = Symbol('observable'); Symbol.observable = result; } } else { result = '@@observable'; } return result; } /* global window */ var root; if (typeof self !== 'undefined') { root = self; } else if (typeof window !== 'undefined') { root = window; } else if (typeof global !== 'undefined') { root = global; } else if (typeof module !== 'undefined') { root = module; } else { root = Function('return this')(); } var result = symbolObservablePonyfill(root); /** * These are private action types reserved by Redux. * For any unknown actions, you must return the current state. * If the current state is undefined, you must return the initial state. * Do not reference these action types directly in your code. */ var randomString = function randomString() { return Math.random().toString(36).substring(7).split('').join('.'); }; var ActionTypes = { INIT: "@@redux/INIT" + randomString(), REPLACE: "@@redux/REPLACE" + randomString(), PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); } }; /** * @param {any} obj The object to inspect. * @returns {boolean} True if the argument appears to be a plain object. */ function isPlainObject(obj) { if (typeof obj !== 'object' || obj === null) return false; var proto = obj; while (Object.getPrototypeOf(proto) !== null) { proto = Object.getPrototypeOf(proto); } return Object.getPrototypeOf(obj) === proto; } /** * Creates a Redux store that holds the state tree. * The only way to change the data in the store is to call `dispatch()` on it. * * There should only be a single store in your app. To specify how different * parts of the state tree respond to actions, you may combine several reducers * into a single reducer function by using `combineReducers`. * * @param {Function} reducer A function that returns the next state tree, given * the current state tree and the action to handle. * * @param {any} [preloadedState] The initial state. You may optionally specify it * to hydrate the state from the server in universal apps, or to restore a * previously serialized user session. * If you use `combineReducers` to produce the root reducer function, this must be * an object with the same shape as `combineReducers` keys. * * @param {Function} [enhancer] The store enhancer. You may optionally specify it * to enhance the store with third-party capabilities such as middleware, * time travel, persistence, etc. The only store enhancer that ships with Redux * is `applyMiddleware()`. * * @returns {Store} A Redux store that lets you read the state, dispatch actions * and subscribe to changes. */ function createStore(reducer, preloadedState, enhancer) { var _ref2; if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function.'); } if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { enhancer = preloadedState; preloadedState = undefined; } if (typeof enhancer !== 'undefined') { if (typeof enhancer !== 'function') { throw new Error('Expected the enhancer to be a function.'); } return enhancer(createStore)(reducer, preloadedState); } if (typeof reducer !== 'function') { throw new Error('Expected the reducer to be a function.'); } var currentReducer = reducer; var currentState = preloadedState; var currentListeners = []; var nextListeners = currentListeners; var isDispatching = false; /** * This makes a shallow copy of currentListeners so we can use * nextListeners as a temporary list while dispatching. * * This prevents any bugs around consumers calling * subscribe/unsubscribe in the middle of a dispatch. */ function ensureCanMutateNextListeners() { if (nextListeners === currentListeners) { nextListeners = currentListeners.slice(); } } /** * Reads the state tree managed by the store. * * @returns {any} The current state tree of your application. */ function getState() { if (isDispatching) { throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.'); } return currentState; } /** * Adds a change listener. It will be called any time an action is dispatched, * and some part of the state tree may potentially have changed. You may then * call `getState()` to read the current state tree inside the callback. * * You may call `dispatch()` from a change listener, with the following * caveats: * * 1. The subscriptions are snapshotted just before every `dispatch()` call. * If you subscribe or unsubscribe while the listeners are being invoked, this * will not have any effect on the `dispatch()` that is currently in progress. * However, the next `dispatch()` call, whether nested or not, will use a more * recent snapshot of the subscription list. * * 2. The listener should not expect to see all state changes, as the state * might have been updated multiple times during a nested `dispatch()` before * the listener is called. It is, however, guaranteed that all subscribers * registered before the `dispatch()` started will be called with the latest * state by the time it exits. * * @param {Function} listener A callback to be invoked on every dispatch. * @returns {Function} A function to remove this change listener. */ function subscribe(listener) { if (typeof listener !== 'function') { throw new Error('Expected the listener to be a function.'); } if (isDispatching) { throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api-reference/store#subscribelistener for more details.'); } var isSubscribed = true; ensureCanMutateNextListeners(); nextListeners.push(listener); return function unsubscribe() { if (!isSubscribed) { return; } if (isDispatching) { throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api-reference/store#subscribelistener for more details.'); } isSubscribed = false; ensureCanMutateNextListeners(); var index = nextListeners.indexOf(listener); nextListeners.splice(index, 1); currentListeners = null; }; } /** * Dispatches an action. It is the only way to trigger a state change. * * The `reducer` function, used to create the store, will be called with the * current state tree and the given `action`. Its return value will * be considered the **next** state of the tree, and the change listeners * will be notified. * * The base implementation only supports plain object actions. If you want to * dispatch a Promise, an Observable, a thunk, or something else, you need to * wrap your store creating function into the corresponding middleware. For * example, see the documentation for the `redux-thunk` package. Even the * middleware will eventually dispatch plain object actions using this method. * * @param {Object} action A plain object representing “what changed”. It is * a good idea to keep actions serializable so you can record and replay user * sessions, or use the time travelling `redux-devtools`. An action must have * a `type` property which may not be `undefined`. It is a good idea to use * string constants for action types. * * @returns {Object} For convenience, the same action object you dispatched. * * Note that, if you use a custom middleware, it may wrap `dispatch()` to * return something else (for example, a Promise you can await). */ function dispatch(action) { if (!isPlainObject(action)) { throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); } if (typeof action.type === 'undefined') { throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); } if (isDispatching) { throw new Error('Reducers may not dispatch actions.'); } try { isDispatching = true; currentState = currentReducer(currentState, action); } finally { isDispatching = false; } var listeners = currentListeners = nextListeners; for (var i = 0; i < listeners.length; i++) { var listener = listeners[i]; listener(); } return action; } /** * Replaces the reducer currently used by the store to calculate the state. * * You might need this if your app implements code splitting and you want to * load some of the reducers dynamically. You might also need this if you * implement a hot reloading mechanism for Redux. * * @param {Function} nextReducer The reducer for the store to use instead. * @returns {void} */ function replaceReducer(nextReducer) { if (typeof nextReducer !== 'function') { throw new Error('Expected the nextReducer to be a function.'); } currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT. // Any reducers that existed in both the new and old rootReducer // will receive the previous state. This effectively populates // the new state tree with any relevant data from the old one. dispatch({ type: ActionTypes.REPLACE }); } /** * Interoperability point for observable/reactive libraries. * @returns {observable} A minimal observable of state changes. * For more information, see the observable proposal: * https://github.com/tc39/proposal-observable */ function observable() { var _ref; var outerSubscribe = subscribe; return _ref = { /** * The minimal observable subscription method. * @param {Object} observer Any object that can be used as an observer. * The observer object should have a `next` method. * @returns {subscription} An object with an `unsubscribe` method that can * be used to unsubscribe the observable from the store, and prevent further * emission of values from the observable. */ subscribe: function subscribe(observer) { if (typeof observer !== 'object' || observer === null) { throw new TypeError('Expected the observer to be an object.'); } function observeState() { if (observer.next) { observer.next(getState()); } } observeState(); var unsubscribe = outerSubscribe(observeState); return { unsubscribe: unsubscribe }; } }, _ref[result] = function () { return this; }, _ref; } // When a store is created, an "INIT" action is dispatched so that every // reducer returns their initial state. This effectively populates // the initial state tree. dispatch({ type: ActionTypes.INIT }); return _ref2 = { dispatch: dispatch, subscribe: subscribe, getState: getState, replaceReducer: replaceReducer }, _ref2[result] = observable, _ref2; } 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 || 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 element