@micromag/screen-video-360 0.4.71 → 0.4.74
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.d.ts +2 -2
- package/es/index.js +273 -322
- package/package.json +16 -15
package/es/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ForwardedRef } from 'react';
|
|
3
|
-
import { VideoElement, Header, Footer, BackgroundElement } from '@micromag/core';
|
|
3
|
+
import { VideoElement, Header, Footer, BackgroundElement, MediaElement } from '@micromag/core';
|
|
4
4
|
|
|
5
5
|
interface Video360ScreenProps {
|
|
6
6
|
layout?: 'full';
|
|
@@ -12,7 +12,7 @@ interface Video360ScreenProps {
|
|
|
12
12
|
preload?: boolean;
|
|
13
13
|
type?: string | null;
|
|
14
14
|
spacing?: number;
|
|
15
|
-
mediaRef?: ForwardedRef<
|
|
15
|
+
mediaRef?: ForwardedRef<MediaElement> | null;
|
|
16
16
|
className?: string | null;
|
|
17
17
|
}
|
|
18
18
|
declare function Video360Screen({ layout: _layout, video, header, footer, background, current, preload, type, spacing, mediaRef: customMediaRef, className, }: Video360ScreenProps): react_jsx_runtime.JSX.Element;
|
package/es/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { FormattedMessage, defineMessage } from 'react-intl';
|
|
2
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
4
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
2
|
import { getSizeWithinBounds } from '@folklore/size';
|
|
6
3
|
import classNames from 'classnames';
|
|
7
4
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
8
5
|
import { ScreenElement, PlaceholderVideo360 } from '@micromag/core/components';
|
|
9
|
-
import { useViewerInteraction, useViewerNavigation, useViewerContext, useScreenSize, useScreenRenderContext, useViewerWebView, usePlaybackContext, usePlaybackMediaRef,
|
|
10
|
-
import { useTrackScreenEvent, useTrackScreenMedia, useDevicePixelRatio,
|
|
6
|
+
import { useViewerInteraction, useViewerNavigation, useViewerContext, useScreenSize, useScreenRenderContext, useViewerWebView, usePlaybackContext, usePlaybackMediaRef, useViewerActivityDetected } from '@micromag/core/contexts';
|
|
7
|
+
import { useTrackScreenEvent, useTrackScreenMedia, useDevicePixelRatio, useDebounce, useAnimationFrame } from '@micromag/core/hooks';
|
|
11
8
|
import { isHeaderFilled, isFooterFilled, getFooterProps, mergeRefs } from '@micromag/core/utils';
|
|
12
9
|
import Background from '@micromag/element-background';
|
|
13
10
|
import ClosedCaptions from '@micromag/element-closed-captions';
|
|
@@ -21,48 +18,48 @@ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
|
21
18
|
/**
|
|
22
19
|
* Locale loader
|
|
23
20
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
let packageCache = null;
|
|
22
|
+
const useThree = () => {
|
|
26
23
|
// transport
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var canceled = false;
|
|
24
|
+
const [{
|
|
25
|
+
package: loadedPackage
|
|
26
|
+
}, setLoadedPackage] = useState({
|
|
27
|
+
package: packageCache
|
|
28
|
+
});
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
let canceled = false;
|
|
35
31
|
if (loadedPackage !== null) {
|
|
36
|
-
return
|
|
32
|
+
return () => {
|
|
37
33
|
canceled = true;
|
|
38
34
|
};
|
|
39
35
|
}
|
|
40
|
-
import('three').then(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
import('three').then(({
|
|
37
|
+
Scene,
|
|
38
|
+
PerspectiveCamera,
|
|
39
|
+
SphereBufferGeometry,
|
|
40
|
+
VideoTexture,
|
|
41
|
+
MeshBasicMaterial,
|
|
42
|
+
Mesh,
|
|
43
|
+
WebGLRenderer,
|
|
44
|
+
MathUtils
|
|
45
|
+
}) => {
|
|
49
46
|
packageCache = {
|
|
50
|
-
Scene
|
|
51
|
-
PerspectiveCamera
|
|
52
|
-
SphereBufferGeometry
|
|
53
|
-
VideoTexture
|
|
54
|
-
MeshBasicMaterial
|
|
55
|
-
Mesh
|
|
56
|
-
WebGLRenderer
|
|
57
|
-
MathUtils
|
|
47
|
+
Scene,
|
|
48
|
+
PerspectiveCamera,
|
|
49
|
+
SphereBufferGeometry,
|
|
50
|
+
VideoTexture,
|
|
51
|
+
MeshBasicMaterial,
|
|
52
|
+
Mesh,
|
|
53
|
+
WebGLRenderer,
|
|
54
|
+
MathUtils
|
|
58
55
|
};
|
|
59
56
|
if (!canceled) {
|
|
60
57
|
setLoadedPackage({
|
|
61
|
-
|
|
58
|
+
package: packageCache
|
|
62
59
|
});
|
|
63
60
|
}
|
|
64
61
|
});
|
|
65
|
-
return
|
|
62
|
+
return () => {
|
|
66
63
|
canceled = true;
|
|
67
64
|
};
|
|
68
65
|
}, [loadedPackage, setLoadedPackage]);
|
|
@@ -71,135 +68,120 @@ var useThree = function useThree() {
|
|
|
71
68
|
|
|
72
69
|
var styles = {"container":"micromag-screen-video-360-container","background":"micromag-screen-video-360-background","content":"micromag-screen-video-360-content","empty":"micromag-screen-video-360-empty","inner":"micromag-screen-video-360-inner","canvas":"micromag-screen-video-360-canvas","canvasButton":"micromag-screen-video-360-canvasButton","video":"micromag-screen-video-360-video","videoContainer":"micromag-screen-video-360-videoContainer","placeholder":"micromag-screen-video-360-placeholder","header":"micromag-screen-video-360-header","bottom":"micromag-screen-video-360-bottom","showVideo":"micromag-screen-video-360-showVideo"};
|
|
73
70
|
|
|
74
|
-
function Video360Screen(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
currentQualityLevel = _usePlaybackContext.currentQualityLevel,
|
|
154
|
-
setCurrentQualityLevel = _usePlaybackContext.setCurrentQualityLevel;
|
|
155
|
-
var _usePlaybackMediaRef = usePlaybackMediaRef(current),
|
|
156
|
-
mediaRef = _usePlaybackMediaRef.ref,
|
|
157
|
-
_usePlaybackMediaRef$ = _usePlaybackMediaRef.isCurrent,
|
|
158
|
-
isCurrentMedia = _usePlaybackMediaRef$ === void 0 ? false : _usePlaybackMediaRef$;
|
|
159
|
-
var backgroundPlaying = current && (isView || isEdit) && (isCurrentMedia || !isView);
|
|
160
|
-
var videoPlaying = current && (isView || isEdit) && playing && (isCurrentMedia || !isView);
|
|
161
|
-
useEffect(function () {
|
|
71
|
+
function Video360Screen({
|
|
72
|
+
layout: _layout = 'full',
|
|
73
|
+
video = null,
|
|
74
|
+
header = null,
|
|
75
|
+
footer = null,
|
|
76
|
+
background = null,
|
|
77
|
+
current = true,
|
|
78
|
+
preload = true,
|
|
79
|
+
type = null,
|
|
80
|
+
spacing = 20,
|
|
81
|
+
mediaRef: customMediaRef = null,
|
|
82
|
+
className = null
|
|
83
|
+
}) {
|
|
84
|
+
const THREE = useThree();
|
|
85
|
+
const trackScreenEvent = useTrackScreenEvent(type);
|
|
86
|
+
const trackScreenMedia = useTrackScreenMedia('video_360');
|
|
87
|
+
const {
|
|
88
|
+
enableInteraction,
|
|
89
|
+
disableInteraction
|
|
90
|
+
} = useViewerInteraction();
|
|
91
|
+
const {
|
|
92
|
+
gotoPreviousScreen,
|
|
93
|
+
gotoNextScreen
|
|
94
|
+
} = useViewerNavigation();
|
|
95
|
+
const {
|
|
96
|
+
topHeight: viewerTopHeight,
|
|
97
|
+
bottomHeight: viewerBottomHeight,
|
|
98
|
+
bottomSidesWidth: viewerBottomSidesWidth
|
|
99
|
+
} = useViewerContext();
|
|
100
|
+
const {
|
|
101
|
+
width,
|
|
102
|
+
height,
|
|
103
|
+
landscape,
|
|
104
|
+
resolution
|
|
105
|
+
} = useScreenSize();
|
|
106
|
+
const {
|
|
107
|
+
isView,
|
|
108
|
+
isPreview,
|
|
109
|
+
isPlaceholder,
|
|
110
|
+
isEdit,
|
|
111
|
+
isStatic,
|
|
112
|
+
isCapture
|
|
113
|
+
} = useScreenRenderContext();
|
|
114
|
+
const {
|
|
115
|
+
open: openWebView
|
|
116
|
+
} = useViewerWebView();
|
|
117
|
+
const devicePixelRatio = useDevicePixelRatio();
|
|
118
|
+
const mediaShouldLoad = current || preload;
|
|
119
|
+
const {
|
|
120
|
+
media: videoMedia = null,
|
|
121
|
+
closedCaptions = null,
|
|
122
|
+
captions = null,
|
|
123
|
+
withSeekBar = false,
|
|
124
|
+
withControls = false,
|
|
125
|
+
autoPlay = true,
|
|
126
|
+
color = null,
|
|
127
|
+
progressColor = null
|
|
128
|
+
} = video || {};
|
|
129
|
+
const videoContainerRef = useRef();
|
|
130
|
+
const {
|
|
131
|
+
playing,
|
|
132
|
+
muted,
|
|
133
|
+
setControls,
|
|
134
|
+
setControlsTheme,
|
|
135
|
+
setControlsSuggestPlay,
|
|
136
|
+
setMedia,
|
|
137
|
+
setPlaying,
|
|
138
|
+
showControls,
|
|
139
|
+
hideControls,
|
|
140
|
+
currentQualityLevel,
|
|
141
|
+
setCurrentQualityLevel
|
|
142
|
+
} = usePlaybackContext();
|
|
143
|
+
const {
|
|
144
|
+
ref: mediaRef,
|
|
145
|
+
isCurrent: isCurrentMedia = false
|
|
146
|
+
} = usePlaybackMediaRef(current);
|
|
147
|
+
const backgroundPlaying = current && (isView || isEdit) && (isCurrentMedia || !isView);
|
|
148
|
+
const videoPlaying = current && (isView || isEdit) && playing && (isCurrentMedia || !isView);
|
|
149
|
+
useEffect(() => {
|
|
162
150
|
if (!current) {
|
|
163
|
-
return
|
|
151
|
+
return () => {};
|
|
164
152
|
}
|
|
165
153
|
if (withControls || withSeekBar) {
|
|
166
154
|
setControls(true);
|
|
167
155
|
setControlsTheme({
|
|
168
156
|
seekBarOnly: withSeekBar && !withControls,
|
|
169
|
-
color
|
|
170
|
-
progressColor
|
|
157
|
+
color,
|
|
158
|
+
progressColor
|
|
171
159
|
});
|
|
172
160
|
} else {
|
|
173
161
|
setControls(false);
|
|
174
162
|
}
|
|
175
|
-
return
|
|
163
|
+
return () => {
|
|
176
164
|
if (withControls || withSeekBar) {
|
|
177
165
|
setControls(false);
|
|
178
166
|
}
|
|
179
167
|
};
|
|
180
168
|
}, [current, withControls, setControls, withSeekBar, color, progressColor]);
|
|
181
|
-
useEffect(
|
|
169
|
+
useEffect(() => {
|
|
182
170
|
if (!current) {
|
|
183
|
-
return
|
|
171
|
+
return () => {};
|
|
184
172
|
}
|
|
185
173
|
setMedia(mediaRef.current);
|
|
186
|
-
return
|
|
174
|
+
return () => {
|
|
187
175
|
setMedia(null);
|
|
188
176
|
};
|
|
189
177
|
}, [current]);
|
|
190
|
-
useEffect(
|
|
178
|
+
useEffect(() => {
|
|
191
179
|
if (current && autoPlay && !playing) {
|
|
192
180
|
setPlaying(true);
|
|
193
181
|
}
|
|
194
182
|
}, [current, autoPlay]);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
element: viewerContainer,
|
|
198
|
-
disabled: !isView,
|
|
199
|
-
timeout: 2000
|
|
200
|
-
}),
|
|
201
|
-
activityDetected = _useActivityDetector.detected;
|
|
202
|
-
var toggleControlsVisibility = useCallback(function () {
|
|
183
|
+
const activityDetected = useViewerActivityDetected();
|
|
184
|
+
const toggleControlsVisibility = useCallback(() => {
|
|
203
185
|
if (activityDetected) {
|
|
204
186
|
showControls();
|
|
205
187
|
} else {
|
|
@@ -207,37 +189,33 @@ function Video360Screen(_ref) {
|
|
|
207
189
|
}
|
|
208
190
|
}, [activityDetected, showControls, hideControls]);
|
|
209
191
|
useDebounce(toggleControlsVisibility, activityDetected, 1000);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
setCurrentTime = _useState2[1];
|
|
214
|
-
var _useState3 = useState(null),
|
|
215
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
216
|
-
duration = _useState4[0],
|
|
217
|
-
setDuration = _useState4[1];
|
|
218
|
-
var onTimeUpdate = useCallback(function (time) {
|
|
192
|
+
const [currentTime, setCurrentTime] = useState(null);
|
|
193
|
+
const [duration, setDuration] = useState(null);
|
|
194
|
+
const onTimeUpdate = useCallback(time => {
|
|
219
195
|
setCurrentTime(time);
|
|
220
196
|
}, [setDuration, duration]);
|
|
221
|
-
|
|
222
|
-
trackScreenMedia(videoMedia,
|
|
197
|
+
const onProgressStep = useCallback((step, meta) => {
|
|
198
|
+
trackScreenMedia(videoMedia, `progress_${Math.round(step * 100, 10)}%`, meta);
|
|
223
199
|
}, [trackScreenMedia, videoMedia]);
|
|
224
|
-
|
|
200
|
+
const onDurationChange = useCallback(dur => {
|
|
225
201
|
setDuration(dur);
|
|
226
202
|
}, [setDuration]);
|
|
227
|
-
|
|
228
|
-
|
|
203
|
+
const onPlay = useCallback(({
|
|
204
|
+
initial
|
|
205
|
+
}) => {
|
|
229
206
|
trackScreenMedia(videoMedia, initial ? 'play' : 'resume');
|
|
230
207
|
}, [trackScreenMedia, videoMedia]);
|
|
231
|
-
|
|
232
|
-
|
|
208
|
+
const onPause = useCallback(({
|
|
209
|
+
midway
|
|
210
|
+
}) => {
|
|
233
211
|
trackScreenMedia(videoMedia, midway ? 'pause' : 'ended');
|
|
234
212
|
}, [trackScreenMedia, videoMedia]);
|
|
235
|
-
|
|
236
|
-
if (
|
|
213
|
+
const onSeeked = useCallback(time_0 => {
|
|
214
|
+
if (time_0 > 0) {
|
|
237
215
|
trackScreenMedia(videoMedia, 'seek');
|
|
238
216
|
}
|
|
239
217
|
}, [trackScreenMedia, videoMedia]);
|
|
240
|
-
|
|
218
|
+
const onEnded = useCallback(() => {
|
|
241
219
|
if (current) {
|
|
242
220
|
setPlaying(false);
|
|
243
221
|
}
|
|
@@ -245,91 +223,86 @@ function Video360Screen(_ref) {
|
|
|
245
223
|
|
|
246
224
|
// ------------------------------------
|
|
247
225
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
251
|
-
ready = _useState6[0],
|
|
252
|
-
setReady = _useState6[1];
|
|
226
|
+
const hasVideo = video !== null;
|
|
227
|
+
const [ready, setReady] = useState(!hasVideo);
|
|
253
228
|
|
|
254
229
|
// const transitionPlaying = current && ready;
|
|
255
230
|
// const transitionDisabled = isStatic || isCapture || isPlaceholder || isPreview || isEdit;
|
|
256
231
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
isView
|
|
261
|
-
current
|
|
262
|
-
openWebView
|
|
263
|
-
isPreview
|
|
264
|
-
enableInteraction
|
|
265
|
-
disableInteraction
|
|
232
|
+
const hasHeader = isHeaderFilled(header);
|
|
233
|
+
const hasFooter = isFooterFilled(footer);
|
|
234
|
+
const footerProps = getFooterProps(footer, {
|
|
235
|
+
isView,
|
|
236
|
+
current,
|
|
237
|
+
openWebView,
|
|
238
|
+
isPreview,
|
|
239
|
+
enableInteraction,
|
|
240
|
+
disableInteraction
|
|
266
241
|
});
|
|
267
|
-
|
|
242
|
+
const finalVideo = hasVideo ? {
|
|
243
|
+
...video,
|
|
268
244
|
autoPlay: !isPreview && !isStatic && !isCapture && autoPlay && current
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
resizedVideoWidth = _getSizeWithinBounds.width,
|
|
293
|
-
resizedVideoHeight = _getSizeWithinBounds.height;
|
|
294
|
-
var resizedVideoLeft = -(resizedVideoWidth - width) / 2;
|
|
295
|
-
var resizedVideoTop = -(resizedVideoHeight - height) / 2;
|
|
296
|
-
useEffect(function () {
|
|
245
|
+
} : null;
|
|
246
|
+
const {
|
|
247
|
+
metadata: videoMetadata = null,
|
|
248
|
+
url: videoUrl = null,
|
|
249
|
+
thumbnail_url: thumbnailUrl = null
|
|
250
|
+
} = videoMedia || {};
|
|
251
|
+
const hasVideoUrl = videoUrl !== null;
|
|
252
|
+
const {
|
|
253
|
+
width: videoWidth = 0,
|
|
254
|
+
height: videoHeight = 0
|
|
255
|
+
} = videoMetadata || {};
|
|
256
|
+
const hasThumbnail = thumbnailUrl !== null;
|
|
257
|
+
const [posterReady, setPosterReady] = useState(!hasThumbnail);
|
|
258
|
+
const withVideoSphere = hasVideoUrl && (isView || isEdit) && !isCapture && !isStatic;
|
|
259
|
+
const {
|
|
260
|
+
width: resizedVideoWidth,
|
|
261
|
+
height: resizedVideoHeight
|
|
262
|
+
} = getSizeWithinBounds(videoWidth, videoHeight, width, height, {
|
|
263
|
+
cover: true
|
|
264
|
+
});
|
|
265
|
+
const resizedVideoLeft = -(resizedVideoWidth - width) / 2;
|
|
266
|
+
const resizedVideoTop = -(resizedVideoHeight - height) / 2;
|
|
267
|
+
useEffect(() => {
|
|
297
268
|
setReady(!hasVideoUrl);
|
|
298
269
|
}, [videoUrl, hasVideoUrl, setReady]);
|
|
299
|
-
useEffect(
|
|
270
|
+
useEffect(() => {
|
|
300
271
|
setPosterReady(!hasThumbnail);
|
|
301
272
|
}, [thumbnailUrl, hasThumbnail, setPosterReady]);
|
|
302
|
-
|
|
273
|
+
const onVideoReady = useCallback(() => {
|
|
303
274
|
setReady(true);
|
|
304
275
|
}, [setReady]);
|
|
305
|
-
|
|
276
|
+
const onPosterLoaded = useCallback(() => {
|
|
306
277
|
setPosterReady(true);
|
|
307
278
|
}, [posterReady]);
|
|
308
279
|
|
|
309
280
|
// 3D layer --------------------------
|
|
310
281
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
282
|
+
const canvasRef = useRef(null);
|
|
283
|
+
const camera = useRef(null);
|
|
284
|
+
const scene = useRef(null);
|
|
285
|
+
const renderer = useRef(null);
|
|
286
|
+
const lon = useRef(0);
|
|
287
|
+
const lat = useRef(0);
|
|
288
|
+
const phi = useRef(0);
|
|
289
|
+
const theta = useRef(0);
|
|
290
|
+
const distance = useRef(50);
|
|
291
|
+
const pointerDown = useRef(false);
|
|
292
|
+
const pointerDownX = useRef(0);
|
|
293
|
+
const pointerDownY = useRef(0);
|
|
294
|
+
const pointerLon = useRef(0);
|
|
295
|
+
const pointerLat = useRef(0);
|
|
325
296
|
|
|
326
297
|
// render 3D frame
|
|
327
298
|
|
|
328
|
-
|
|
299
|
+
const render3D = useCallback(() => {
|
|
329
300
|
if (THREE === null) {
|
|
330
301
|
return;
|
|
331
302
|
}
|
|
332
|
-
|
|
303
|
+
const {
|
|
304
|
+
MathUtils
|
|
305
|
+
} = THREE;
|
|
333
306
|
lat.current = Math.max(-85, Math.min(85, lat.current));
|
|
334
307
|
phi.current = MathUtils.degToRad(90 - lat.current);
|
|
335
308
|
theta.current = MathUtils.degToRad(lon.current);
|
|
@@ -342,45 +315,40 @@ function Video360Screen(_ref) {
|
|
|
342
315
|
|
|
343
316
|
// Init 3D layer
|
|
344
317
|
|
|
345
|
-
useEffect(
|
|
318
|
+
useEffect(() => {
|
|
346
319
|
if (THREE !== null && hasVideoUrl && withVideoSphere) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
_ref7$MeshBasicMateri = _ref7.MeshBasicMaterial,
|
|
357
|
-
MeshBasicMaterial = _ref7$MeshBasicMateri === void 0 ? null : _ref7$MeshBasicMateri,
|
|
358
|
-
_ref7$Mesh = _ref7.Mesh,
|
|
359
|
-
Mesh = _ref7$Mesh === void 0 ? null : _ref7$Mesh,
|
|
360
|
-
_ref7$WebGLRenderer = _ref7.WebGLRenderer,
|
|
361
|
-
WebGLRenderer = _ref7$WebGLRenderer === void 0 ? null : _ref7$WebGLRenderer;
|
|
320
|
+
const {
|
|
321
|
+
Scene = null,
|
|
322
|
+
PerspectiveCamera = null,
|
|
323
|
+
SphereBufferGeometry = null,
|
|
324
|
+
VideoTexture = null,
|
|
325
|
+
MeshBasicMaterial = null,
|
|
326
|
+
Mesh = null,
|
|
327
|
+
WebGLRenderer = null
|
|
328
|
+
} = THREE || {};
|
|
362
329
|
if (Scene === null || PerspectiveCamera === null || SphereBufferGeometry === null || VideoTexture === null || MeshBasicMaterial === null || Mesh === null || WebGLRenderer === null) {
|
|
363
|
-
return
|
|
330
|
+
return () => {
|
|
364
331
|
camera.current = null;
|
|
365
332
|
scene.current = null;
|
|
366
333
|
renderer.current = null;
|
|
367
334
|
};
|
|
368
335
|
}
|
|
369
|
-
|
|
370
|
-
canvasWidth
|
|
371
|
-
canvasHeight
|
|
336
|
+
const {
|
|
337
|
+
offsetWidth: canvasWidth,
|
|
338
|
+
offsetHeight: canvasHeight
|
|
339
|
+
} = canvasRef.current;
|
|
372
340
|
camera.current = new PerspectiveCamera(75, canvasWidth / canvasHeight, 1, 1100);
|
|
373
341
|
scene.current = new Scene();
|
|
374
|
-
|
|
342
|
+
const geometry = new SphereBufferGeometry(500, 60, 40);
|
|
375
343
|
geometry.scale(-1, 1, 1);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
344
|
+
const {
|
|
345
|
+
current: videoElement = null
|
|
346
|
+
} = mediaRef || {};
|
|
347
|
+
const videoTexture = new VideoTexture(videoElement);
|
|
348
|
+
const videoMaterial = new MeshBasicMaterial({
|
|
381
349
|
map: videoTexture
|
|
382
350
|
});
|
|
383
|
-
|
|
351
|
+
const mesh = new Mesh(geometry, videoMaterial);
|
|
384
352
|
scene.current.add(mesh);
|
|
385
353
|
renderer.current = new WebGLRenderer({
|
|
386
354
|
canvas: canvasRef.current
|
|
@@ -389,7 +357,7 @@ function Video360Screen(_ref) {
|
|
|
389
357
|
renderer.current.setSize(canvasWidth, canvasHeight);
|
|
390
358
|
render3D();
|
|
391
359
|
}
|
|
392
|
-
return
|
|
360
|
+
return () => {
|
|
393
361
|
if (withVideoSphere) {
|
|
394
362
|
camera.current = null;
|
|
395
363
|
scene.current = null;
|
|
@@ -403,7 +371,7 @@ function Video360Screen(_ref) {
|
|
|
403
371
|
|
|
404
372
|
// Resize 3D layer
|
|
405
373
|
|
|
406
|
-
useEffect(
|
|
374
|
+
useEffect(() => {
|
|
407
375
|
if (camera.current !== null && renderer.current !== null) {
|
|
408
376
|
camera.current.aspect = width / height;
|
|
409
377
|
camera.current.updateProjectionMatrix();
|
|
@@ -412,8 +380,8 @@ function Video360Screen(_ref) {
|
|
|
412
380
|
}, [width, height]);
|
|
413
381
|
|
|
414
382
|
// Pointer interaction
|
|
415
|
-
|
|
416
|
-
|
|
383
|
+
const togglePlayTimeout = useRef(null);
|
|
384
|
+
const onPointerDown = useCallback(e => {
|
|
417
385
|
pointerDown.current = true;
|
|
418
386
|
pointerDownX.current = e.clientX;
|
|
419
387
|
pointerDownY.current = e.clientY;
|
|
@@ -429,27 +397,25 @@ function Video360Screen(_ref) {
|
|
|
429
397
|
}, [
|
|
430
398
|
/* togglePlay */
|
|
431
399
|
]);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
400
|
+
const pixelsMoved = useRef(0);
|
|
401
|
+
const lastPointerClient = useRef(null);
|
|
402
|
+
const pixelsMovedTracked = useRef(false);
|
|
403
|
+
const onPointerMove = useCallback(e_0 => {
|
|
436
404
|
if (pointerDown.current) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
var downDeltaY = pointerDownY.current - clientY;
|
|
405
|
+
const {
|
|
406
|
+
clientX = null,
|
|
407
|
+
clientY = null
|
|
408
|
+
} = e_0 || {};
|
|
409
|
+
const downDeltaX = pointerDownX.current - clientX;
|
|
410
|
+
const downDeltaY = pointerDownY.current - clientY;
|
|
444
411
|
lon.current = downDeltaX * 0.2 + pointerLon.current;
|
|
445
412
|
lat.current = downDeltaY * 0.2 + pointerLat.current;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
var deltaY = Math.abs(lastY - clientY) || 0;
|
|
413
|
+
const {
|
|
414
|
+
x: lastX = clientX,
|
|
415
|
+
y: lastY = clientY
|
|
416
|
+
} = lastPointerClient.current || {};
|
|
417
|
+
const deltaX = Math.abs(lastX - clientX) || 0;
|
|
418
|
+
const deltaY = Math.abs(lastY - clientY) || 0;
|
|
453
419
|
pixelsMoved.current += deltaX + deltaY;
|
|
454
420
|
if (!pixelsMovedTracked.current && pixelsMoved.current > Math.min(width, height)) {
|
|
455
421
|
trackScreenEvent('drag_sphere', video.name);
|
|
@@ -467,21 +433,21 @@ function Video360Screen(_ref) {
|
|
|
467
433
|
}
|
|
468
434
|
}
|
|
469
435
|
}, [width, height, trackScreenEvent, video]);
|
|
470
|
-
|
|
471
|
-
|
|
436
|
+
const onPointerUp = useCallback(e_1 => {
|
|
437
|
+
const videoContainer = videoContainerRef.current;
|
|
472
438
|
if (pointerDown.current && videoContainer !== null) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
439
|
+
const distX = Math.abs(pointerDownX.current - e_1.clientX);
|
|
440
|
+
const distY = Math.abs(pointerDownY.current - e_1.clientY);
|
|
441
|
+
const pixelsMovedTolerance = 3;
|
|
442
|
+
const tapNextScreenWidthPercent = 0.5;
|
|
443
|
+
const canTapToNavigate = !landscape && togglePlayTimeout.current !== null;
|
|
444
|
+
const validNavigateTap = canTapToNavigate && distX < pixelsMovedTolerance && distY < pixelsMovedTolerance;
|
|
479
445
|
if (validNavigateTap) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
446
|
+
const {
|
|
447
|
+
left: containerX = 0,
|
|
448
|
+
width: containerWidth
|
|
449
|
+
} = videoContainer.getBoundingClientRect();
|
|
450
|
+
const hasTappedLeft = e_1.clientX - containerX < containerWidth * (1 - tapNextScreenWidthPercent);
|
|
485
451
|
if (hasTappedLeft) {
|
|
486
452
|
if (gotoPreviousScreen !== null) {
|
|
487
453
|
gotoPreviousScreen();
|
|
@@ -497,14 +463,16 @@ function Video360Screen(_ref) {
|
|
|
497
463
|
}
|
|
498
464
|
pointerDown.current = false;
|
|
499
465
|
}, [gotoPreviousScreen, gotoNextScreen, landscape]);
|
|
500
|
-
|
|
466
|
+
const onPlayError = useCallback(() => {
|
|
501
467
|
if (isView && playing && current && hasVideoUrl && autoPlay) {
|
|
502
468
|
setPlaying(false);
|
|
503
469
|
setControlsSuggestPlay(true);
|
|
504
470
|
}
|
|
505
471
|
}, [isView, current, playing, hasVideoUrl, autoPlay, setPlaying, setControlsSuggestPlay]);
|
|
506
472
|
return /*#__PURE__*/jsxs("div", {
|
|
507
|
-
className: classNames([styles.container, className,
|
|
473
|
+
className: classNames([styles.container, className, {
|
|
474
|
+
[styles.showVideo]: isPreview || isStatic || isCapture
|
|
475
|
+
}]),
|
|
508
476
|
"data-screen-ready": (isStatic || isCapture) && posterReady || ready,
|
|
509
477
|
children: [/*#__PURE__*/jsxs(Container, {
|
|
510
478
|
width: width,
|
|
@@ -519,7 +487,8 @@ function Video360Screen(_ref) {
|
|
|
519
487
|
left: resizedVideoLeft,
|
|
520
488
|
top: resizedVideoTop
|
|
521
489
|
},
|
|
522
|
-
children: /*#__PURE__*/jsx(Video,
|
|
490
|
+
children: /*#__PURE__*/jsx(Video, {
|
|
491
|
+
...finalVideo,
|
|
523
492
|
mediaRef: mergeRefs(mediaRef, customMediaRef),
|
|
524
493
|
className: styles.video,
|
|
525
494
|
paused: !videoPlaying,
|
|
@@ -540,7 +509,7 @@ function Video360Screen(_ref) {
|
|
|
540
509
|
shouldLoad: mediaShouldLoad,
|
|
541
510
|
qualityStartLevel: currentQualityLevel,
|
|
542
511
|
onQualityLevelChange: setCurrentQualityLevel
|
|
543
|
-
})
|
|
512
|
+
})
|
|
544
513
|
}) : null, /*#__PURE__*/jsxs("div", {
|
|
545
514
|
className: styles.inner,
|
|
546
515
|
children: [/*#__PURE__*/jsxs(ScreenElement, {
|
|
@@ -552,10 +521,7 @@ function Video360Screen(_ref) {
|
|
|
552
521
|
emptyClassName: styles.empty,
|
|
553
522
|
emptyLabel: /*#__PURE__*/jsx(FormattedMessage, {
|
|
554
523
|
id: "oLtEu6",
|
|
555
|
-
defaultMessage:
|
|
556
|
-
"type": 0,
|
|
557
|
-
"value": "Video 360"
|
|
558
|
-
}]
|
|
524
|
+
defaultMessage: "Video 360"
|
|
559
525
|
}),
|
|
560
526
|
isEmpty: !withVideoSphere,
|
|
561
527
|
children: [!isPlaceholder && hasHeader ? /*#__PURE__*/jsx("div", {
|
|
@@ -564,9 +530,11 @@ function Video360Screen(_ref) {
|
|
|
564
530
|
paddingTop: spacing / 2,
|
|
565
531
|
paddingLeft: spacing,
|
|
566
532
|
paddingRight: spacing,
|
|
567
|
-
transform: !isPreview ?
|
|
533
|
+
transform: !isPreview ? `translate(0, ${viewerTopHeight}px)` : null
|
|
568
534
|
},
|
|
569
|
-
children: /*#__PURE__*/jsx(Header,
|
|
535
|
+
children: /*#__PURE__*/jsx(Header, {
|
|
536
|
+
...header
|
|
537
|
+
})
|
|
570
538
|
}, "header") : null, withVideoSphere ? /*#__PURE__*/jsxs(Fragment, {
|
|
571
539
|
children: [/*#__PURE__*/jsx("canvas", {
|
|
572
540
|
ref: canvasRef,
|
|
@@ -605,20 +573,21 @@ function Video360Screen(_ref) {
|
|
|
605
573
|
}, "video"), !isPlaceholder ? /*#__PURE__*/jsxs("div", {
|
|
606
574
|
className: styles.bottom,
|
|
607
575
|
style: {
|
|
608
|
-
transform: current && !isPreview ?
|
|
576
|
+
transform: current && !isPreview ? `translate(0, -${viewerBottomHeight}px)` : null,
|
|
609
577
|
paddingLeft: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
610
578
|
paddingRight: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
611
579
|
paddingBottom: spacing / 2,
|
|
612
580
|
paddingTop: 0
|
|
613
581
|
},
|
|
614
|
-
children: [(closedCaptions !== null || captions !== null) && !isPreview && !isCapture && !isStatic ? /*#__PURE__*/jsx(ClosedCaptions,
|
|
582
|
+
children: [(closedCaptions !== null || captions !== null) && !isPreview && !isCapture && !isStatic ? /*#__PURE__*/jsx(ClosedCaptions, {
|
|
615
583
|
className: styles.closedCaptions,
|
|
616
|
-
media: closedCaptions
|
|
617
|
-
|
|
584
|
+
media: closedCaptions,
|
|
585
|
+
...captions,
|
|
618
586
|
currentTime: currentTime
|
|
619
|
-
})
|
|
587
|
+
}) : null, hasFooter ? /*#__PURE__*/jsx(Footer, {
|
|
588
|
+
...footerProps,
|
|
620
589
|
className: styles.callToAction
|
|
621
|
-
})
|
|
590
|
+
}) : null]
|
|
622
591
|
}, "bottom-content") : null]
|
|
623
592
|
})]
|
|
624
593
|
}), !isPlaceholder ? /*#__PURE__*/jsx(Background, {
|
|
@@ -643,19 +612,13 @@ var definition = {
|
|
|
643
612
|
group: {
|
|
644
613
|
label: defineMessage({
|
|
645
614
|
id: "+9akmg",
|
|
646
|
-
defaultMessage:
|
|
647
|
-
"type": 0,
|
|
648
|
-
"value": "Audio and Video"
|
|
649
|
-
}]
|
|
615
|
+
defaultMessage: "Audio and Video"
|
|
650
616
|
}),
|
|
651
617
|
order: 5
|
|
652
618
|
},
|
|
653
619
|
title: defineMessage({
|
|
654
620
|
id: "GRVidW",
|
|
655
|
-
defaultMessage:
|
|
656
|
-
"type": 0,
|
|
657
|
-
"value": "360 Video"
|
|
658
|
-
}]
|
|
621
|
+
defaultMessage: "360 Video"
|
|
659
622
|
}),
|
|
660
623
|
component: Video360Screen,
|
|
661
624
|
layouts: ['full'],
|
|
@@ -671,30 +634,21 @@ var definition = {
|
|
|
671
634
|
},
|
|
672
635
|
label: defineMessage({
|
|
673
636
|
id: "tvl2Zc",
|
|
674
|
-
defaultMessage:
|
|
675
|
-
"type": 0,
|
|
676
|
-
"value": "Video"
|
|
677
|
-
}]
|
|
637
|
+
defaultMessage: "Video"
|
|
678
638
|
})
|
|
679
639
|
}, {
|
|
680
640
|
name: 'background',
|
|
681
641
|
type: 'background',
|
|
682
642
|
label: defineMessage({
|
|
683
643
|
id: "+MPZRu",
|
|
684
|
-
defaultMessage:
|
|
685
|
-
"type": 0,
|
|
686
|
-
"value": "Background"
|
|
687
|
-
}]
|
|
644
|
+
defaultMessage: "Background"
|
|
688
645
|
})
|
|
689
646
|
}, {
|
|
690
647
|
name: 'header',
|
|
691
648
|
type: 'header',
|
|
692
649
|
label: defineMessage({
|
|
693
650
|
id: "rhuDxI",
|
|
694
|
-
defaultMessage:
|
|
695
|
-
"type": 0,
|
|
696
|
-
"value": "Header"
|
|
697
|
-
}]
|
|
651
|
+
defaultMessage: "Header"
|
|
698
652
|
}),
|
|
699
653
|
theme: {
|
|
700
654
|
badge: {
|
|
@@ -709,10 +663,7 @@ var definition = {
|
|
|
709
663
|
type: 'footer',
|
|
710
664
|
label: defineMessage({
|
|
711
665
|
id: "g4nybp",
|
|
712
|
-
defaultMessage:
|
|
713
|
-
"type": 0,
|
|
714
|
-
"value": "Footer"
|
|
715
|
-
}]
|
|
666
|
+
defaultMessage: "Footer"
|
|
716
667
|
}),
|
|
717
668
|
theme: {
|
|
718
669
|
callToAction: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/screen-video-360",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.74",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
38
|
"types": "./es/index.d.ts",
|
|
39
|
+
"style": "./assets/css/styles.css",
|
|
39
40
|
"import": "./es/index.js"
|
|
40
41
|
},
|
|
41
42
|
"./assets/css/styles": "./assets/css/styles.css",
|
|
@@ -52,25 +53,25 @@
|
|
|
52
53
|
"build": "../../scripts/prepare-package.sh --types"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"react": "^
|
|
56
|
-
"react-dom": "^
|
|
56
|
+
"react": "^19.0.0",
|
|
57
|
+
"react-dom": "^19.0.0"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
|
-
"react": "^
|
|
60
|
-
"react-dom": "^
|
|
60
|
+
"react": "^19.0.0",
|
|
61
|
+
"react-dom": "^19.0.0"
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
64
|
"@babel/runtime": "^7.28.6",
|
|
64
65
|
"@folklore/size": "^0.1.20",
|
|
65
|
-
"@micromag/core": "^0.4.
|
|
66
|
-
"@micromag/element-background": "^0.4.
|
|
67
|
-
"@micromag/element-closed-captions": "^0.4.
|
|
68
|
-
"@micromag/element-container": "^0.4.
|
|
69
|
-
"@micromag/element-footer": "^0.4.
|
|
70
|
-
"@micromag/element-header": "^0.4.
|
|
71
|
-
"@micromag/element-image": "^0.4.
|
|
72
|
-
"@micromag/element-video": "^0.4.
|
|
73
|
-
"@micromag/transforms": "^0.4.
|
|
66
|
+
"@micromag/core": "^0.4.74",
|
|
67
|
+
"@micromag/element-background": "^0.4.74",
|
|
68
|
+
"@micromag/element-closed-captions": "^0.4.74",
|
|
69
|
+
"@micromag/element-container": "^0.4.74",
|
|
70
|
+
"@micromag/element-footer": "^0.4.74",
|
|
71
|
+
"@micromag/element-header": "^0.4.74",
|
|
72
|
+
"@micromag/element-image": "^0.4.74",
|
|
73
|
+
"@micromag/element-video": "^0.4.74",
|
|
74
|
+
"@micromag/transforms": "^0.4.74",
|
|
74
75
|
"classnames": "^2.2.6",
|
|
75
76
|
"lodash": "^4.17.23",
|
|
76
77
|
"react-intl": "^8.1.3 || ^10.0.0",
|
|
@@ -81,6 +82,6 @@
|
|
|
81
82
|
"access": "public",
|
|
82
83
|
"registry": "https://registry.npmjs.org/"
|
|
83
84
|
},
|
|
84
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "fe510ee87845280d0760cb292aef9d2eb69e67c1",
|
|
85
86
|
"types": "es/index.d.ts"
|
|
86
87
|
}
|