l-min-components 1.0.1155 → 1.0.1159

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.0.1155",
3
+ "version": "1.0.1159",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -1,11 +1,4 @@
1
- import {
2
- useCallback,
3
- useContext,
4
- useEffect,
5
- useMemo,
6
- useRef,
7
- useState,
8
- } from "react";
1
+ import { useCallback, useContext, useEffect, useMemo, useState } from "react";
9
2
  import Hls from "hls.js";
10
3
  import { OutletContext } from "../AppMainLayout";
11
4
 
@@ -16,37 +9,37 @@ const useAudioPlayer = ({ src, streamSrc }) => {
16
9
  const [error, setError] = useState(null);
17
10
  const [progress, setProgress] = useState({});
18
11
 
19
- const audioRef = useRef(null);
12
+ const audio = useMemo(() => new Audio(), []);
20
13
 
21
14
  const { accessToken, generalData } = useContext(OutletContext);
22
15
 
23
16
  const accountId = generalData?.selectedAccount?.id;
24
17
 
25
18
  const play = useCallback(() => {
26
- if (audioRef.current && isReady) {
27
- audioRef.current.play();
19
+ if (audio && isReady) {
20
+ audio.play();
28
21
  }
29
- }, [isReady]);
22
+ }, [isReady, audio]);
30
23
 
31
24
  const pause = useCallback(() => {
32
- if (audioRef.current && isReady) {
33
- audioRef.current.pause();
25
+ if (audio && isReady) {
26
+ audio.pause();
34
27
  }
35
- }, [isReady]);
28
+ }, [isReady, audio]);
36
29
 
37
30
  const stop = useCallback(() => {
38
- if (audioRef.current && isReady) {
39
- audioRef.current.pause();
40
- audioRef.current.currentTime = 0;
31
+ if (audio && isReady) {
32
+ audio.pause();
33
+ audio.currentTime = 0;
41
34
  }
42
- }, [isReady]);
35
+ }, [isReady, audio]);
43
36
 
44
37
  const url = useMemo(() => src || streamSrc, [src, streamSrc]);
45
38
 
46
39
  useEffect(() => {
47
40
  let hls;
48
41
 
49
- if (audioRef.current && accountId) {
42
+ if (audio && accountId) {
50
43
  if (Hls?.isSupported() && streamSrc && !src) {
51
44
  hls = new Hls({
52
45
  xhrSetup: function (xhr, url) {
@@ -58,7 +51,7 @@ const useAudioPlayer = ({ src, streamSrc }) => {
58
51
  });
59
52
 
60
53
  hls.loadSource(url);
61
- hls?.attachMedia(audioRef.current);
54
+ hls?.attachMedia(audio);
62
55
 
63
56
  hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
64
57
  setIsReady(true);
@@ -76,18 +69,15 @@ const useAudioPlayer = ({ src, streamSrc }) => {
76
69
  setError(data);
77
70
  setIsReady(false);
78
71
  });
79
- } else if (
80
- !src &&
81
- audioRef.current.canPlayType("application/vnd.apple.mpegurl")
82
- ) {
83
- audioRef.current.src = url;
84
- audioRef.current.addEventListener("loadedmetadata", () => {
72
+ } else if (!src && audio.canPlayType("application/vnd.apple.mpegurl")) {
73
+ audio.src = url;
74
+ audio.addEventListener("loadedmetadata", () => {
85
75
  setIsReady(true);
86
76
  });
87
77
  } else {
88
- if (audioRef.current && src) {
89
- audioRef.current.src = src;
90
- audioRef.current.load();
78
+ if (audio && src) {
79
+ audio.src = src;
80
+ audio.load();
91
81
  setIsReady(true);
92
82
  }
93
83
  }
@@ -96,23 +86,21 @@ const useAudioPlayer = ({ src, streamSrc }) => {
96
86
  const handlePlay = () => setIsPlaying(true);
97
87
 
98
88
  const handleProgress = () => {
99
- if (audioRef.current) {
100
- const currentTime = audioRef.current.currentTime;
101
- const duration = audioRef.current.duration;
89
+ if (audio) {
90
+ const currentTime = audio.currentTime;
91
+ const duration = audio.duration;
102
92
 
103
93
  setProgress({ currentTime, duration });
104
94
  }
105
95
  };
106
96
 
107
- audioRef.current.addEventListener("ended", handleEnded);
108
- audioRef.current.addEventListener("pause", handlePause);
109
- audioRef.current.addEventListener("playing", handlePlay);
110
- audioRef.current?.addEventListener("timeupdate", handleProgress);
111
- audioRef.current?.addEventListener("loadedmetadata", handleProgress);
112
- audioRef.current?.addEventListener("waiting", () => setIsBuffering(true));
113
- audioRef.current?.addEventListener("canplay", () =>
114
- setIsBuffering(false)
115
- );
97
+ audio.addEventListener("ended", handleEnded);
98
+ audio.addEventListener("pause", handlePause);
99
+ audio.addEventListener("playing", handlePlay);
100
+ audio.addEventListener("timeupdate", handleProgress);
101
+ audio.addEventListener("loadedmetadata", handleProgress);
102
+ audio.addEventListener("waiting", () => setIsBuffering(true));
103
+ audio.addEventListener("canplay", () => setIsBuffering(false));
116
104
  }
117
105
  return () => {
118
106
  if (hls) {
@@ -121,11 +109,11 @@ const useAudioPlayer = ({ src, streamSrc }) => {
121
109
 
122
110
  setIsReady(false);
123
111
  };
124
- }, [url, accessToken, accountId, audioRef.current]);
112
+ }, [url, accessToken, accountId, audio]);
125
113
 
126
114
  return {
127
115
  stop,
128
- audioRef,
116
+ audio,
129
117
  play,
130
118
  pause,
131
119
  isPlaying,
@@ -114,7 +114,7 @@ const VideoPlayer = ({
114
114
 
115
115
  useEffect(() => {
116
116
  let hls;
117
-
117
+ setError(false);
118
118
  if (videoRef.current && accountId) {
119
119
  if (!src && streamUrl && Hls.isSupported()) {
120
120
  hls = new Hls({