@faintlines/video-player
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -6,3 +6,2 @@ import { isEmpty, values, isEqual } from 'lodash'; | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
@@ -14,6 +13,4 @@ var symbols = Object.getOwnPropertySymbols(object); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
@@ -28,6 +25,4 @@ for (var i = 1; i < arguments.length; i++) { | ||
} | ||
return target; | ||
} | ||
function _typeof(obj) { | ||
@@ -42,3 +37,2 @@ "@babel/helpers - typeof"; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
@@ -55,6 +49,4 @@ if (key in obj) { | ||
} | ||
return obj; | ||
} | ||
function _extends() { | ||
@@ -64,3 +56,2 @@ _extends = Object.assign || function (target) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -72,9 +63,6 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -85,3 +73,2 @@ if (source == null) return {}; | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
@@ -92,16 +79,10 @@ key = sourceKeys[i]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
@@ -114,17 +95,12 @@ key = sourceSymbolKeys[i]; | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
@@ -134,9 +110,6 @@ var _arr = []; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
@@ -154,6 +127,4 @@ } | ||
} | ||
return _arr; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -167,11 +138,7 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableRest() { | ||
@@ -183,3 +150,2 @@ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
var sourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer; | ||
function hasNativeHlsSupport() { | ||
@@ -189,18 +155,18 @@ var video = document.createElement("video"); | ||
} | ||
function hasHlsJsSupport() { | ||
// based on https://github.com/video-dev/hls.js/blob/c35441b94f7ffef94e12ecf99aa7a5c61d5759a0/src/is-supported.ts#L8 | ||
if (!mediaSource) { | ||
return false; | ||
} | ||
var isTypeSupported = mediaSource && typeof mediaSource.isTypeSupported === "function" && mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'); | ||
var isTypeSupported = mediaSource && typeof mediaSource.isTypeSupported === "function" && mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'); // if SourceBuffer is exposed ensure its API is valid | ||
// if SourceBuffer is exposed ensure its API is valid | ||
// safari and old version of Chrome doe not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible | ||
var sourceBufferValidAPI = !sourceBuffer || sourceBuffer.prototype && typeof sourceBuffer.prototype.appendBuffer === "function" && typeof sourceBuffer.prototype.remove === "function"; | ||
return !!isTypeSupported && !!sourceBufferValidAPI; | ||
} | ||
var SUPPORTS_HLS = hasNativeHlsSupport() || hasHlsJsSupport(); | ||
var SUPPORTS_HLS = hasNativeHlsSupport() || hasHlsJsSupport(); // https://github.com/Dash-Industry-Forum/dash.js/issues/2055#issuecomment-313187528 | ||
// https://github.com/Dash-Industry-Forum/dash.js/issues/2055#issuecomment-313187528 | ||
var SUPPORTS_DASH = mediaSource && typeof mediaSource.isTypeSupported === "function"; | ||
@@ -219,40 +185,35 @@ function filterVideoUrls(urls) { | ||
var _excluded = ["url", "hlsUrl", "dashUrl", "fileUrl", "className", "progressInterval", "playsInline", "startAt", "autoPlay", "preload", "poster", "controlsList", "loopRange", "autoRetry", "onPlay", "onPause", "onProgress", "onLoadedMetadata", "onError", "onRetryAttempt"], | ||
_excluded2 = ["children"]; | ||
_excluded2 = ["children"]; | ||
var ReactPlayer = require("react-player/file"); | ||
var WrapperPropsContext = /*#__PURE__*/React.createContext(); | ||
var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) { | ||
var url = _ref.url, | ||
hlsUrl = _ref.hlsUrl, | ||
dashUrl = _ref.dashUrl, | ||
fileUrl = _ref.fileUrl, | ||
className = _ref.className, | ||
progressInterval = _ref.progressInterval, | ||
playsInline = _ref.playsInline, | ||
startAt = _ref.startAt, | ||
autoPlay = _ref.autoPlay, | ||
preload = _ref.preload, | ||
poster = _ref.poster, | ||
controlsList = _ref.controlsList, | ||
loopRange = _ref.loopRange, | ||
autoRetry = _ref.autoRetry, | ||
onPlay = _ref.onPlay, | ||
onPause = _ref.onPause, | ||
onProgress = _ref.onProgress, | ||
onLoadedMetadata = _ref.onLoadedMetadata, | ||
onError = _ref.onError, | ||
onRetryAttempt = _ref.onRetryAttempt, | ||
props = _objectWithoutProperties(_ref, _excluded); | ||
hlsUrl = _ref.hlsUrl, | ||
dashUrl = _ref.dashUrl, | ||
fileUrl = _ref.fileUrl, | ||
className = _ref.className, | ||
progressInterval = _ref.progressInterval, | ||
playsInline = _ref.playsInline, | ||
startAt = _ref.startAt, | ||
autoPlay = _ref.autoPlay, | ||
preload = _ref.preload, | ||
poster = _ref.poster, | ||
controlsList = _ref.controlsList, | ||
loopRange = _ref.loopRange, | ||
autoRetry = _ref.autoRetry, | ||
onPlay = _ref.onPlay, | ||
onPause = _ref.onPause, | ||
onProgress = _ref.onProgress, | ||
onLoadedMetadata = _ref.onLoadedMetadata, | ||
onError = _ref.onError, | ||
onRetryAttempt = _ref.onRetryAttempt, | ||
props = _objectWithoutProperties(_ref, _excluded); | ||
var _useState = useState(autoPlay), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
playing = _useState2[0], | ||
setPlaying = _useState2[1]; | ||
_useState2 = _slicedToArray(_useState, 2), | ||
playing = _useState2[0], | ||
setPlaying = _useState2[1]; | ||
var _useState3 = useState(0), | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
retryAttempt = _useState4[0], | ||
setRetryAttempt = _useState4[1]; | ||
_useState4 = _slicedToArray(_useState3, 2), | ||
retryAttempt = _useState4[0], | ||
setRetryAttempt = _useState4[1]; | ||
var playerRef = useRef(); | ||
@@ -264,3 +225,2 @@ var loopRangeRef = useRef(loopRange); | ||
var _playerRef$current, _playerRef$current$ge, _playerRef$current2, _playerRef$current2$g; | ||
ref.current = { | ||
@@ -271,3 +231,2 @@ paused: playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current = playerRef.current) === null || _playerRef$current === void 0 ? void 0 : (_playerRef$current$ge = _playerRef$current.getInternalPlayer()) === null || _playerRef$current$ge === void 0 ? void 0 : _playerRef$current$ge.paused, | ||
var _playerRef$current3, _playerRef$current3$g; | ||
setPlaying(true); | ||
@@ -278,3 +237,2 @@ return playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current3 = playerRef.current) === null || _playerRef$current3 === void 0 ? void 0 : (_playerRef$current3$g = _playerRef$current3.getInternalPlayer()) === null || _playerRef$current3$g === void 0 ? void 0 : _playerRef$current3$g.play(); | ||
var _playerRef$current4, _playerRef$current4$g; | ||
setPlaying(false); | ||
@@ -285,10 +243,8 @@ return playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current4 = playerRef.current) === null || _playerRef$current4 === void 0 ? void 0 : (_playerRef$current4$g = _playerRef$current4.getInternalPlayer()) === null || _playerRef$current4$g === void 0 ? void 0 : _playerRef$current4$g.pause(); | ||
var _playerRef$current5; | ||
var player = playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current5 = playerRef.current) === null || _playerRef$current5 === void 0 ? void 0 : _playerRef$current5.getInternalPlayer(); | ||
if (player) { | ||
player.currentTime = time; | ||
} // TODO: the following doesn't work. figure out why | ||
} | ||
// TODO: the following doesn't work. figure out why | ||
// playerRef?.current?.seekTo(time, "seconds"); | ||
} | ||
@@ -305,31 +261,26 @@ }; | ||
} | ||
if (loopRangeRef.current) { | ||
var _playerRef$current6; | ||
applyLoopRange(loopRangeRef.current, progress.playedSeconds, playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current6 = playerRef.current) === null || _playerRef$current6 === void 0 ? void 0 : _playerRef$current6.getInternalPlayer()); | ||
} | ||
if (onProgress) { | ||
onProgress(progress); | ||
} | ||
}, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[onProgress]); | ||
var metadataLoadedHandler = useCallback(function (evt) { | ||
var _playerRef$current7; | ||
var player = playerRef === null || playerRef === void 0 ? void 0 : (_playerRef$current7 = playerRef.current) === null || _playerRef$current7 === void 0 ? void 0 : _playerRef$current7.getInternalPlayer(); | ||
if (ref && ref.current) { | ||
ref.current.duration = player === null || player === void 0 ? void 0 : player.duration; | ||
} | ||
if (startAt && player) { | ||
player.currentTime = startAt; | ||
} | ||
if (onLoadedMetadata) { | ||
onLoadedMetadata(evt); | ||
} | ||
}, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[onLoadedMetadata, startAt]); | ||
@@ -340,7 +291,7 @@ var playHandler = useCallback(function (evt) { | ||
} | ||
if (onPlay) { | ||
onPlay(evt); | ||
} | ||
}, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[onPlay]); | ||
@@ -351,7 +302,7 @@ var pauseHandler = useCallback(function (evt) { | ||
} | ||
if (onPause) { | ||
onPause(evt); | ||
} | ||
}, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[onPause]); | ||
@@ -362,3 +313,2 @@ var errorHandler = useCallback(function (evt) { | ||
} | ||
if (autoRetry && !evt.defaultPrevented) { | ||
@@ -369,3 +319,2 @@ setTimeout(function () { | ||
}); | ||
if (onRetryAttempt) { | ||
@@ -422,8 +371,6 @@ onRetryAttempt(); | ||
poster: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" // transparent pixel | ||
}; | ||
var Wrapper = /*#__PURE__*/forwardRef(function (_ref2, ref) { | ||
var children = _ref2.children, | ||
props = _objectWithoutProperties(_ref2, _excluded2); | ||
props = _objectWithoutProperties(_ref2, _excluded2); | ||
var wrapperProps = useContext(WrapperPropsContext) || {}; | ||
@@ -439,19 +386,14 @@ return /*#__PURE__*/React.createElement("div", _extends({ | ||
} | ||
function selectVideoUrl(_ref3) { | ||
var hlsUrl = _ref3.hlsUrl, | ||
dashUrl = _ref3.dashUrl, | ||
fileUrl = _ref3.fileUrl; | ||
dashUrl = _ref3.dashUrl, | ||
fileUrl = _ref3.fileUrl; | ||
if (hlsUrl && SUPPORTS_HLS) { | ||
return hlsUrl; | ||
} | ||
if (dashUrl && SUPPORTS_DASH) { | ||
return dashUrl; | ||
} | ||
return fileUrl; | ||
} | ||
function getRemotePlaybackAttribute() { | ||
@@ -463,3 +405,2 @@ if (React.version.startsWith("16.")) { | ||
} | ||
return { | ||
@@ -469,10 +410,9 @@ disableRemotePlayback: true | ||
} | ||
function applyLoopRange(range, currentTime, player) { | ||
var _range = _slicedToArray(range, 3), | ||
start = _range[0], | ||
end = _range[1], | ||
jumpToStart = _range[2]; // not jumping to start | ||
start = _range[0], | ||
end = _range[1], | ||
jumpToStart = _range[2]; | ||
// not jumping to start | ||
if (currentTime >= end || jumpToStart && currentTime < start) { | ||
@@ -485,8 +425,17 @@ player.currentTime = start; | ||
var urls = _ref.urls; | ||
if ((urls || []).length === 0) { | ||
return null; | ||
} | ||
return /*#__PURE__*/React.createElement("div", null, (urls || []).map(function (url) { | ||
return /*#__PURE__*/React.createElement("div", { | ||
style: { | ||
position: "absolute", | ||
bottom: 0, | ||
left: 0, | ||
overflow: "hidden", | ||
// let the browser think it's visible | ||
width: 1, | ||
height: 1, | ||
opacity: 0.00001 | ||
} | ||
}, (urls || []).map(function (url) { | ||
return /*#__PURE__*/React.createElement(VideoPlayer, { | ||
@@ -500,5 +449,3 @@ key: urlToKey(url), | ||
} | ||
var VideoPreloader = /*#__PURE__*/memo(VideoPreloaderInner, isEqual); | ||
function urlToKey(url) { | ||
@@ -505,0 +452,0 @@ var urlObj = ensureUrlObject(url); |
{ | ||
"name": "@faintlines/video-player", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "", | ||
@@ -43,3 +43,3 @@ "license": "UNLICENSED", | ||
}, | ||
"gitHead": "ed8551a156172518730062da0be6b9e2cd4de91d" | ||
"gitHead": "e25609d43b40d4c4c1fd2e33884f10bc5cdc112c" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
420
37403
0