@micromag/element-video 0.3.251 → 0.3.252
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 +9 -36
- package/lib/index.js +7 -34
- 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,
|
|
10
|
-
import { getMediaFilesAsArray } from '@micromag/core/utils';
|
|
9
|
+
import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useProgressSteps } from '@micromag/core/hooks';
|
|
10
|
+
import { getMediaFilesAsArray, getVideoSupportedMimes } 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,7 +40,6 @@ 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),
|
|
44
43
|
withPoster: PropTypes$1.bool // onPosterLoaded: PropTypes.func,
|
|
45
44
|
|
|
46
45
|
};
|
|
@@ -71,7 +70,6 @@ var defaultProps = {
|
|
|
71
70
|
onSuspend: null,
|
|
72
71
|
onSuspended: null,
|
|
73
72
|
focusable: true,
|
|
74
|
-
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
75
73
|
withPoster: false
|
|
76
74
|
};
|
|
77
75
|
|
|
@@ -104,7 +102,6 @@ var Video = function Video(_ref) {
|
|
|
104
102
|
customOnSuspend = _ref.onSuspend,
|
|
105
103
|
onSuspended = _ref.onSuspended,
|
|
106
104
|
focusable = _ref.focusable,
|
|
107
|
-
supportedMimes = _ref.supportedMimes,
|
|
108
105
|
withPoster = _ref.withPoster;
|
|
109
106
|
|
|
110
107
|
var _ref2 = media || {},
|
|
@@ -140,29 +137,21 @@ var Video = function Video(_ref) {
|
|
|
140
137
|
var ready = useMediaReady(_ref9.current, {
|
|
141
138
|
id: mediaUrl
|
|
142
139
|
});
|
|
143
|
-
useMediaLoad(_ref9.current, {
|
|
144
|
-
preload: preload,
|
|
145
|
-
shouldLoad: shouldLoad
|
|
146
|
-
}); // Get source files with supported mimes
|
|
147
|
-
|
|
148
140
|
var sourceFiles = useMemo(function () {
|
|
149
141
|
if (filesArray.length === 0) {
|
|
150
142
|
return null;
|
|
151
143
|
}
|
|
152
144
|
|
|
153
|
-
var
|
|
154
|
-
var finalSupportedMimes = supportedMimes.filter(function (mime) {
|
|
155
|
-
return supportVideo.canPlayType(mime) !== '';
|
|
156
|
-
});
|
|
145
|
+
var supportedMimes = getVideoSupportedMimes();
|
|
157
146
|
|
|
158
|
-
if (
|
|
147
|
+
if (supportedMimes.length === 0) {
|
|
159
148
|
return null;
|
|
160
149
|
}
|
|
161
150
|
|
|
162
151
|
var sourceFilesMap = filesArray.filter(function (file) {
|
|
163
152
|
var _file$mime = file.mime,
|
|
164
153
|
mime = _file$mime === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime;
|
|
165
|
-
return
|
|
154
|
+
return supportedMimes.indexOf(mime) !== -1;
|
|
166
155
|
}).reduce(function (filesMap, file) {
|
|
167
156
|
var _file$mime2 = file.mime,
|
|
168
157
|
mime = _file$mime2 === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime2;
|
|
@@ -177,7 +166,7 @@ var Video = function Video(_ref) {
|
|
|
177
166
|
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
178
167
|
return sourceFilesMap[mime];
|
|
179
168
|
});
|
|
180
|
-
}, [filesArray
|
|
169
|
+
}, [filesArray]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
181
170
|
|
|
182
171
|
var _ref5 = filesArray.find(function (_ref6) {
|
|
183
172
|
var handle = _ref6.handle;
|
|
@@ -240,31 +229,15 @@ var Video = function Video(_ref) {
|
|
|
240
229
|
if (customOnSuspend !== null) {
|
|
241
230
|
customOnSuspend(e);
|
|
242
231
|
}
|
|
243
|
-
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
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]);
|
|
232
|
+
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
260
233
|
useEffect(function () {
|
|
261
234
|
if (ready && onReady !== null) {
|
|
262
235
|
onReady();
|
|
263
236
|
}
|
|
264
237
|
}, [ready, onReady]);
|
|
265
238
|
useEffect(function () {
|
|
266
|
-
var _ref$
|
|
267
|
-
element = _ref$
|
|
239
|
+
var _ref$current2 = _ref9.current,
|
|
240
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
268
241
|
|
|
269
242
|
if (element === null) {
|
|
270
243
|
return;
|
package/lib/index.js
CHANGED
|
@@ -52,7 +52,6 @@ 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),
|
|
56
55
|
withPoster: PropTypes__default["default"].bool // onPosterLoaded: PropTypes.func,
|
|
57
56
|
|
|
58
57
|
};
|
|
@@ -83,7 +82,6 @@ var defaultProps = {
|
|
|
83
82
|
onSuspend: null,
|
|
84
83
|
onSuspended: null,
|
|
85
84
|
focusable: true,
|
|
86
|
-
supportedMimes: ['video/mp4', 'video/webm', 'video/ogg'],
|
|
87
85
|
withPoster: false
|
|
88
86
|
};
|
|
89
87
|
|
|
@@ -116,7 +114,6 @@ var Video = function Video(_ref) {
|
|
|
116
114
|
customOnSuspend = _ref.onSuspend,
|
|
117
115
|
onSuspended = _ref.onSuspended,
|
|
118
116
|
focusable = _ref.focusable,
|
|
119
|
-
supportedMimes = _ref.supportedMimes,
|
|
120
117
|
withPoster = _ref.withPoster;
|
|
121
118
|
|
|
122
119
|
var _ref2 = media || {},
|
|
@@ -152,29 +149,21 @@ var Video = function Video(_ref) {
|
|
|
152
149
|
var ready = hooks.useMediaReady(_ref9.current, {
|
|
153
150
|
id: mediaUrl
|
|
154
151
|
});
|
|
155
|
-
hooks.useMediaLoad(_ref9.current, {
|
|
156
|
-
preload: preload,
|
|
157
|
-
shouldLoad: shouldLoad
|
|
158
|
-
}); // Get source files with supported mimes
|
|
159
|
-
|
|
160
152
|
var sourceFiles = React.useMemo(function () {
|
|
161
153
|
if (filesArray.length === 0) {
|
|
162
154
|
return null;
|
|
163
155
|
}
|
|
164
156
|
|
|
165
|
-
var
|
|
166
|
-
var finalSupportedMimes = supportedMimes.filter(function (mime) {
|
|
167
|
-
return supportVideo.canPlayType(mime) !== '';
|
|
168
|
-
});
|
|
157
|
+
var supportedMimes = utils.getVideoSupportedMimes();
|
|
169
158
|
|
|
170
|
-
if (
|
|
159
|
+
if (supportedMimes.length === 0) {
|
|
171
160
|
return null;
|
|
172
161
|
}
|
|
173
162
|
|
|
174
163
|
var sourceFilesMap = filesArray.filter(function (file) {
|
|
175
164
|
var _file$mime = file.mime,
|
|
176
165
|
mime = _file$mime === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime;
|
|
177
|
-
return
|
|
166
|
+
return supportedMimes.indexOf(mime) !== -1;
|
|
178
167
|
}).reduce(function (filesMap, file) {
|
|
179
168
|
var _file$mime2 = file.mime,
|
|
180
169
|
mime = _file$mime2 === void 0 ? "video/".concat(file.id === 'h264' ? 'mp4' : file.id) : _file$mime2;
|
|
@@ -189,7 +178,7 @@ var Video = function Video(_ref) {
|
|
|
189
178
|
return Object.keys(sourceFilesMap).map(function (mime) {
|
|
190
179
|
return sourceFilesMap[mime];
|
|
191
180
|
});
|
|
192
|
-
}, [filesArray
|
|
181
|
+
}, [filesArray]); // @NOTE: Media is an animated image and doesn't have source files in video formats
|
|
193
182
|
|
|
194
183
|
var _ref5 = filesArray.find(function (_ref6) {
|
|
195
184
|
var handle = _ref6.handle;
|
|
@@ -252,31 +241,15 @@ var Video = function Video(_ref) {
|
|
|
252
241
|
if (customOnSuspend !== null) {
|
|
253
242
|
customOnSuspend(e);
|
|
254
243
|
}
|
|
255
|
-
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
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]);
|
|
244
|
+
}, [isSuspended, paused, setIsSuspended, customOnSuspend, onSuspended]);
|
|
272
245
|
React.useEffect(function () {
|
|
273
246
|
if (ready && onReady !== null) {
|
|
274
247
|
onReady();
|
|
275
248
|
}
|
|
276
249
|
}, [ready, onReady]);
|
|
277
250
|
React.useEffect(function () {
|
|
278
|
-
var _ref$
|
|
279
|
-
element = _ref$
|
|
251
|
+
var _ref$current2 = _ref9.current,
|
|
252
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
280
253
|
|
|
281
254
|
if (element === null) {
|
|
282
255
|
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.252",
|
|
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.252",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.252",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.252",
|
|
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": "67a8b8144a40086a6dfd98c9eb8c4b6b8ebb05b0"
|
|
68
68
|
}
|