@micromag/element-video 0.3.676 → 0.3.682
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.js +36 -38
- package/package.json +4 -4
package/es/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
2
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
3
|
import classNames from 'classnames';
|
|
5
4
|
import Hls from 'hls.js';
|
|
@@ -140,19 +139,19 @@ var Video = function Video(_ref) {
|
|
|
140
139
|
return getMediaFilesAsArray(files);
|
|
141
140
|
}, [files]);
|
|
142
141
|
var finalThumbnail = useMediaThumbnail(media, thumbnail);
|
|
143
|
-
var
|
|
144
|
-
var currentTime = useMediaCurrentTime(
|
|
142
|
+
var _ref17 = useRef(null);
|
|
143
|
+
var currentTime = useMediaCurrentTime(_ref17.current, {
|
|
145
144
|
id: mediaUrl,
|
|
146
145
|
disabled: paused || onProgressStep === null
|
|
147
146
|
});
|
|
148
|
-
var duration = useMediaDuration(
|
|
147
|
+
var duration = useMediaDuration(_ref17.current, {
|
|
149
148
|
id: mediaUrl
|
|
150
149
|
});
|
|
151
150
|
var _useState = useState(false),
|
|
152
151
|
_useState2 = _slicedToArray(_useState, 2),
|
|
153
152
|
showLoading = _useState2[0],
|
|
154
153
|
setShowLoading = _useState2[1];
|
|
155
|
-
var ready = useMediaReady(
|
|
154
|
+
var ready = useMediaReady(_ref17.current, {
|
|
156
155
|
id: mediaUrl
|
|
157
156
|
});
|
|
158
157
|
useEffect(function () {
|
|
@@ -214,7 +213,7 @@ var Video = function Video(_ref) {
|
|
|
214
213
|
hls.on(Hls.Events.LEVEL_SWITCHED, function (_, _ref5) {
|
|
215
214
|
var level = _ref5.level;
|
|
216
215
|
if (onQualityLevelChange !== null) {
|
|
217
|
-
onQualityLevelChange(level,
|
|
216
|
+
onQualityLevelChange(level, _ref17.current);
|
|
218
217
|
}
|
|
219
218
|
});
|
|
220
219
|
hls.on(Hls.Events.ERROR, function (_, _ref6) {
|
|
@@ -260,8 +259,8 @@ var Video = function Video(_ref) {
|
|
|
260
259
|
|
|
261
260
|
// attach hls.js when the <video> ref or the hls.js instance is ready
|
|
262
261
|
useEffect(function () {
|
|
263
|
-
if (hlsJs !== null &&
|
|
264
|
-
hlsJs.attachMedia(
|
|
262
|
+
if (hlsJs !== null && _ref17.current !== null) {
|
|
263
|
+
hlsJs.attachMedia(_ref17.current);
|
|
265
264
|
// if (onQualityLevelChange !== null) {
|
|
266
265
|
// onQualityLevelChange(hlsJs.currentLevel, ref.current);
|
|
267
266
|
// }
|
|
@@ -271,7 +270,7 @@ var Video = function Video(_ref) {
|
|
|
271
270
|
hlsJs.detachMedia();
|
|
272
271
|
}
|
|
273
272
|
};
|
|
274
|
-
}, [hlsJs,
|
|
273
|
+
}, [hlsJs, _ref17.current]);
|
|
275
274
|
|
|
276
275
|
// cleanup hls.js instance when it is no longer needed
|
|
277
276
|
useEffect(function () {
|
|
@@ -290,7 +289,7 @@ var Video = function Video(_ref) {
|
|
|
290
289
|
if (hlsJs !== null) {
|
|
291
290
|
var qualityLevel = qualityStartLevel !== null ? qualityStartLevel : -1;
|
|
292
291
|
hlsJs.startLevel = qualityLevel;
|
|
293
|
-
if (
|
|
292
|
+
if (_ref17.current !== null && _ref17.current.paused) {
|
|
294
293
|
hlsJs.currentLevel = qualityLevel;
|
|
295
294
|
hlsJs.nextLevel = -1; // force auto quality selection for the next fragment
|
|
296
295
|
}
|
|
@@ -302,40 +301,39 @@ var Video = function Video(_ref) {
|
|
|
302
301
|
}
|
|
303
302
|
var supportedMimes = getVideoSupportedMimes();
|
|
304
303
|
if (supportedMimes.length === 0) {
|
|
305
|
-
|
|
304
|
+
supportedMimes = ['video/mp4', 'video/webm'];
|
|
306
305
|
}
|
|
307
|
-
var
|
|
306
|
+
var supportedFiles = filesArray.filter(function (file) {
|
|
308
307
|
var fileHandle = file.handle || file.id;
|
|
309
308
|
var _file$mime = file.mime,
|
|
310
309
|
mime = _file$mime === void 0 ? "video/".concat(fileHandle === 'h264' ? 'mp4' : fileHandle) : _file$mime;
|
|
311
310
|
return supportedMimes.indexOf(mime) !== -1;
|
|
312
|
-
})
|
|
311
|
+
});
|
|
312
|
+
var supportedFilesWithoutOriginal = supportedFiles.filter(function (file) {
|
|
313
313
|
var fileHandle = file.handle || file.id;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
var _ref9 =
|
|
318
|
-
_ref9$
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
326
|
-
return sourceFilesMap[mime];
|
|
314
|
+
return fileHandle !== 'original';
|
|
315
|
+
});
|
|
316
|
+
return (supportedFilesWithoutOriginal.length > 0 ? supportedFilesWithoutOriginal : supportedFiles).sort(function (_ref9, _ref10) {
|
|
317
|
+
var _ref9$size = _ref9.size,
|
|
318
|
+
a = _ref9$size === void 0 ? '' : _ref9$size;
|
|
319
|
+
var _ref10$size = _ref10.size,
|
|
320
|
+
b = _ref10$size === void 0 ? '' : _ref10$size;
|
|
321
|
+
if (a === b) {
|
|
322
|
+
return 0;
|
|
323
|
+
}
|
|
324
|
+
return a > b ? 1 : -1;
|
|
327
325
|
});
|
|
328
326
|
}, [filesArray, hlsSources]);
|
|
329
327
|
|
|
330
328
|
// @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
331
|
-
var
|
|
332
|
-
var handle =
|
|
329
|
+
var _ref11 = filesArray.find(function (_ref12) {
|
|
330
|
+
var handle = _ref12.handle;
|
|
333
331
|
return handle === 'original';
|
|
334
332
|
}) || {},
|
|
335
|
-
|
|
336
|
-
originalType =
|
|
337
|
-
|
|
338
|
-
originalMime =
|
|
333
|
+
_ref11$type = _ref11.type,
|
|
334
|
+
originalType = _ref11$type === void 0 ? null : _ref11$type,
|
|
335
|
+
_ref11$mime = _ref11.mime,
|
|
336
|
+
originalMime = _ref11$mime === void 0 ? mediaMime : _ref11$mime;
|
|
339
337
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
340
338
|
var isImageWithoutSourceFile = originalFileIsImage && (sourceFiles === null || sourceFiles.length === 0);
|
|
341
339
|
var withSize = width !== null && height !== null;
|
|
@@ -345,7 +343,7 @@ var Video = function Video(_ref) {
|
|
|
345
343
|
}
|
|
346
344
|
}, [duration, customOnDurationChange]);
|
|
347
345
|
var onVolumeChange = useCallback(function () {
|
|
348
|
-
var _ref$current =
|
|
346
|
+
var _ref$current = _ref17.current,
|
|
349
347
|
element = _ref$current === void 0 ? null : _ref$current;
|
|
350
348
|
if (element === null) {
|
|
351
349
|
return;
|
|
@@ -390,7 +388,7 @@ var Video = function Video(_ref) {
|
|
|
390
388
|
}
|
|
391
389
|
}, [ready, onReady]);
|
|
392
390
|
useEffect(function () {
|
|
393
|
-
var _ref$current2 =
|
|
391
|
+
var _ref$current2 = _ref17.current,
|
|
394
392
|
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
395
393
|
if (element === null) {
|
|
396
394
|
return;
|
|
@@ -427,7 +425,7 @@ var Video = function Video(_ref) {
|
|
|
427
425
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
428
426
|
key: mediaUrl,
|
|
429
427
|
ref: function ref(newRef) {
|
|
430
|
-
|
|
428
|
+
_ref17.current = newRef;
|
|
431
429
|
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
432
430
|
mediaRef(newRef);
|
|
433
431
|
} else if (mediaRef !== null) {
|
|
@@ -458,9 +456,9 @@ var Video = function Video(_ref) {
|
|
|
458
456
|
"data-hls": hlsJs !== null,
|
|
459
457
|
"data-ts-offset": hlsTsOffset,
|
|
460
458
|
"aria-hidden": true
|
|
461
|
-
}, (shouldLoad ? sourceFiles || [] : []).map(function (
|
|
462
|
-
var sourceUrl =
|
|
463
|
-
sourceMime =
|
|
459
|
+
}, (shouldLoad ? sourceFiles || [] : []).map(function (_ref16) {
|
|
460
|
+
var sourceUrl = _ref16.url,
|
|
461
|
+
sourceMime = _ref16.mime;
|
|
464
462
|
return /*#__PURE__*/React.createElement("source", {
|
|
465
463
|
key: "".concat(sourceUrl, "-").concat(sourceMime),
|
|
466
464
|
src: sourceUrl !== null ? "".concat(sourceUrl, "#t=0.001") : null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.682",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@babel/runtime": "^7.13.10",
|
|
62
|
-
"@micromag/core": "^0.3.
|
|
63
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
62
|
+
"@micromag/core": "^0.3.679",
|
|
63
|
+
"@micromag/element-closed-captions": "^0.3.679",
|
|
64
64
|
"classnames": "^2.2.6",
|
|
65
65
|
"hls.js": "^1.5.15",
|
|
66
66
|
"lodash": "^4.17.21",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"access": "public",
|
|
73
73
|
"registry": "https://registry.npmjs.org/"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "ff77a57d44913b0e5afa373445ae9f014799e183"
|
|
76
76
|
}
|