Skip to content

Commit e087f15

Browse files
committed
feat: create LiveStreamPlayer component
1 parent 50b1ea6 commit e087f15

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { useEffect, useRef } from 'react';
2+
import Hls from 'hls.js';
3+
4+
type Props = {
5+
src: string;
6+
width?: string;
7+
height?: string;
8+
borderRadius?: string;
9+
};
10+
11+
const LiveStreamPlayer: React.FC<Props> = ({ src, width = '100%', height = '100%', borderRadius = '8px' }) => {
12+
const videoRef = useRef<HTMLVideoElement | null>(null);
13+
14+
useEffect(() => {
15+
const video = videoRef.current;
16+
17+
if (video) {
18+
if (video.canPlayType('application/vnd.apple.mpegurl')) {
19+
video.src = src;
20+
} else if (Hls.isSupported()) {
21+
const hls = new Hls();
22+
hls.loadSource(src);
23+
hls.attachMedia(video);
24+
25+
return () => hls.destroy();
26+
} else {
27+
console.error('HLS no soportado');
28+
}
29+
}
30+
}, [src]);
31+
32+
return (
33+
<div>
34+
<video
35+
ref={videoRef}
36+
controls
37+
style={{ width: width, height: height, borderRadius: borderRadius }}
38+
/>
39+
</div>
40+
);
41+
};
42+
43+
export default LiveStreamPlayer;

common-front/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common-front/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/react": "^18.2.0",
2222
"@vitejs/plugin-react": "^4.0.0",
2323
"@zerollup/ts-transform-paths": "^1.7.18",
24+
"hls.js": "^1.6.2",
2425
"lodash": "^4.17.21",
2526
"math": "^0.0.3",
2627
"react": "^18.2.0",

0 commit comments

Comments
 (0)