@rxdrag/website-lib-core 0.0.109 → 0.0.110
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.110",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"eslint": "^7.32.0",
|
|
26
26
|
"typescript": "^5",
|
|
27
27
|
"@rxdrag/eslint-config-custom": "0.2.12",
|
|
28
|
-
"@rxdrag/
|
|
29
|
-
"@rxdrag/
|
|
28
|
+
"@rxdrag/slate-preview": "1.2.63",
|
|
29
|
+
"@rxdrag/tsconfig": "0.2.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@iconify/utils": "^3.0.2",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"gsap": "^3.12.7",
|
|
35
35
|
"hls.js": "^1.6.13",
|
|
36
36
|
"lodash-es": "^4.17.21",
|
|
37
|
-
"@rxdrag/
|
|
38
|
-
"@rxdrag/
|
|
37
|
+
"@rxdrag/entify-lib": "0.0.23",
|
|
38
|
+
"@rxdrag/rxcms-models": "0.3.96"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"astro": "^4.0.0 || ^5.0.0",
|
|
@@ -54,17 +54,21 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
54
54
|
const [isPlaying, setIsPlaying] = useState(false);
|
|
55
55
|
const [isEnded, setIsEnded] = useState(false);
|
|
56
56
|
const [isSourceReady, setIsSourceReady] = useState(false);
|
|
57
|
+
const sourceReadyRef = useRef(false);
|
|
58
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
59
|
+
const isEndedRef = useRef(false);
|
|
57
60
|
|
|
58
61
|
const ensureSourceReady = useCallback(() => {
|
|
59
62
|
const video = videoRef.current;
|
|
60
63
|
const url = media.file?.original;
|
|
61
64
|
if (!video || !url) return false;
|
|
62
|
-
if (
|
|
65
|
+
if (sourceReadyRef.current) return true;
|
|
63
66
|
|
|
64
67
|
if (media.storageType === "cloudflare_stream") {
|
|
65
68
|
if (!Hls.isSupported()) {
|
|
66
69
|
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
|
67
70
|
video.src = url;
|
|
71
|
+
sourceReadyRef.current = true;
|
|
68
72
|
setIsSourceReady(true);
|
|
69
73
|
return true;
|
|
70
74
|
}
|
|
@@ -90,14 +94,16 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
90
94
|
hls.loadSource(url);
|
|
91
95
|
hls.attachMedia(video);
|
|
92
96
|
hlsRef.current = hls;
|
|
97
|
+
sourceReadyRef.current = true;
|
|
93
98
|
setIsSourceReady(true);
|
|
94
99
|
return true;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
video.src = url;
|
|
103
|
+
sourceReadyRef.current = true;
|
|
98
104
|
setIsSourceReady(true);
|
|
99
105
|
return true;
|
|
100
|
-
}, [
|
|
106
|
+
}, [media.file?.original, media.storageType]);
|
|
101
107
|
|
|
102
108
|
const handleContainerClick = useCallback(
|
|
103
109
|
(e: React.MouseEvent) => {
|
|
@@ -128,7 +134,12 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
128
134
|
const ok = ensureSourceReady();
|
|
129
135
|
if (!ok) return;
|
|
130
136
|
|
|
131
|
-
|
|
137
|
+
setIsLoading(true);
|
|
138
|
+
|
|
139
|
+
v.play().catch((error) => {
|
|
140
|
+
console.log("ReactVideoPlayer play() failed:", error);
|
|
141
|
+
setIsLoading(false);
|
|
142
|
+
});
|
|
132
143
|
},
|
|
133
144
|
[isPlaying, designMode, ensureSourceReady]
|
|
134
145
|
);
|
|
@@ -137,6 +148,7 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
137
148
|
const video = videoRef.current;
|
|
138
149
|
if (!video) return;
|
|
139
150
|
|
|
151
|
+
video.pause();
|
|
140
152
|
if (hlsRef.current) {
|
|
141
153
|
hlsRef.current.destroy();
|
|
142
154
|
hlsRef.current = null;
|
|
@@ -144,20 +156,34 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
144
156
|
video.removeAttribute("src");
|
|
145
157
|
video.load();
|
|
146
158
|
setIsSourceReady(false);
|
|
159
|
+
sourceReadyRef.current = false;
|
|
147
160
|
|
|
148
161
|
const onPlay = () => {
|
|
149
162
|
setIsPlaying(true);
|
|
150
163
|
setIsEnded(false);
|
|
164
|
+
isEndedRef.current = false;
|
|
165
|
+
setIsLoading(false);
|
|
151
166
|
};
|
|
152
167
|
const onPause = () => setIsPlaying(false);
|
|
153
168
|
const onEnded = () => {
|
|
154
169
|
setIsPlaying(false);
|
|
155
170
|
setIsEnded(true);
|
|
171
|
+
isEndedRef.current = true;
|
|
172
|
+
setIsLoading(false);
|
|
173
|
+
};
|
|
174
|
+
const onWaiting = () => {
|
|
175
|
+
if (!isEndedRef.current) setIsLoading(true);
|
|
176
|
+
};
|
|
177
|
+
const onCanPlay = () => {
|
|
178
|
+
setIsLoading(false);
|
|
156
179
|
};
|
|
157
180
|
|
|
158
181
|
video.addEventListener("play", onPlay);
|
|
159
182
|
video.addEventListener("pause", onPause);
|
|
160
183
|
video.addEventListener("ended", onEnded);
|
|
184
|
+
video.addEventListener("waiting", onWaiting);
|
|
185
|
+
video.addEventListener("canplay", onCanPlay);
|
|
186
|
+
video.addEventListener("playing", onCanPlay);
|
|
161
187
|
|
|
162
188
|
if (eagerLoad) {
|
|
163
189
|
ensureSourceReady();
|
|
@@ -167,6 +193,9 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
167
193
|
video.removeEventListener("play", onPlay);
|
|
168
194
|
video.removeEventListener("pause", onPause);
|
|
169
195
|
video.removeEventListener("ended", onEnded);
|
|
196
|
+
video.removeEventListener("waiting", onWaiting);
|
|
197
|
+
video.removeEventListener("canplay", onCanPlay);
|
|
198
|
+
video.removeEventListener("playing", onCanPlay);
|
|
170
199
|
|
|
171
200
|
if (hlsRef.current) {
|
|
172
201
|
hlsRef.current.destroy();
|
|
@@ -202,7 +231,7 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
202
231
|
Your browser does not support video playback.
|
|
203
232
|
</video>
|
|
204
233
|
|
|
205
|
-
{!isPlaying && !isEnded && (
|
|
234
|
+
{!isPlaying && !isEnded && !isLoading && (
|
|
206
235
|
<button
|
|
207
236
|
type="button"
|
|
208
237
|
onClick={handlePlayClick}
|
|
@@ -243,6 +272,21 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
243
272
|
</button>
|
|
244
273
|
)}
|
|
245
274
|
|
|
275
|
+
{!isPlaying && !isEnded && isLoading && (
|
|
276
|
+
<div
|
|
277
|
+
className={clsx(
|
|
278
|
+
"absolute inset-0 flex items-center justify-center w-full h-full rounded-lg z-10 bg-black/20",
|
|
279
|
+
classNames?.playButton
|
|
280
|
+
)}
|
|
281
|
+
onClick={(e) => e.stopPropagation()}
|
|
282
|
+
>
|
|
283
|
+
<div className="flex items-center gap-3 rounded-full bg-black/50 px-4 py-2 text-white">
|
|
284
|
+
<div className="h-4 w-4 animate-spin rounded-full border-2 border-white/30 border-t-white" />
|
|
285
|
+
<span className="text-sm">Loading...</span>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
)}
|
|
289
|
+
|
|
246
290
|
<div
|
|
247
291
|
className={clsx(
|
|
248
292
|
"absolute inset-0 bg-black/50 flex-col gap-6 items-center justify-center text-center text-white hidden z-10 rounded-2xl",
|
|
@@ -277,9 +321,13 @@ export const ReactVideoPlayer = forwardRef<
|
|
|
277
321
|
if (!v) return;
|
|
278
322
|
const ok = ensureSourceReady();
|
|
279
323
|
if (!ok) return;
|
|
324
|
+
setIsLoading(true);
|
|
280
325
|
v.currentTime = 0;
|
|
281
326
|
setIsEnded(false);
|
|
282
|
-
v.play()
|
|
327
|
+
v.play().catch((error) => {
|
|
328
|
+
console.log("ReactVideoPlayer play() failed:", error);
|
|
329
|
+
setIsLoading(false);
|
|
330
|
+
});
|
|
283
331
|
}}
|
|
284
332
|
>
|
|
285
333
|
Replay
|