UNPKG

xom-stream-chat-react

Version:

React components to create chat conversations or livestream style chat

1,512 lines (1,207 loc) 3.16 MB
(function (exports, React, reactDom) { 'use strict'; var React__default = 'default' in React ? React['default'] : React; var reactDom__default = 'default' in reactDom ? reactDom['default'] : reactDom; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function commonjsRequire () { throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); } function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } function getCjsExportFromNamespace (n) { return n && n['default'] || n; } var _extends_1 = createCommonjsModule(function (module) { function _extends() { module.exports = _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); } module.exports = _extends; }); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var classCallCheck = _classCallCheck; 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; } var createClass = _createClass; var _typeof_1 = createCommonjsModule(function (module) { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { module.exports = _typeof = function _typeof(obj) { return typeof obj; }; } else { module.exports = _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } module.exports = _typeof; }); function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } var assertThisInitialized = _assertThisInitialized; function _possibleConstructorReturn(self, call) { if (call && (_typeof_1(call) === "object" || typeof call === "function")) { return call; } return assertThisInitialized(self); } var possibleConstructorReturn = _possibleConstructorReturn; var getPrototypeOf = createCommonjsModule(function (module) { function _getPrototypeOf(o) { module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } module.exports = _getPrototypeOf; }); var setPrototypeOf = createCommonjsModule(function (module) { function _setPrototypeOf(o, p) { module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } module.exports = _setPrototypeOf; }); function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) setPrototypeOf(subClass, superClass); } var inherits = _inherits; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var defineProperty = _defineProperty; /** * 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; function emptyFunction() {} function emptyFunctionWithReset() {} emptyFunctionWithReset.resetWarningCache = emptyFunction; var factoryWithThrowingShims = function() { 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; } // Important! // 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 propTypes_1 = propTypes.array; var propTypes_2 = propTypes.bool; var propTypes_3 = propTypes.func; var propTypes_4 = propTypes.number; var propTypes_5 = propTypes.object; var propTypes_6 = propTypes.string; var propTypes_7 = propTypes.symbol; var propTypes_8 = propTypes.any; var propTypes_9 = propTypes.arrayOf; var propTypes_10 = propTypes.element; var propTypes_11 = propTypes.elementType; var propTypes_12 = propTypes.instanceOf; var propTypes_13 = propTypes.node; var propTypes_14 = propTypes.objectOf; var propTypes_15 = propTypes.oneOf; var propTypes_16 = propTypes.oneOfType; var propTypes_17 = propTypes.shape; var propTypes_18 = propTypes.exact; var propTypes_19 = propTypes.checkPropTypes; var propTypes_20 = propTypes.resetWarningCache; var propTypes_21 = propTypes.PropTypes; var props = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.DEPRECATED_CONFIG_PROPS = exports.defaultProps = exports.propTypes = void 0; var _propTypes = _interopRequireDefault(propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var string = _propTypes["default"].string, bool = _propTypes["default"].bool, number = _propTypes["default"].number, array = _propTypes["default"].array, oneOfType = _propTypes["default"].oneOfType, shape = _propTypes["default"].shape, object = _propTypes["default"].object, func = _propTypes["default"].func, node = _propTypes["default"].node; var propTypes$1 = { url: oneOfType([string, array, object]), playing: bool, loop: bool, controls: bool, volume: number, muted: bool, playbackRate: number, width: oneOfType([string, number]), height: oneOfType([string, number]), style: object, progressInterval: number, playsinline: bool, pip: bool, light: oneOfType([bool, string]), playIcon: node, wrapper: oneOfType([string, func, shape({ render: func.isRequired })]), config: shape({ soundcloud: shape({ options: object, preload: bool }), youtube: shape({ playerVars: object, embedOptions: object, preload: bool }), facebook: shape({ appId: string, version: string, playerId: string }), dailymotion: shape({ params: object, preload: bool }), vimeo: shape({ playerOptions: object, preload: bool }), file: shape({ attributes: object, tracks: array, forceVideo: bool, forceAudio: bool, forceHLS: bool, forceDASH: bool, hlsOptions: object, hlsVersion: string, dashVersion: string }), wistia: shape({ options: object }), mixcloud: shape({ options: object }), twitch: shape({ options: object, playerId: string }) }), onReady: func, onStart: func, onPlay: func, onPause: func, onBuffer: func, onBufferEnd: func, onEnded: func, onError: func, onDuration: func, onSeek: func, onProgress: func, onEnablePIP: func, onDisablePIP: func }; exports.propTypes = propTypes$1; var defaultProps = { playing: false, loop: false, controls: false, volume: null, muted: false, playbackRate: 1, width: '640px', height: '360px', style: {}, progressInterval: 1000, playsinline: false, pip: false, light: false, wrapper: 'div', config: { soundcloud: { options: { visual: true, // Undocumented, but makes player fill container and look better buying: false, liking: false, download: false, sharing: false, show_comments: false, show_playcount: false } }, youtube: { playerVars: { playsinline: 1, showinfo: 0, rel: 0, iv_load_policy: 3, modestbranding: 1 }, embedOptions: {}, preload: false }, facebook: { appId: '1309697205772819', version: 'v3.3', playerId: null }, dailymotion: { params: { api: 1, 'endscreen-enable': false }, preload: false }, vimeo: { playerOptions: { autopause: false, byline: false, portrait: false, title: false }, preload: false }, file: { attributes: {}, tracks: [], forceVideo: false, forceAudio: false, forceHLS: false, forceDASH: false, hlsOptions: {}, hlsVersion: '0.13.1', dashVersion: '2.9.2' }, wistia: { options: {} }, mixcloud: { options: { hide_cover: 1 } }, twitch: { options: {}, playerId: null } }, onReady: function onReady() {}, onStart: function onStart() {}, onPlay: function onPlay() {}, onPause: function onPause() {}, onBuffer: function onBuffer() {}, onBufferEnd: function onBufferEnd() {}, onEnded: function onEnded() {}, onError: function onError() {}, onDuration: function onDuration() {}, onSeek: function onSeek() {}, onProgress: function onProgress() {}, onEnablePIP: function onEnablePIP() {}, onDisablePIP: function onDisablePIP() {} }; exports.defaultProps = defaultProps; var DEPRECATED_CONFIG_PROPS = ['soundcloudConfig', 'youtubeConfig', 'facebookConfig', 'dailymotionConfig', 'vimeoConfig', 'fileConfig', 'wistiaConfig']; exports.DEPRECATED_CONFIG_PROPS = DEPRECATED_CONFIG_PROPS; }); unwrapExports(props); var props_1 = props.DEPRECATED_CONFIG_PROPS; var props_2 = props.defaultProps; var props_3 = props.propTypes; var loadScript = function load (src, opts, cb) { var head = document.head || document.getElementsByTagName('head')[0]; var script = document.createElement('script'); if (typeof opts === 'function') { cb = opts; opts = {}; } opts = opts || {}; cb = cb || function() {}; script.type = opts.type || 'text/javascript'; script.charset = opts.charset || 'utf8'; script.async = 'async' in opts ? !!opts.async : true; script.src = src; if (opts.attrs) { setAttributes(script, opts.attrs); } if (opts.text) { script.text = '' + opts.text; } var onend = 'onload' in script ? stdOnEnd : ieOnEnd; onend(script, cb); // some good legacy browsers (firefox) fail the 'in' detection above // so as a fallback we always set onload // old IE will ignore this and new IE will set onload if (!script.onload) { stdOnEnd(script, cb); } head.appendChild(script); }; function setAttributes(script, attrs) { for (var attr in attrs) { script.setAttribute(attr, attrs[attr]); } } function stdOnEnd (script, cb) { script.onload = function () { this.onerror = this.onload = null; cb(null, script); }; script.onerror = function () { // this.onload = null here is necessary // because even IE9 works not like others this.onerror = this.onload = null; cb(new Error('Failed to load ' + this.src), script); }; } function ieOnEnd (script, cb) { script.onreadystatechange = function () { if (this.readyState != 'complete' && this.readyState != 'loaded') return this.onreadystatechange = null; cb(null, script); // there is no way to catch loading errors in IE8 }; } var isMergeableObject = function isMergeableObject(value) { return isNonNullObject(value) && !isSpecial(value) }; function isNonNullObject(value) { return !!value && typeof value === 'object' } function isSpecial(value) { var stringValue = Object.prototype.toString.call(value); return stringValue === '[object RegExp]' || stringValue === '[object Date]' || isReactElement(value) } // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 var canUseSymbol = typeof Symbol === 'function' && Symbol.for; var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; function isReactElement(value) { return value.$$typeof === REACT_ELEMENT_TYPE } function emptyTarget(val) { return Array.isArray(val) ? [] : {} } function cloneUnlessOtherwiseSpecified(value, options) { return (options.clone !== false && options.isMergeableObject(value)) ? deepmerge(emptyTarget(value), value, options) : value } function defaultArrayMerge(target, source, options) { return target.concat(source).map(function(element) { return cloneUnlessOtherwiseSpecified(element, options) }) } function getMergeFunction(key, options) { if (!options.customMerge) { return deepmerge } var customMerge = options.customMerge(key); return typeof customMerge === 'function' ? customMerge : deepmerge } function getEnumerableOwnPropertySymbols(target) { return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function(symbol) { return target.propertyIsEnumerable(symbol) }) : [] } function getKeys(target) { return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) } function propertyIsOnObject(object, property) { try { return property in object } catch(_) { return false } } // Protects from prototype poisoning and unexpected merging up the prototype chain. function propertyIsUnsafe(target, key) { return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet, && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. } function mergeObject(target, source, options) { var destination = {}; if (options.isMergeableObject(target)) { getKeys(target).forEach(function(key) { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); }); } getKeys(source).forEach(function(key) { if (propertyIsUnsafe(target, key)) { return } if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) { destination[key] = getMergeFunction(key, options)(target[key], source[key], options); } else { destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); } }); return destination } function deepmerge(target, source, options) { options = options || {}; options.arrayMerge = options.arrayMerge || defaultArrayMerge; options.isMergeableObject = options.isMergeableObject || isMergeableObject; // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() // implementations can use it. The caller may not replace it. options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; var sourceIsArray = Array.isArray(source); var targetIsArray = Array.isArray(target); var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options) } else if (sourceIsArray) { return options.arrayMerge(target, source, options) } else { return mergeObject(target, source, options) } } deepmerge.all = function deepmergeAll(array, options) { if (!Array.isArray(array)) { throw new Error('first argument should be an array') } return array.reduce(function(prev, next) { return deepmerge(prev, next, options) }, {}) }; var deepmerge_1 = deepmerge; var cjs = deepmerge_1; var utils = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports.parseStartTime = parseStartTime; exports.parseEndTime = parseEndTime; exports.randomString = randomString; exports.queryString = queryString; exports.getSDK = getSDK; exports.getConfig = getConfig; exports.omit = omit; exports.callPlayer = callPlayer; exports.isObject = isObject; exports.isEqual = isEqual; exports.isMediaStream = isMediaStream; var _loadScript = _interopRequireDefault(loadScript); var _deepmerge = _interopRequireDefault(cjs); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } var MATCH_START_QUERY = /[?&#](?:start|t)=([0-9hms]+)/; var MATCH_END_QUERY = /[?&#]end=([0-9hms]+)/; var MATCH_START_STAMP = /(\d+)(h|m|s)/g; var MATCH_NUMERIC = /^\d+$/; // Parse YouTube URL for a start time param, ie ?t=1h14m30s // and return the start time in seconds function parseTimeParam(url, pattern) { var match = url.match(pattern); if (match) { var stamp = match[1]; if (stamp.match(MATCH_START_STAMP)) { return parseTimeString(stamp); } if (MATCH_NUMERIC.test(stamp)) { return parseInt(stamp); } } return undefined; } function parseTimeString(stamp) { var seconds = 0; var array = MATCH_START_STAMP.exec(stamp); while (array !== null) { var _array = array, _array2 = _slicedToArray(_array, 3), count = _array2[1], period = _array2[2]; if (period === 'h') seconds += parseInt(count, 10) * 60 * 60; if (period === 'm') seconds += parseInt(count, 10) * 60; if (period === 's') seconds += parseInt(count, 10); array = MATCH_START_STAMP.exec(stamp); } return seconds; } function parseStartTime(url) { return parseTimeParam(url, MATCH_START_QUERY); } function parseEndTime(url) { return parseTimeParam(url, MATCH_END_QUERY); } // http://stackoverflow.com/a/38622545 function randomString() { return Math.random().toString(36).substr(2, 5); } function queryString(object) { return Object.keys(object).map(function (key) { return "".concat(key, "=").concat(object[key]); }).join('&'); } // Util function to load an external SDK // or return the SDK if it is already loaded var requests = {}; function getSDK(url, sdkGlobal) { var sdkReady = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var isLoaded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () { return true; }; var fetchScript = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _loadScript["default"]; if (window[sdkGlobal] && isLoaded(window[sdkGlobal])) { return Promise.resolve(window[sdkGlobal]); } return new Promise(function (resolve, reject) { // If we are already loading the SDK, add the resolve and reject // functions to the existing array of requests if (requests[url]) { requests[url].push({ resolve: resolve, reject: reject }); return; } requests[url] = [{ resolve: resolve, reject: reject }]; var onLoaded = function onLoaded(sdk) { // When loaded, resolve all pending request promises requests[url].forEach(function (request) { return request.resolve(sdk); }); }; if (sdkReady) { var previousOnReady = window[sdkReady]; window[sdkReady] = function () { if (previousOnReady) previousOnReady(); onLoaded(window[sdkGlobal]); }; } fetchScript(url, function (err) { if (err) { // Loading the SDK failed – reject all requests and // reset the array of requests for this SDK requests[url].forEach(function (request) { return request.reject(err); }); requests[url] = null; } else if (!sdkReady) { onLoaded(window[sdkGlobal]); } }); }); } function getConfig(props$1, defaultProps, showWarning) { var config = (0, _deepmerge["default"])(defaultProps.config, props$1.config); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = props.DEPRECATED_CONFIG_PROPS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var p = _step.value; if (props$1[p]) { var key = p.replace(/Config$/, ''); config = (0, _deepmerge["default"])(config, _defineProperty({}, key, props$1[p])); if (showWarning) { var link = 'https://github.com/CookPete/react-player#config-prop'; var message = "ReactPlayer: %c".concat(p, " %cis deprecated, please use the config prop instead \u2013 ").concat(link); console.warn(message, 'font-weight: bold', ''); } } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator["return"] != null) { _iterator["return"](); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return config; } function omit(object) { var _ref; for (var _len = arguments.length, arrays = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { arrays[_key - 1] = arguments[_key]; } var omitKeys = (_ref = []).concat.apply(_ref, arrays); var output = {}; var keys = Object.keys(object); for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) { var key = _keys[_i2]; if (omitKeys.indexOf(key) === -1) { output[key] = object[key]; } } return output; } function callPlayer(method) { var _this$player; // Util method for calling a method on this.player // but guard against errors and console.warn instead if (!this.player || !this.player[method]) { var message = "ReactPlayer: ".concat(this.constructor.displayName, " player could not call %c").concat(method, "%c \u2013 "); if (!this.player) { message += 'The player was not available'; } else if (!this.player[method]) { message += 'The method was not available'; } console.warn(message, 'font-weight: bold', ''); return null; } for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { args[_key2 - 1] = arguments[_key2]; } return (_this$player = this.player)[method].apply(_this$player, args); } function isObject(val) { return val !== null && _typeof(val) === 'object'; } // Deep comparison of two objects, but ignoring functions // and React elements, for use in shouldComponentUpdate function isEqual(a, b) { if (typeof a === 'function' && typeof b === 'function') { return true; } if ((0, React__default.isValidElement)(a) && (0, React__default.isValidElement)(b)) { return true; } if (a instanceof Array && b instanceof Array) { if (a.length !== b.length) { return false; } for (var i = 0; i !== a.length; i++) { if (!isEqual(a[i], b[i])) { return false; } } return true; } if (isObject(a) && isObject(b)) { if (Object.keys(a).length !== Object.keys(b).length) { return false; } for (var _i3 = 0, _Object$keys = Object.keys(a); _i3 < _Object$keys.length; _i3++) { var key = _Object$keys[_i3]; if (!isEqual(a[key], b[key])) { return false; } } return true; } return a === b; } function isMediaStream(url) { return typeof window !== 'undefined' && typeof window.MediaStream !== 'undefined' && url instanceof window.MediaStream; } }); unwrapExports(utils); var utils_1 = utils.parseStartTime; var utils_2 = utils.parseEndTime; var utils_3 = utils.randomString; var utils_4 = utils.queryString; var utils_5 = utils.getSDK; var utils_6 = utils.getConfig; var utils_7 = utils.omit; var utils_8 = utils.callPlayer; var utils_9 = utils.isObject; var utils_10 = utils.isEqual; var utils_11 = utils.isMediaStream; var Player_1 = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireWildcard(React__default); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var SEEK_ON_PLAY_EXPIRY = 5000; var Player = /*#__PURE__*/ function (_Component) { _inherits(Player, _Component); function Player() { var _getPrototypeOf2; var _this; _classCallCheck(this, Player); for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) { _args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Player)).call.apply(_getPrototypeOf2, [this].concat(_args))); _defineProperty(_assertThisInitialized(_this), "mounted", false); _defineProperty(_assertThisInitialized(_this), "isReady", false); _defineProperty(_assertThisInitialized(_this), "isPlaying", false); _defineProperty(_assertThisInitialized(_this), "isLoading", true); _defineProperty(_assertThisInitialized(_this), "loadOnReady", null); _defineProperty(_assertThisInitialized(_this), "startOnPlay", true); _defineProperty(_assertThisInitialized(_this), "seekOnPlay", null); _defineProperty(_assertThisInitialized(_this), "onDurationCalled", false); _defineProperty(_assertThisInitialized(_this), "getInternalPlayer", function (key) { if (!_this.player) return null; return _this.player[key]; }); _defineProperty(_assertThisInitialized(_this), "progress", function () { if (_this.props.url && _this.player && _this.isReady) { var playedSeconds = _this.getCurrentTime() || 0; var loadedSeconds = _this.getSecondsLoaded(); var duration = _this.getDuration(); if (duration) { var progress = { playedSeconds: playedSeconds, played: playedSeconds / duration }; if (loadedSeconds !== null) { progress.loadedSeconds = loadedSeconds; progress.loaded = loadedSeconds / duration; } // Only call onProgress if values have changed if (progress.playedSeconds !== _this.prevPlayed || progress.loadedSeconds !== _this.prevLoaded) { _this.props.onProgress(progress); } _this.prevPlayed = progress.playedSeconds; _this.prevLoaded = progress.loadedSeconds; } } _this.progressTimeout = setTimeout(_this.progress, _this.props.progressFrequency || _this.props.progressInterval); }); _defineProperty(_assertThisInitialized(_this), "handleReady", function () { if (!_this.mounted) return; _this.isReady = true; _this.isLoading = false; var _this$props = _this.props, onReady = _this$props.onReady, playing = _this$props.playing, volume = _this$props.volume, muted = _this$props.muted; onReady(); if (!muted && volume !== null) { _this.player.setVolume(volume); } if (_this.loadOnReady) { _this.player.load(_this.loadOnReady, true); _this.loadOnReady = null; } else if (playing) { _this.player.play(); } _this.handleDurationCheck(); }); _defineProperty(_assertThisInitialized(_this), "handlePlay", function () { _this.isPlaying = true; _this.isLoading = false; var _this$props2 = _this.props, onStart = _this$props2.onStart, onPlay = _this$props2.onPlay, playbackRate = _this$props2.playbackRate; if (_this.startOnPlay) { if (_this.player.setPlaybackRate && playbackRate !== 1) { _this.player.setPlaybackRate(playbackRate); } onStart(); _this.startOnPlay = false; } onPlay(); if (_this.seekOnPlay) { _this.seekTo(_this.seekOnPlay); _this.seekOnPlay = null; } _this.handleDurationCheck(); }); _defineProperty(_assertThisInitialized(_this), "handlePause", function (e) { _this.isPlaying = false; if (!_this.isLoading) { _this.props.onPause(e); } }); _defineProperty(_assertThisInitialized(_this), "handleEnded", function () { var _this$props3 = _this.props, activePlayer = _this$props3.activePlayer, loop = _this$props3.loop, onEnded = _this$props3.onEnded; if (activePlayer.loopOnEnded && loop) { _this.seekTo(0); } if (!loop) { _this.isPlaying = false; onEnded(); } }); _defineProperty(_assertThisInitialized(_this), "handleError", function () { var _this$props4; _this.isLoading = false; (_this$props4 = _this.props).onError.apply(_this$props4, arguments); }); _defineProperty(_assertThisInitialized(_this), "handleDurationCheck", function () { clearTimeout(_this.durationCheckTimeout); var duration = _this.getDuration(); if (duration) { if (!_this.onDurationCalled) { _this.props.onDuration(duration); _this.onDurationCalled = true; } } else { _this.durationCheckTimeout = setTimeout(_this.handleDurationCheck, 100); } }); _defineProperty(_assertThisInitialized(_this), "handleLoaded", function () { // Sometimes we know loading has stopped but onReady/onPlay are never called // so this provides a way for players to avoid getting stuck _this.isLoading = false; }); _defineProperty(_assertThisInitialized(_this), "ref", function (player) { if (player) { _this.player = player; } }); return _this; } _createClass(Player, [{ key: "componentDidMount", value: function componentDidMount() { this.mounted = true; this.player.load(this.props.url); this.progress(); } }, { key: "componentWillUnmount", value: function componentWillUnmount() { clearTimeout(this.progressTimeout); clearTimeout(this.durationCheckTimeout); if (this.isReady) { this.player.stop(); } if (this.player.disablePIP) { this.player.disablePIP(); } this.mounted = false; } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { var _this2 = this; // Invoke player methods based on changed props var _this$props5 = this.props, url = _this$props5.url, playing = _this$props5.playing, volume = _this$props5.volume, muted = _this$props5.muted, playbackRate = _this$props5.playbackRate, pip = _this$props5.pip, loop = _this$props5.loop, activePlayer = _this$props5.activePlayer; if (!(0, utils.isEqual)(prevProps.url, url)) { if (this.isLoading && !activePlayer.forceLoad) { console.warn("ReactPlayer: the attempt to load ".concat(url, " is being deferred until the player has loaded")); this.loadOnReady = url; return; } this.isLoading = true; this.startOnPlay = true; this.onDurationCalled = false; this.player.load(url, this.isReady); } if (!prevProps.playing && playing && !this.isPlaying) { this.player.play(); } if (prevProps.playing && !playing && this.isPlaying) { this.player.pause(); } if (!prevProps.pip && pip && this.player.enablePIP) { this.player.enablePIP(); } if (prevProps.pip && !pip && this.player.disablePIP) { this.player.disablePIP(); } if (prevProps.volume !== volume && volume !== null) { this.player.setVolume(volume); } if (prevProps.muted !== muted) { if (muted) { this.player.mute(); } else { this.player.unmute(); if (volume !== null) { // Set volume next tick to fix a bug with DailyMotion setTimeout(function () { return _this2.player.setVolume(volume); }); } } } if (prevProps.playbackRate !== playbackRate && this.player.setPlaybackRate) { this.player.setPlaybackRate(playbackRate); } if (prevProps.loop !== loop && this.player.setLoop) { this.player.setLoop(loop); } } }, { key: "getDuration", value: function getDuration() { if (!this.isReady) return null; return this.player.getDuration(); } }, { key: "getCurrentTime", value: function getCurrentTime() { if (!this.isReady) return null; return this.player.getCurrentTime(); } }, { key: "getSecondsLoaded", value: function getSecondsLoaded() { if (!this.isReady) return null; return this.player.getSecondsLoaded(); } }, { key: "seekTo", value: function seekTo(amount, type) { var _this3 = this; // When seeking before player is ready, store value and seek later if (!this.isReady && amount !== 0) { this.seekOnPlay = amount; setTimeout(function () { _this3.seekOnPlay = null; }, SEEK_ON_PLAY_EXPIRY); return; } var isFraction = !type ? amount > 0 && amount < 1 : type === 'fraction'; if (isFraction) { // Convert fraction to seconds based on duration var duration = this.player.getDuration(); if (!duration) { console.warn('ReactPlayer: could not seek using fraction – duration not yet available'); return; } this.player.seekTo(duration * amount); return; } this.player.seekTo(amount); } }, { key: "render", value: function render() { var Player = this.props.activePlayer; if (!Player) { return null; } return _react["default"].createElement(Player, _extends({}, this.props, { ref: this.ref, onReady: this.handleReady, onPlay: this.handlePlay, onPause: this.handlePause, onEnded: this.handleEnded, onLoaded: this.handleLoaded, onError: this.handleError })); } }]); return Player; }(_react.Component); exports["default"] = Player; _defineProperty(Player, "displayName", 'Player'); _defineProperty(Player, "propTypes", props.propTypes); _defineProperty(Player, "defaultProps", props.defaultProps); }); unwrapExports(Player_1); var singlePlayer = createCommonjsModule(function (module, exports) { Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = createSinglePlayer; var _react = _interopRequireWildcard(React__default); var _Player = _interopRequireDefault(Player_1); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var SUPPORTED_PROPS = Object.keys(props.propTypes); function createSinglePlayer(activePlayer) { var _class, _temp; return _temp = _class = /*#__PURE__*/ function (_Component) { _inherits(SinglePlayer, _Component); function SinglePlayer() { var _getPrototypeOf2; var _this; _classCallCheck(this, SinglePlayer); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(SinglePlayer)).call.apply(_getPrototypeOf2, [this].concat(args))); _defineProperty(_assertThisInitialized(_this), "config", (0, utils.getConfig)(_this.props, props.defaultProps, true)); _defineProperty(_assertThisInitialized(_this), "getDuration", function () { if (!_this.player) return null; return _this.player.getDuration(); }); _defineProperty(_assertThisInitialized(_this), "getCurrentTime", function () { if (!_this.player) return null; return _this.player.getCurrentTime(); }); _defineProperty(_assertThisInitialized(_this), "getSecondsLoaded", function () { if (!_this.player) return null; return _this.player.getSecondsLoaded(); }); _defineProperty(_assertThisInitialized(_this), "getInternalPlayer", function () { var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'player'; if (!_this.player) return null; return _this.player.getInternalPlayer(key); }); _defineProperty(_assertThisInitialized(_this), "seekTo", function (fraction, type) { if (!_this.player) return null; _this.player.seekTo(fraction, type); }); _defineProperty(_assertThisInitialized(_this), "ref", function (player) { _this.player = player; }); return _this; } _createClass(SinglePlayer, [{ key: "shouldComponentUpdate", value: function shouldComponentUpdate(nextProps) { return !(0, utils.isEqual)(this.props, nextProps); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { this.config = (0, utils.getConfig)(this.props