l-min-components 1.7.1474 → 1.7.1475
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
|
@@ -44,6 +44,7 @@ const VideoPlayer2 = ({
|
|
|
44
44
|
|
|
45
45
|
const playContainerRef = useRef();
|
|
46
46
|
const videoRef = useRef();
|
|
47
|
+
const hlsRef = useRef(null);
|
|
47
48
|
const { accessToken, generalData } = useContext(OutletContext);
|
|
48
49
|
|
|
49
50
|
const accountId = generalData?.selectedAccount?.id;
|
|
@@ -154,8 +155,17 @@ const VideoPlayer2 = ({
|
|
|
154
155
|
}
|
|
155
156
|
};
|
|
156
157
|
|
|
158
|
+
const detachEvents = () => {
|
|
159
|
+
video?.removeEventListener("play", handlePlay);
|
|
160
|
+
video?.removeEventListener("pause", handlePause);
|
|
161
|
+
video?.removeEventListener("ended", handleEnded);
|
|
162
|
+
video?.removeEventListener("timeupdate", handleTimeUpdate);
|
|
163
|
+
video?.removeEventListener("waiting", handleWaiting);
|
|
164
|
+
video?.removeEventListener("canplay", handleCanPlay);
|
|
165
|
+
};
|
|
166
|
+
|
|
157
167
|
if (!src && Hls.isSupported()) {
|
|
158
|
-
|
|
168
|
+
hlsRef.current = new Hls({
|
|
159
169
|
xhrSetup: function (xhr, url) {
|
|
160
170
|
const modifiedURL = `${url}?_account=${accountId}`;
|
|
161
171
|
xhr.open("GET", modifiedURL, true);
|
|
@@ -164,48 +174,54 @@ const VideoPlayer2 = ({
|
|
|
164
174
|
lowLatencyMode: true,
|
|
165
175
|
});
|
|
166
176
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
hlsRef.current?.attachMedia(video);
|
|
178
|
+
hlsRef.current?.on(Hls.Events.MEDIA_ATTACHED, () => {
|
|
179
|
+
hlsRef.current?.loadSource(url);
|
|
170
180
|
});
|
|
171
181
|
|
|
172
|
-
|
|
182
|
+
hlsRef.current?.on(Hls.Events.LEVEL_SWITCHED, (val) => {
|
|
173
183
|
if (val === "hlsLevelSwitched") {
|
|
174
184
|
setIsReady(true);
|
|
175
185
|
setError(null);
|
|
176
186
|
}
|
|
177
187
|
});
|
|
178
|
-
|
|
188
|
+
hlsRef.current?.on(Hls.Events.LEVEL_LOADING, (val) => {
|
|
179
189
|
if (val === "hlsLevelLoading") {
|
|
180
190
|
setIsReady(false);
|
|
181
191
|
}
|
|
182
192
|
});
|
|
183
193
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
194
|
+
hlsRef.current?.on(Hls.Events.BUFFER_STALLED, () => setIsBuffering(true));
|
|
195
|
+
hlsRef.current?.on(Hls.Events.BUFFER_APPENDED, () =>
|
|
196
|
+
setIsBuffering(false)
|
|
197
|
+
);
|
|
198
|
+
hlsRef.current?.on(Hls.Events.BUFFER_CREATED, (val) => {
|
|
187
199
|
if (val === "hlsBufferCreated") {
|
|
188
200
|
setIsBuffering(true);
|
|
189
201
|
}
|
|
190
202
|
});
|
|
191
203
|
|
|
192
|
-
|
|
204
|
+
hlsRef.current?.on(Hls.Events.BUFFER_APPENDED, (val) => {
|
|
193
205
|
if (val === "hlsBufferAppended") {
|
|
194
206
|
setIsBuffering(false);
|
|
195
207
|
}
|
|
196
208
|
});
|
|
197
|
-
|
|
198
|
-
hls?.on(Hls.Events.ERROR, (event, data) => {
|
|
209
|
+
hlsRef.current?.on(Hls.Events.ERROR, (event, data) => {
|
|
199
210
|
console.warn("HLS error", data);
|
|
200
211
|
if (data.fatal) {
|
|
201
212
|
setError(data);
|
|
202
213
|
setIsReady(false);
|
|
203
214
|
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
|
|
204
|
-
|
|
215
|
+
hlsRef.current?.startLoad();
|
|
205
216
|
} else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) {
|
|
206
|
-
|
|
217
|
+
hlsRef.current?.recoverMediaError();
|
|
207
218
|
} else {
|
|
208
|
-
|
|
219
|
+
if (
|
|
220
|
+
hlsRef.current &&
|
|
221
|
+
typeof hlsRef.current.destroy === "function"
|
|
222
|
+
) {
|
|
223
|
+
hlsRef.current?.destroy();
|
|
224
|
+
}
|
|
209
225
|
}
|
|
210
226
|
}
|
|
211
227
|
});
|
|
@@ -221,12 +237,13 @@ const VideoPlayer2 = ({
|
|
|
221
237
|
});
|
|
222
238
|
video.load();
|
|
223
239
|
}
|
|
224
|
-
|
|
225
240
|
attachEvents();
|
|
226
241
|
return () => {
|
|
227
|
-
if (
|
|
228
|
-
|
|
242
|
+
if (hlsRef.current && typeof hlsRef.current.destroy === "function") {
|
|
243
|
+
hlsRef.current.destroy();
|
|
229
244
|
}
|
|
245
|
+
|
|
246
|
+
detachEvents();
|
|
230
247
|
};
|
|
231
248
|
}, [url, accountId, accessToken, videoRef.current]);
|
|
232
249
|
|