deepsea-components 5.17.32 → 5.17.34
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.
|
@@ -40,25 +40,29 @@ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
|
40
40
|
const external_react_namespaceObject = require("react");
|
|
41
41
|
const external_hls_js_namespaceObject = require("hls.js");
|
|
42
42
|
var external_hls_js_default = /*#__PURE__*/ __webpack_require__.n(external_hls_js_namespaceObject);
|
|
43
|
-
const HlsPlayer =
|
|
44
|
-
const { src, ...rest } = props;
|
|
43
|
+
const HlsPlayer = ({ ref, src, ...rest })=>{
|
|
45
44
|
const video = (0, external_react_namespaceObject.useRef)(null);
|
|
46
45
|
(0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>video.current, []);
|
|
47
46
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
48
47
|
const { current: player } = video;
|
|
49
48
|
if (!player || !src) return;
|
|
50
|
-
|
|
51
|
-
player.src = src;
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
49
|
+
let hls = null;
|
|
54
50
|
if (external_hls_js_default().isSupported()) {
|
|
55
|
-
|
|
51
|
+
hls = new (external_hls_js_default())();
|
|
56
52
|
hls.loadSource(src);
|
|
57
53
|
hls.attachMedia(player);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
hls.on(external_hls_js_default().Events.ERROR, (event, data)=>{
|
|
55
|
+
console.log(event);
|
|
56
|
+
console.log(data);
|
|
57
|
+
});
|
|
58
|
+
} else if (player.canPlayType("application/vnd.apple.mpegurl")) player.src = src;
|
|
59
|
+
return ()=>{
|
|
60
|
+
if (hls) hls.destroy();
|
|
61
|
+
if (player) {
|
|
62
|
+
player.src = "";
|
|
63
|
+
player.load();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
62
66
|
}, [
|
|
63
67
|
src
|
|
64
68
|
]);
|
|
@@ -66,7 +70,7 @@ const HlsPlayer = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)((
|
|
|
66
70
|
ref: video,
|
|
67
71
|
...rest
|
|
68
72
|
});
|
|
69
|
-
}
|
|
73
|
+
};
|
|
70
74
|
exports.HlsPlayer = __webpack_exports__.HlsPlayer;
|
|
71
75
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
72
76
|
"HlsPlayer"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface HlsPlayerProps extends Omit<
|
|
1
|
+
import { ComponentProps, FC } from "react";
|
|
2
|
+
export interface HlsPlayerProps extends Omit<ComponentProps<"video">, "src" | "children"> {
|
|
3
3
|
src: string;
|
|
4
4
|
}
|
|
5
|
-
export declare const HlsPlayer:
|
|
5
|
+
export declare const HlsPlayer: FC<HlsPlayerProps>;
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useImperativeHandle, useRef } from "react";
|
|
4
4
|
import hls_0 from "hls.js";
|
|
5
|
-
const HlsPlayer =
|
|
6
|
-
const { src, ...rest } = props;
|
|
5
|
+
const HlsPlayer = ({ ref, src, ...rest })=>{
|
|
7
6
|
const video = useRef(null);
|
|
8
7
|
useImperativeHandle(ref, ()=>video.current, []);
|
|
9
8
|
useEffect(()=>{
|
|
10
9
|
const { current: player } = video;
|
|
11
10
|
if (!player || !src) return;
|
|
12
|
-
|
|
13
|
-
player.src = src;
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
11
|
+
let hls = null;
|
|
16
12
|
if (hls_0.isSupported()) {
|
|
17
|
-
|
|
13
|
+
hls = new hls_0();
|
|
18
14
|
hls.loadSource(src);
|
|
19
15
|
hls.attachMedia(player);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
hls.on(hls_0.Events.ERROR, (event, data)=>{
|
|
17
|
+
console.log(event);
|
|
18
|
+
console.log(data);
|
|
19
|
+
});
|
|
20
|
+
} else if (player.canPlayType("application/vnd.apple.mpegurl")) player.src = src;
|
|
21
|
+
return ()=>{
|
|
22
|
+
if (hls) hls.destroy();
|
|
23
|
+
if (player) {
|
|
24
|
+
player.src = "";
|
|
25
|
+
player.load();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
24
28
|
}, [
|
|
25
29
|
src
|
|
26
30
|
]);
|
|
@@ -28,5 +32,5 @@ const HlsPlayer = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
28
32
|
ref: video,
|
|
29
33
|
...rest
|
|
30
34
|
});
|
|
31
|
-
}
|
|
35
|
+
};
|
|
32
36
|
export { HlsPlayer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepsea-components",
|
|
3
|
-
"version": "5.17.
|
|
3
|
+
"version": "5.17.34",
|
|
4
4
|
"description": "格数科技自用组件库",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"hls.js": "^1.6.13",
|
|
42
42
|
"smooth-scrollbar": "^8.8.4",
|
|
43
43
|
"stable-hash": "^0.0.6",
|
|
44
|
-
"deepsea-tools": "5.47.
|
|
45
|
-
"soda-hooks": "6.16.
|
|
44
|
+
"deepsea-tools": "5.47.9",
|
|
45
|
+
"soda-hooks": "6.16.22"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": ">=5.8.3"
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentProps, FC, useEffect, useImperativeHandle, useRef } from "react"
|
|
4
4
|
|
|
5
5
|
import Hls from "hls.js"
|
|
6
6
|
|
|
7
|
-
export interface HlsPlayerProps extends Omit<
|
|
7
|
+
export interface HlsPlayerProps extends Omit<ComponentProps<"video">, "src" | "children"> {
|
|
8
8
|
src: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const HlsPlayer
|
|
12
|
-
const { src, ...rest } = props
|
|
11
|
+
export const HlsPlayer: FC<HlsPlayerProps> = ({ ref, src, ...rest }) => {
|
|
13
12
|
const video = useRef<HTMLVideoElement>(null)
|
|
14
13
|
|
|
15
14
|
useImperativeHandle(ref, () => video.current!, [])
|
|
@@ -18,20 +17,35 @@ export const HlsPlayer = forwardRef<HTMLVideoElement, HlsPlayerProps>((props, re
|
|
|
18
17
|
const { current: player } = video
|
|
19
18
|
if (!player || !src) return
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
player.src = src
|
|
23
|
-
return
|
|
24
|
-
}
|
|
20
|
+
let hls: Hls | null = null
|
|
25
21
|
|
|
22
|
+
// 1. 优先检查是否支持 hls.js (MSE 模式)
|
|
23
|
+
// 这将覆盖 Chrome, Firefox, Edge 等现代浏览器,绕过它们不成熟或过于严格的原生 HLS 引擎
|
|
26
24
|
if (Hls.isSupported()) {
|
|
27
|
-
|
|
25
|
+
hls = new Hls()
|
|
28
26
|
hls.loadSource(src)
|
|
29
27
|
hls.attachMedia(player)
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
|
|
29
|
+
// 绑定错误监听以便调试
|
|
30
|
+
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
31
|
+
console.log(event)
|
|
32
|
+
console.log(data)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 2. 只有在 hls.js 不可用时,才尝试原生播放 (主要针对 iOS Safari 和 macOS Safari)
|
|
37
|
+
else if (player.canPlayType("application/vnd.apple.mpegurl")) player.src = src
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
if (hls) hls.destroy()
|
|
41
|
+
|
|
42
|
+
// 清理原生 src,防止切换地址时内存泄漏
|
|
43
|
+
if (player) {
|
|
44
|
+
player.src = ""
|
|
45
|
+
player.load()
|
|
32
46
|
}
|
|
33
47
|
}
|
|
34
48
|
}, [src])
|
|
35
49
|
|
|
36
50
|
return <video ref={video} {...rest} />
|
|
37
|
-
}
|
|
51
|
+
}
|