l-min-components 1.7.1362 → 1.7.1364

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": "l-min-components",
3
- "version": "1.7.1362",
3
+ "version": "1.7.1364",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -321,7 +321,7 @@ const AppMainLayout = ({ children }) => {
321
321
 
322
322
  const handleGetStorageSummary = async () => {
323
323
  const accountType = generalData?.selectedAccount?.type?.toLowerCase();
324
- if (accountType) {
324
+ if (accountType === "enterprise" || accountType === "instructor") {
325
325
  const res = await handleGetFileStorageSummary(accountType);
326
326
  res?.data && setStorageSummary({ ...res?.data, results: undefined });
327
327
  }
@@ -0,0 +1,142 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import Hls from "hls.js";
3
+
4
+ import { OutletContext } from "../AppMainLayout";
5
+
6
+ const useVideoPlayer = ({ src, streamSrc }) => {
7
+ const videoRef = useRef(null);
8
+ const [isReady, setIsReady] = useState(false);
9
+ const [isBuffering, setIsBuffering] = useState(false);
10
+ const [isPlaying, setIsPlaying] = useState(false);
11
+ const [error, setError] = useState(null);
12
+ const [progress, setProgress] = useState({ currentTime: 0, duration: 0 });
13
+ const { accessToken, generalData } = useContext(OutletContext);
14
+
15
+ const accountId = generalData?.selectedAccount?.id;
16
+
17
+ const url = src || streamSrc;
18
+
19
+ const play = () => {
20
+ if (videoRef.current && isReady) {
21
+ videoRef.current.play();
22
+ }
23
+ };
24
+
25
+ const pause = () => {
26
+ if (videoRef.current && isReady) {
27
+ videoRef.current.pause();
28
+ }
29
+ };
30
+
31
+ const stop = () => {
32
+ if (videoRef.current && isReady) {
33
+ videoRef.current.pause();
34
+ videoRef.current.currentTime = 0;
35
+ }
36
+ };
37
+
38
+ useEffect(() => {
39
+ const video = videoRef.current;
40
+ let hls;
41
+
42
+ const handlePlay = () => setIsPlaying(true);
43
+ const handlePause = () => setIsPlaying(false);
44
+ const handleEnded = () => setIsPlaying(false);
45
+ const handleTimeUpdate = () => {
46
+ setProgress({
47
+ currentTime: video.currentTime,
48
+ duration: video.duration,
49
+ });
50
+ };
51
+
52
+ const handleWaiting = () => setIsBuffering(true);
53
+ const handleCanPlay = () => {
54
+ setIsBuffering(false);
55
+ setIsReady(true);
56
+ };
57
+
58
+ const attachEvents = () => {
59
+ video.addEventListener("play", handlePlay);
60
+ video.addEventListener("pause", handlePause);
61
+ video.addEventListener("ended", handleEnded);
62
+ video.addEventListener("timeupdate", handleTimeUpdate);
63
+ video.addEventListener("waiting", handleWaiting);
64
+ video.addEventListener("canplay", handleCanPlay);
65
+ };
66
+
67
+ const detachEvents = () => {
68
+ video.removeEventListener("play", handlePlay);
69
+ video.removeEventListener("pause", handlePause);
70
+ video.removeEventListener("ended", handleEnded);
71
+ video.removeEventListener("timeupdate", handleTimeUpdate);
72
+ video.removeEventListener("waiting", handleWaiting);
73
+ video.removeEventListener("canplay", handleCanPlay);
74
+ };
75
+
76
+ if (!src && Hls.isSupported()) {
77
+ hls = new Hls({
78
+ xhrSetup: function (xhr, url) {
79
+ const modifiedURL = `${url}?_account=${accountId}`;
80
+ xhr.open("GET", modifiedURL, true);
81
+ xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
82
+ },
83
+ lowLatencyMode: true,
84
+ });
85
+
86
+ hls.attachMedia(video);
87
+ hls.loadSource(url);
88
+
89
+ hls.on(Hls.Events.MANIFEST_PARSED, () => {
90
+ setIsReady(true);
91
+ setError(null);
92
+ });
93
+
94
+ hls.on(Hls.Events.BUFFER_STALLED, () => setIsBuffering(true));
95
+ hls.on(Hls.Events.BUFFER_APPENDED, () => setIsBuffering(false));
96
+
97
+ hls.on(Hls.Events.ERROR, (event, data) => {
98
+ console.warn("HLS error", data);
99
+ setError(data);
100
+ if (data.fatal) {
101
+ if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
102
+ hls.startLoad();
103
+ } else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
104
+ hls.recoverMediaError();
105
+ } else {
106
+ hls.destroy();
107
+ }
108
+ }
109
+ });
110
+ } else if (video.canPlayType("application/vnd.apple.mpegurl") && !src) {
111
+ video.src = url;
112
+ video.addEventListener("loadedmetadata", () => {
113
+ setIsReady(true);
114
+ });
115
+ } else {
116
+ video.src = src;
117
+ video.load();
118
+ setIsReady(true);
119
+ }
120
+
121
+ attachEvents();
122
+
123
+ return () => {
124
+ if (hls) hls.destroy();
125
+ detachEvents();
126
+ };
127
+ }, [src, streamSrc, accountId, accessToken]);
128
+
129
+ return {
130
+ videoRef,
131
+ isReady,
132
+ isPlaying,
133
+ isBuffering,
134
+ progress,
135
+ error,
136
+ play,
137
+ pause,
138
+ stop,
139
+ };
140
+ };
141
+
142
+ export default useVideoPlayer;
@@ -22,7 +22,7 @@ import PlayIcon from "./icons/playVideoIcon";
22
22
  import PauseIcon from "./icons/pause";
23
23
  import errorImage from "./icons/laptop-book.png";
24
24
 
25
- const VideoPlayer = ({
25
+ const VideoPlayer2 = ({
26
26
  width,
27
27
  height = "360px",
28
28
  style,
@@ -60,18 +60,23 @@ const VideoPlayer = ({
60
60
  .join(":");
61
61
  }, []);
62
62
 
63
- const handlePlayPause = useCallback(() => {
64
- setIsPlaying((prev) => !prev);
65
- if (videoRef.current) {
66
- isPlaying ? videoRef.current.pause() : videoRef.current.play();
63
+ const play = useCallback(() => {
64
+ if (videoRef?.current && isReady) {
65
+ videoRef.current.play();
67
66
  }
68
- }, [isPlaying]);
67
+ }, [isReady, videoRef?.current]);
68
+
69
+ const pause = useCallback(() => {
70
+ if (videoRef?.current && isReady) {
71
+ videoRef.current.pause();
72
+ }
73
+ }, [isReady, videoRef?.current]);
69
74
 
70
75
  const handleFullScreen = useCallback(() => {
71
76
  if (screenfull.isEnabled) {
72
77
  screenfull.toggle(playContainerRef.current);
73
78
  }
74
- }, []);
79
+ }, [playContainerRef?.current]);
75
80
 
76
81
  const handleProgress = useCallback(() => {
77
82
  if (count > 3) {
@@ -98,7 +103,7 @@ const VideoPlayer = ({
98
103
 
99
104
  const handleSeekMouseUp = () => {
100
105
  setIsSeeking(false);
101
- if (videoRef.current) {
106
+ if (videoRef?.current) {
102
107
  videoRef.current.currentTime = rangeProgress * videoRef.current.duration;
103
108
  }
104
109
  };
@@ -113,64 +118,127 @@ const VideoPlayer = ({
113
118
  };
114
119
 
115
120
  useEffect(() => {
121
+ const video = videoRef?.current;
122
+ if (!video) return null;
116
123
  let hls;
117
- setError(false);
118
- if (videoRef.current && accountId) {
119
- if (!src && streamUrl && Hls.isSupported()) {
120
- hls = new Hls({
121
- xhrSetup: function (xhr, url) {
122
- const modifiedURL = `${url}?_account=${accountId}`;
123
- xhr.open("GET", modifiedURL, true);
124
- xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
125
- },
126
124
 
127
- lowLatencyMode: true,
128
- });
125
+ const handlePlay = () => setIsPlaying(true);
126
+ const handlePause = () => setIsPlaying(false);
127
+ const handleEnded = () => setIsPlaying(false);
128
+ const handleTimeUpdate = () => {
129
+ const currentTime = video.currentTime;
130
+ const duration = video.duration;
131
+
132
+ const played = currentTime / duration;
133
+ setProgress({
134
+ currentTime,
135
+ duration,
136
+ played,
137
+ });
138
+ };
139
+
140
+ const handleWaiting = () => setIsBuffering(true);
141
+ const handleCanPlay = () => {
142
+ setIsBuffering(false);
143
+ setIsReady(true);
144
+ };
145
+
146
+ const attachEvents = () => {
147
+ video.addEventListener("play", handlePlay);
148
+ video.addEventListener("pause", handlePause);
149
+ video.addEventListener("ended", handleEnded);
150
+ video.addEventListener("timeupdate", handleTimeUpdate);
151
+ video.addEventListener("waiting", handleWaiting);
152
+ if (streamUrl && !src) {
153
+ video.addEventListener("canplay", handleCanPlay);
154
+ }
155
+ };
156
+
157
+ const detachEvents = () => {
158
+ video.removeEventListener("play", handlePlay);
159
+ video.removeEventListener("pause", handlePause);
160
+ video.removeEventListener("ended", handleEnded);
161
+ video.removeEventListener("timeupdate", handleTimeUpdate);
162
+ video.removeEventListener("waiting", handleWaiting);
163
+ video.removeEventListener("canplay", handleCanPlay);
164
+ };
165
+
166
+ if (!src && Hls.isSupported()) {
167
+ hls = new Hls({
168
+ xhrSetup: function (xhr, url) {
169
+ const modifiedURL = `${url}?_account=${accountId}`;
170
+ xhr.open("GET", modifiedURL, true);
171
+ xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
172
+ },
173
+ lowLatencyMode: true,
174
+ });
175
+
176
+ hls.attachMedia(video);
177
+ hls.on(Hls.Events.MEDIA_ATTACHED, () => {
129
178
  hls.loadSource(url);
130
- hls.attachMedia(videoRef.current);
179
+ });
131
180
 
132
- hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
181
+ hls.on(Hls.Events.LEVEL_SWITCHED, (val) => {
182
+ if (val === "hlsLevelSwitched") {
133
183
  setIsReady(true);
134
184
  setError(null);
135
- });
185
+ }
186
+ });
187
+ hls.on(Hls.Events.LEVEL_LOADING, (val) => {
188
+ if (val === "hlsLevelLoading") {
189
+ setIsReady(false);
190
+ }
191
+ });
136
192
 
137
- hls.on(Hls?.Events?.BUFFER_STALLED, () => {
193
+ hls.on(Hls.Events.BUFFER_STALLED, () => setIsBuffering(true));
194
+ hls.on(Hls.Events.BUFFER_APPENDED, () => setIsBuffering(false));
195
+ hls.on(Hls.Events.BUFFER_CREATED, (val) => {
196
+ if (val === "hlsBufferCreated") {
138
197
  setIsBuffering(true);
139
- });
198
+ }
199
+ });
140
200
 
141
- hls.on(Hls?.Events?.BUFFER_APPENDED, () => {
201
+ hls.on(Hls.Events.BUFFER_APPENDED, (val) => {
202
+ if (val === "hlsBufferAppended") {
142
203
  setIsBuffering(false);
143
- });
144
-
145
- hls.on(Hls.Events.ERROR, (event, data) => {
146
- console.log(data, "errorr....", event);
147
- // setError(true);
148
- });
149
- } else if (
150
- videoRef.current.canPlayType("application/vnd.apple.mpegurl") &&
151
- !src
152
- ) {
153
- videoRef.current.src = url;
154
- videoRef.current.addEventListener("loadedmetadata", () => {
155
- setIsReady(true);
156
- });
157
- } else {
158
- if (videoRef.current && src) {
159
- videoRef.current.src = src;
204
+ }
205
+ });
160
206
 
161
- videoRef.current.load();
162
- setIsReady(true);
207
+ hls.on(Hls.Events.ERROR, (event, data) => {
208
+ console.warn("HLS error", data);
209
+ if (data.fatal) {
210
+ setError(data);
211
+ setIsReady(false);
212
+ if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
213
+ hls.startLoad();
214
+ } else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
215
+ hls.recoverMediaError();
216
+ } else {
217
+ hls.destroy();
218
+ }
163
219
  }
164
- }
220
+ });
221
+ } else if (video.canPlayType("application/vnd.apple.mpegurl") && !src) {
222
+ video.src = url;
223
+ video.addEventListener("loadedmetadata", () => {
224
+ setIsReady(true);
225
+ });
226
+ } else {
227
+ video.src = src;
228
+ video.addEventListener("loadedmetadata", () => {
229
+ setIsReady(true);
230
+ });
231
+ video.load();
165
232
  }
166
233
 
234
+ attachEvents();
167
235
  return () => {
168
- if (hls) {
236
+ if (hls && typeof hls.destroy === "function") {
169
237
  hls.destroy();
170
238
  }
171
- setIsReady(false);
239
+ detachEvents();
172
240
  };
173
- }, [url, accountId, accessToken, videoRef?.current]);
241
+ }, [url, accountId, accessToken, videoRef.current]);
174
242
 
175
243
  return (
176
244
  <VideoPlayerContainer
@@ -193,7 +261,7 @@ const VideoPlayer = ({
193
261
  </ErrorMessage>
194
262
  ) : (
195
263
  <>
196
- {!isReady && (
264
+ {(!isReady || isBuffering) && (
197
265
  <LoadingScreen>
198
266
  <FullPageLoader
199
267
  isSectionLoader
@@ -202,8 +270,6 @@ const VideoPlayer = ({
202
270
  loaderHeight={small ? 150 : 200}
203
271
  zIndex={5}
204
272
  />
205
-
206
- {error && <p className={`error ${small ? "sm" : ""}`}>{error}</p>}
207
273
  </LoadingScreen>
208
274
  )}
209
275
 
@@ -242,15 +308,16 @@ const VideoPlayer = ({
242
308
  <VideoScreenIcon onClick={handleFullScreen} />
243
309
  </RangeContainer>
244
310
  )}
245
- {isReady && (
246
- <div className="play_pause_wrap" onClick={handlePlayPause}>
247
- {isPlaying ? (
311
+ {isReady &&
312
+ (isPlaying ? (
313
+ <div className="play_pause_wrap" onClick={pause}>
248
314
  <PauseIcon fill="#fff" />
249
- ) : (
315
+ </div>
316
+ ) : (
317
+ <div className="play_pause_wrap" onClick={play}>
250
318
  <PlayIcon fill="#fff" />
251
- )}
252
- </div>
253
- )}
319
+ </div>
320
+ ))}
254
321
  </VideoController>
255
322
  </>
256
323
  )}
@@ -258,4 +325,4 @@ const VideoPlayer = ({
258
325
  );
259
326
  };
260
327
 
261
- export default VideoPlayer;
328
+ export default VideoPlayer2;