@micromag/element-video 0.3.577 → 0.3.578
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 +54 -25
- package/package.json +4 -4
package/es/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { PropTypes } from '@micromag/core';
|
|
|
9
9
|
import { Spinner } from '@micromag/core/components';
|
|
10
10
|
import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useProgressSteps } from '@micromag/core/hooks';
|
|
11
11
|
import { getMediaFilesAsArray, getVideoSupportedMimes } from '@micromag/core/utils';
|
|
12
|
+
import Hls from 'hls.js';
|
|
12
13
|
|
|
13
14
|
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","media":"micromag-element-video-media","spinner":"micromag-element-video-spinner"};
|
|
14
15
|
|
|
@@ -27,6 +28,7 @@ var propTypes = {
|
|
|
27
28
|
playsInline: PropTypes$1.bool,
|
|
28
29
|
preload: PropTypes$1.oneOf(['auto', 'metadata', 'none', null]),
|
|
29
30
|
disablePictureInPicture: PropTypes$1.bool,
|
|
31
|
+
disableHls: PropTypes$1.bool,
|
|
30
32
|
shouldLoad: PropTypes$1.bool,
|
|
31
33
|
withoutCors: PropTypes$1.bool,
|
|
32
34
|
className: PropTypes$1.string,
|
|
@@ -60,6 +62,7 @@ var defaultProps = {
|
|
|
60
62
|
playsInline: true,
|
|
61
63
|
preload: 'auto',
|
|
62
64
|
disablePictureInPicture: true,
|
|
65
|
+
disableHls: false,
|
|
63
66
|
shouldLoad: true,
|
|
64
67
|
withoutCors: false,
|
|
65
68
|
className: null,
|
|
@@ -111,7 +114,8 @@ var Video = function Video(_ref) {
|
|
|
111
114
|
focusable = _ref.focusable,
|
|
112
115
|
withPoster = _ref.withPoster,
|
|
113
116
|
withLoading = _ref.withLoading,
|
|
114
|
-
disablePictureInPicture = _ref.disablePictureInPicture
|
|
117
|
+
disablePictureInPicture = _ref.disablePictureInPicture,
|
|
118
|
+
disableHls = _ref.disableHls;
|
|
115
119
|
var _ref2 = media || {},
|
|
116
120
|
_ref2$url = _ref2.url,
|
|
117
121
|
mediaUrl = _ref2$url === void 0 ? null : _ref2$url,
|
|
@@ -130,19 +134,19 @@ var Video = function Video(_ref) {
|
|
|
130
134
|
return getMediaFilesAsArray(files);
|
|
131
135
|
}, [files]);
|
|
132
136
|
var finalThumbnail = useMediaThumbnail(media, thumbnail);
|
|
133
|
-
var
|
|
134
|
-
var currentTime = useMediaCurrentTime(
|
|
137
|
+
var _ref12 = useRef(null);
|
|
138
|
+
var currentTime = useMediaCurrentTime(_ref12.current, {
|
|
135
139
|
id: mediaUrl,
|
|
136
140
|
disabled: paused || onProgressStep === null
|
|
137
141
|
});
|
|
138
|
-
var duration = useMediaDuration(
|
|
142
|
+
var duration = useMediaDuration(_ref12.current, {
|
|
139
143
|
id: mediaUrl
|
|
140
144
|
});
|
|
141
145
|
var _useState = useState(false),
|
|
142
146
|
_useState2 = _slicedToArray(_useState, 2),
|
|
143
147
|
showLoading = _useState2[0],
|
|
144
148
|
setShowLoading = _useState2[1];
|
|
145
|
-
var ready = useMediaReady(
|
|
149
|
+
var ready = useMediaReady(_ref12.current, {
|
|
146
150
|
id: mediaUrl
|
|
147
151
|
});
|
|
148
152
|
useEffect(function () {
|
|
@@ -157,8 +161,33 @@ var Video = function Video(_ref) {
|
|
|
157
161
|
clearTimeout(id);
|
|
158
162
|
};
|
|
159
163
|
}, [mediaUrl, withLoading]);
|
|
164
|
+
var hlsIsSupported = useMemo(function () {
|
|
165
|
+
return Hls.isSupported();
|
|
166
|
+
}, [Hls]);
|
|
167
|
+
var hlsSources = useMemo(function () {
|
|
168
|
+
if (filesArray.length === 0 || disableHls) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return filesArray.filter(function (_ref4) {
|
|
172
|
+
var _ref4$mime = _ref4.mime,
|
|
173
|
+
mime = _ref4$mime === void 0 ? null : _ref4$mime,
|
|
174
|
+
_ref4$name = _ref4.name,
|
|
175
|
+
name = _ref4$name === void 0 ? null : _ref4$name;
|
|
176
|
+
return mime === 'application/vnd.apple.mpegurl' || (name || '').endsWith('.m3u8');
|
|
177
|
+
});
|
|
178
|
+
}, [filesArray, hlsIsSupported, disableHls]);
|
|
179
|
+
useEffect(function () {
|
|
180
|
+
if (_ref12.current === null || !hlsIsSupported) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (hlsSources !== null && hlsSources.length > 0) {
|
|
184
|
+
var hls = new Hls();
|
|
185
|
+
hls.loadSource(hlsSources[0].url);
|
|
186
|
+
hls.attachMedia(_ref12.current);
|
|
187
|
+
}
|
|
188
|
+
}, [hlsIsSupported, hlsSources, _ref12]);
|
|
160
189
|
var sourceFiles = useMemo(function () {
|
|
161
|
-
if (filesArray.length === 0) {
|
|
190
|
+
if (filesArray.length === 0 || hlsSources !== null && hlsSources.length > 0) {
|
|
162
191
|
return null;
|
|
163
192
|
}
|
|
164
193
|
var supportedMimes = getVideoSupportedMimes();
|
|
@@ -175,28 +204,28 @@ var Video = function Video(_ref) {
|
|
|
175
204
|
var _file$mime2 = file.mime,
|
|
176
205
|
mime = _file$mime2 === void 0 ? "video/".concat(fileHandle === 'h264' ? 'mp4' : fileHandle) : _file$mime2;
|
|
177
206
|
var currentMimeFile = filesMap[mime] || null;
|
|
178
|
-
var
|
|
179
|
-
|
|
180
|
-
currentId =
|
|
181
|
-
|
|
182
|
-
currentHandle =
|
|
207
|
+
var _ref5 = currentMimeFile || {},
|
|
208
|
+
_ref5$id = _ref5.id,
|
|
209
|
+
currentId = _ref5$id === void 0 ? null : _ref5$id,
|
|
210
|
+
_ref5$handle = _ref5.handle,
|
|
211
|
+
currentHandle = _ref5$handle === void 0 ? null : _ref5$handle;
|
|
183
212
|
var currentMimeHandle = currentHandle || currentId;
|
|
184
213
|
return currentMimeFile === null || currentMimeHandle === 'original' ? _objectSpread(_objectSpread({}, filesMap), {}, _defineProperty({}, mime, file)) : filesMap;
|
|
185
214
|
}, {});
|
|
186
215
|
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
187
216
|
return sourceFilesMap[mime];
|
|
188
217
|
});
|
|
189
|
-
}, [filesArray]);
|
|
218
|
+
}, [filesArray, hlsSources]);
|
|
190
219
|
|
|
191
220
|
// @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
192
|
-
var
|
|
193
|
-
var handle =
|
|
221
|
+
var _ref6 = filesArray.find(function (_ref7) {
|
|
222
|
+
var handle = _ref7.handle;
|
|
194
223
|
return handle === 'original';
|
|
195
224
|
}) || {},
|
|
196
|
-
|
|
197
|
-
originalType =
|
|
198
|
-
|
|
199
|
-
originalMime =
|
|
225
|
+
_ref6$type = _ref6.type,
|
|
226
|
+
originalType = _ref6$type === void 0 ? null : _ref6$type,
|
|
227
|
+
_ref6$mime = _ref6.mime,
|
|
228
|
+
originalMime = _ref6$mime === void 0 ? mediaMime : _ref6$mime;
|
|
200
229
|
var originalFileIsImage = originalType === 'image' || originalMime !== null && originalMime.indexOf('image/') === 0;
|
|
201
230
|
var isImageWithoutSourceFile = originalFileIsImage && (sourceFiles === null || sourceFiles.length === 0);
|
|
202
231
|
var withSize = width !== null && height !== null;
|
|
@@ -206,7 +235,7 @@ var Video = function Video(_ref) {
|
|
|
206
235
|
}
|
|
207
236
|
}, [duration, customOnDurationChange]);
|
|
208
237
|
var onVolumeChange = useCallback(function () {
|
|
209
|
-
var _ref$current =
|
|
238
|
+
var _ref$current = _ref12.current,
|
|
210
239
|
element = _ref$current === void 0 ? null : _ref$current;
|
|
211
240
|
if (element === null) {
|
|
212
241
|
return;
|
|
@@ -251,7 +280,7 @@ var Video = function Video(_ref) {
|
|
|
251
280
|
}
|
|
252
281
|
}, [ready, onReady]);
|
|
253
282
|
useEffect(function () {
|
|
254
|
-
var _ref$current2 =
|
|
283
|
+
var _ref$current2 = _ref12.current,
|
|
255
284
|
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
256
285
|
if (element === null) {
|
|
257
286
|
return;
|
|
@@ -288,14 +317,14 @@ var Video = function Video(_ref) {
|
|
|
288
317
|
}) : null, !isImageWithoutSourceFile ? /*#__PURE__*/React.createElement("video", {
|
|
289
318
|
key: mediaUrl,
|
|
290
319
|
ref: function ref(newRef) {
|
|
291
|
-
|
|
320
|
+
_ref12.current = newRef;
|
|
292
321
|
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
293
322
|
mediaRef(newRef);
|
|
294
323
|
} else if (mediaRef !== null) {
|
|
295
324
|
mediaRef.current = newRef;
|
|
296
325
|
}
|
|
297
326
|
},
|
|
298
|
-
src: sourceFiles === null || sourceFiles.length === 0 ? "".concat(mediaUrl, "#t=0.001") : null,
|
|
327
|
+
src: (sourceFiles === null || sourceFiles.length === 0) && (hlsSources === null || hlsSources.length === 0) ? "".concat(mediaUrl, "#t=0.001") : null,
|
|
299
328
|
autoPlay: autoPlay && !paused,
|
|
300
329
|
loop: loop,
|
|
301
330
|
muted: muted,
|
|
@@ -317,9 +346,9 @@ var Video = function Video(_ref) {
|
|
|
317
346
|
"data-has-audio": hasAudio,
|
|
318
347
|
"data-is-suspended": isSuspended,
|
|
319
348
|
"aria-hidden": true
|
|
320
|
-
}, (sourceFiles || []).map(function (
|
|
321
|
-
var sourceUrl =
|
|
322
|
-
sourceMime =
|
|
349
|
+
}, (sourceFiles || []).map(function (_ref11) {
|
|
350
|
+
var sourceUrl = _ref11.url,
|
|
351
|
+
sourceMime = _ref11.mime;
|
|
323
352
|
return /*#__PURE__*/React.createElement("source", {
|
|
324
353
|
key: "".concat(sourceUrl, "-").concat(sourceMime),
|
|
325
354
|
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.578",
|
|
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.578",
|
|
63
|
+
"@micromag/element-closed-captions": "^0.3.578",
|
|
64
64
|
"classnames": "^2.2.6",
|
|
65
65
|
"lodash": "^4.17.21",
|
|
66
66
|
"prop-types": "^15.7.2",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public",
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "924e621e3cf56f4d46abed790ef7f1f13ec29fb1"
|
|
75
75
|
}
|