@micromag/element-video 0.3.246 → 0.3.251
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 -9
- package/lib/index.js +34 -7
- package/package.json +5 -5
package/es/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import isFunction from 'lodash/isFunction';
|
|
|
6
6
|
import PropTypes$1 from 'prop-types';
|
|
7
7
|
import React, { useMemo, useRef, useEffect, useCallback, useState } from 'react';
|
|
8
8
|
import { PropTypes } from '@micromag/core';
|
|
9
|
-
import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useProgressSteps } from '@micromag/core/hooks';
|
|
10
|
-
import { getMediaFilesAsArray
|
|
9
|
+
import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useMediaLoad, useProgressSteps } from '@micromag/core/hooks';
|
|
10
|
+
import { getMediaFilesAsArray } from '@micromag/core/utils';
|
|
11
11
|
|
|
12
12
|
var styles = {"container":"micromag-element-video-container","withSize":"micromag-element-video-withSize","video":"micromag-element-video-video"};
|
|
13
13
|
|
|
@@ -40,6 +40,7 @@ var propTypes = {
|
|
|
40
40
|
onSuspend: PropTypes$1.func,
|
|
41
41
|
onSuspended: PropTypes$1.func,
|
|
42
42
|
focusable: PropTypes$1.bool,
|
|
43
|
+
supportedMimes: PropTypes$1.arrayOf(PropTypes$1.string),
|
|
43
44
|
withPoster: PropTypes$1.bool // onPosterLoaded: PropTypes.func,
|
|
44
45
|
|
|
45
46
|
};
|
|
@@ -70,6 +71,7 @@ var defaultProps = {
|
|
|
70
71
|
onSuspend: null,
|
|
71
72
|
onSuspended: null,
|
|
72
73
|
focusable: true,
|
|
74
|
+
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
73
75
|
withPoster: false
|
|
74
76
|
};
|
|
75
77
|
|
|
@@ -102,6 +104,7 @@ var Video = function Video(_ref) {
|
|
|
102
104
|
customOnSuspend = _ref.onSuspend,
|
|
103
105
|
onSuspended = _ref.onSuspended,
|
|
104
106
|
focusable = _ref.focusable,
|
|
107
|
+
supportedMimes = _ref.supportedMimes,
|
|
105
108
|
withPoster = _ref.withPoster;
|
|
106
109
|
|
|
107
110
|
var _ref2 = media || {},
|
|
@@ -137,21 +140,29 @@ var Video = function Video(_ref) {
|
|
|
137
140
|
var ready = useMediaReady(_ref9.current, {
|
|
138
141
|
id: mediaUrl
|
|
139
142
|
});
|
|
143
|
+
useMediaLoad(_ref9.current, {
|
|
144
|
+
preload: preload,
|
|
145
|
+
shouldLoad: shouldLoad
|
|
146
|
+
}); // Get source files with supported mimes
|
|
147
|
+
|
|
140
148
|
var sourceFiles = useMemo(function () {
|
|
141
149
|
if (filesArray.length === 0) {
|
|
142
150
|
return null;
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
var
|
|
153
|
+
var supportVideo = document.createElement('video');
|
|
154
|
+
var finalSupportedMimes = supportedMimes.filter(function (mime) {
|
|
155
|
+
return supportVideo.canPlayType(mime) !== '';
|
|
156
|
+
});
|
|
146
157
|
|
|
147
|
-
if (
|
|
158
|
+
if (finalSupportedMimes.length === 0) {
|
|
148
159
|
return null;
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
var sourceFilesMap = filesArray.filter(function (file) {
|
|
152
163
|
var _file$mime = file.mime,
|
|
153
164
|
mime = _file$mime === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime;
|
|
154
|
-
return
|
|
165
|
+
return finalSupportedMimes.indexOf(mime) !== -1;
|
|
155
166
|
}).reduce(function (filesMap, file) {
|
|
156
167
|
var _file$mime2 = file.mime,
|
|
157
168
|
mime = _file$mime2 === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime2;
|
|
@@ -166,7 +177,7 @@ var Video = function Video(_ref) {
|
|
|
166
177
|
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
167
178
|
return sourceFilesMap[mime];
|
|
168
179
|
});
|
|
169
|
-
}, [filesArray]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
180
|
+
}, [filesArray, supportedMimes]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
170
181
|
|
|
171
182
|
var _ref5 = filesArray.find(function (_ref6) {
|
|
172
183
|
var handle = _ref6.handle;
|
|
@@ -229,15 +240,31 @@ var Video = function Video(_ref) {
|
|
|
229
240
|
if (customOnSuspend !== null) {
|
|
230
241
|
customOnSuspend(e);
|
|
231
242
|
}
|
|
232
|
-
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
243
|
+
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]); // Ensure load if preload value change over time
|
|
244
|
+
|
|
245
|
+
var firstPreloadRef = useRef(preload);
|
|
246
|
+
var firstShouldLoadRef = useRef(shouldLoad);
|
|
247
|
+
var hasLoadedRef = useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
248
|
+
useEffect(function () {
|
|
249
|
+
var _ref$current2 = _ref9.current,
|
|
250
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
251
|
+
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad;
|
|
252
|
+
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
253
|
+
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
254
|
+
|
|
255
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
256
|
+
hasLoadedRef.current = true;
|
|
257
|
+
element.load();
|
|
258
|
+
}
|
|
259
|
+
}, [shouldLoad, preload]);
|
|
233
260
|
useEffect(function () {
|
|
234
261
|
if (ready && onReady !== null) {
|
|
235
262
|
onReady();
|
|
236
263
|
}
|
|
237
264
|
}, [ready, onReady]);
|
|
238
265
|
useEffect(function () {
|
|
239
|
-
var _ref$
|
|
240
|
-
element = _ref$
|
|
266
|
+
var _ref$current3 = _ref9.current,
|
|
267
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
241
268
|
|
|
242
269
|
if (element === null) {
|
|
243
270
|
return;
|
package/lib/index.js
CHANGED
|
@@ -52,6 +52,7 @@ var propTypes = {
|
|
|
52
52
|
onSuspend: PropTypes__default["default"].func,
|
|
53
53
|
onSuspended: PropTypes__default["default"].func,
|
|
54
54
|
focusable: PropTypes__default["default"].bool,
|
|
55
|
+
supportedMimes: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
|
|
55
56
|
withPoster: PropTypes__default["default"].bool // onPosterLoaded: PropTypes.func,
|
|
56
57
|
|
|
57
58
|
};
|
|
@@ -82,6 +83,7 @@ var defaultProps = {
|
|
|
82
83
|
onSuspend: null,
|
|
83
84
|
onSuspended: null,
|
|
84
85
|
focusable: true,
|
|
86
|
+
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
85
87
|
withPoster: false
|
|
86
88
|
};
|
|
87
89
|
|
|
@@ -114,6 +116,7 @@ var Video = function Video(_ref) {
|
|
|
114
116
|
customOnSuspend = _ref.onSuspend,
|
|
115
117
|
onSuspended = _ref.onSuspended,
|
|
116
118
|
focusable = _ref.focusable,
|
|
119
|
+
supportedMimes = _ref.supportedMimes,
|
|
117
120
|
withPoster = _ref.withPoster;
|
|
118
121
|
|
|
119
122
|
var _ref2 = media || {},
|
|
@@ -149,21 +152,29 @@ var Video = function Video(_ref) {
|
|
|
149
152
|
var ready = hooks.useMediaReady(_ref9.current, {
|
|
150
153
|
id: mediaUrl
|
|
151
154
|
});
|
|
155
|
+
hooks.useMediaLoad(_ref9.current, {
|
|
156
|
+
preload: preload,
|
|
157
|
+
shouldLoad: shouldLoad
|
|
158
|
+
}); // Get source files with supported mimes
|
|
159
|
+
|
|
152
160
|
var sourceFiles = React.useMemo(function () {
|
|
153
161
|
if (filesArray.length === 0) {
|
|
154
162
|
return null;
|
|
155
163
|
}
|
|
156
164
|
|
|
157
|
-
var
|
|
165
|
+
var supportVideo = document.createElement('video');
|
|
166
|
+
var finalSupportedMimes = supportedMimes.filter(function (mime) {
|
|
167
|
+
return supportVideo.canPlayType(mime) !== '';
|
|
168
|
+
});
|
|
158
169
|
|
|
159
|
-
if (
|
|
170
|
+
if (finalSupportedMimes.length === 0) {
|
|
160
171
|
return null;
|
|
161
172
|
}
|
|
162
173
|
|
|
163
174
|
var sourceFilesMap = filesArray.filter(function (file) {
|
|
164
175
|
var _file$mime = file.mime,
|
|
165
176
|
mime = _file$mime === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime;
|
|
166
|
-
return
|
|
177
|
+
return finalSupportedMimes.indexOf(mime) !== -1;
|
|
167
178
|
}).reduce(function (filesMap, file) {
|
|
168
179
|
var _file$mime2 = file.mime,
|
|
169
180
|
mime = _file$mime2 === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime2;
|
|
@@ -178,7 +189,7 @@ var Video = function Video(_ref) {
|
|
|
178
189
|
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
179
190
|
return sourceFilesMap[mime];
|
|
180
191
|
});
|
|
181
|
-
}, [filesArray]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
192
|
+
}, [filesArray, supportedMimes]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
182
193
|
|
|
183
194
|
var _ref5 = filesArray.find(function (_ref6) {
|
|
184
195
|
var handle = _ref6.handle;
|
|
@@ -241,15 +252,31 @@ var Video = function Video(_ref) {
|
|
|
241
252
|
if (customOnSuspend !== null) {
|
|
242
253
|
customOnSuspend(e);
|
|
243
254
|
}
|
|
244
|
-
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
255
|
+
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]); // Ensure load if preload value change over time
|
|
256
|
+
|
|
257
|
+
var firstPreloadRef = React.useRef(preload);
|
|
258
|
+
var firstShouldLoadRef = React.useRef(shouldLoad);
|
|
259
|
+
var hasLoadedRef = React.useRef(preload !== 'none' && preload !== 'metadata' && shouldLoad);
|
|
260
|
+
React.useEffect(function () {
|
|
261
|
+
var _ref$current2 = _ref9.current,
|
|
262
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
263
|
+
var canLoad = preload !== 'none' && preload !== 'metadata' && shouldLoad;
|
|
264
|
+
var preloadHasChanged = firstPreloadRef.current !== preload;
|
|
265
|
+
var shouldLoadHasChanged = firstShouldLoadRef.current !== shouldLoad;
|
|
266
|
+
|
|
267
|
+
if (canLoad && (preloadHasChanged || shouldLoadHasChanged) && !hasLoadedRef.current && element !== null && typeof element.load !== 'undefined') {
|
|
268
|
+
hasLoadedRef.current = true;
|
|
269
|
+
element.load();
|
|
270
|
+
}
|
|
271
|
+
}, [shouldLoad, preload]);
|
|
245
272
|
React.useEffect(function () {
|
|
246
273
|
if (ready && onReady !== null) {
|
|
247
274
|
onReady();
|
|
248
275
|
}
|
|
249
276
|
}, [ready, onReady]);
|
|
250
277
|
React.useEffect(function () {
|
|
251
|
-
var _ref$
|
|
252
|
-
element = _ref$
|
|
278
|
+
var _ref$current3 = _ref9.current,
|
|
279
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
253
280
|
|
|
254
281
|
if (element === null) {
|
|
255
282
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-video",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.251",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
53
53
|
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
54
54
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
55
|
-
"@micromag/core": "^0.3.
|
|
56
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
57
|
-
"@micromag/element-media-controls": "^0.3.
|
|
55
|
+
"@micromag/core": "^0.3.251",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.251",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.251",
|
|
58
58
|
"classnames": "^2.2.6",
|
|
59
59
|
"lodash": "^4.17.21",
|
|
60
60
|
"prop-types": "^15.7.2",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "3b6fb00baaa7f3ab90684a88cbe4c30929b6b27d"
|
|
68
68
|
}
|