Skip to content

Commit a0a6fc7

Browse files
committed
Fetch and display livestream information including title and user details
1 parent f2ee832 commit a0a6fc7

File tree

1 file changed

+72
-15
lines changed

1 file changed

+72
-15
lines changed

src/pages/WatchLiveStream.js

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import CopyButton from "../components/ButtonCustom/CopyButton";
66
import ReactPlayer from "react-player";
77
import { ToastContainer, toast } from "react-toastify";
88
import { useParams } from 'react-router-dom';
9+
import avatar from '../assets/images/avar.jpg';
910
const WatchLiveStream = () => {
1011
const [isStreamLive, setIsStreamLive] = useState(false); // Trạng thái livestream
1112
const [chatMessages, setChatMessages] = useState([]); // Phải là một mảng
1213
const [message, setMessage] = useState(""); // Tin nhắn hiện tại
1314
const { streamKey } = useParams();
1415
const streamUrl = `http://192.168.120.213:13000/hls/${streamKey}.m3u8`;
1516
const eventCode = streamKey; // Mã sự kiện mặc định
17+
const [streamInfo, setStreamInfo] = useState({
18+
titleLive: "",
19+
userName: ""
20+
});
1621
console.log(streamKey + "asddas");
1722
// Kiểm tra trạng thái livestream
1823
const checkStreamStatus = async () => {
@@ -88,6 +93,26 @@ const WatchLiveStream = () => {
8893
}
8994
}
9095
};
96+
useEffect(() => {
97+
// Gọi API để lấy thông tin stream
98+
const fetchStreamInfo = async () => {
99+
try {
100+
const response = await fetch(`http://103.9.157.149:15001/streams/get/${streamKey}`);
101+
if (!response.ok) {
102+
throw new Error("Failed to fetch stream info");
103+
}
104+
const data = await response.json();
105+
setStreamInfo({
106+
titleLive: data.titleLive,
107+
userName: data.userName
108+
});
109+
} catch (error) {
110+
console.error("Error fetching stream info:", error);
111+
}
112+
};
113+
114+
fetchStreamInfo();
115+
}, [streamKey]);
91116

92117
return (
93118
<div className="bg-[#f0f4f9] h-screen">
@@ -117,23 +142,55 @@ const WatchLiveStream = () => {
117142
</div>
118143

119144
{/* Thông tin livestream */}
120-
<div className="mt-4 flex justify-between items-center">
121-
<div className="flex space-x-4">
122-
<button className="flex items-center text-gray-700 hover:text-blue-600">
123-
<AiOutlineLike className="mr-1" size={20} />
124-
<span>Like</span>
125-
</button>
126-
<button className="flex items-center text-gray-700 hover:text-red-600">
127-
<AiOutlineDislike className="mr-1" size={20} />
128-
<span>Dislike</span>
129-
</button>
130-
<button className="flex items-center text-gray-700 hover:text-green-600">
131-
<CiShare1 className="mr-1" size={20} />
132-
<span>Share</span>
133-
</button>
145+
<div className="mt-4">
146+
{/* Title */}
147+
<h2 className="font-medium font-roboto my-[10px] flex gap-3 bg-white text-[24px]">{streamInfo.titleLive || "Loading title..."}</h2>
148+
<hr></hr>
149+
{/* User */}
150+
{/* User Info */}
151+
<div className="flex items-center mt-2 justify-between">
152+
{/* Avatar và Thông tin người dùng */}
153+
<div className="flex items-center space-x-3">
154+
{/* Avatar */}
155+
<img
156+
src={avatar}
157+
alt="User Avatar"
158+
className="w-12 h-12 rounded-full object-cover"
159+
/>
160+
<div>
161+
{/* User Name */}
162+
<p className="text-[20px] font-bold cursor-pointer px-1 py-1 rounded-[10px] hover:bg-[#dadada]">
163+
{streamInfo.userName || "Loading user..."}
164+
</p>
165+
{/* Followers */}
166+
<p className="font-roboto text-gray-600 text-sm">
167+
Theo dõi: 0
168+
</p>
134169
</div>
135-
<CopyButton textToCopy={streamUrl} />
170+
<button className="bg-red-500 text-white font-medium px-4 py-2 rounded-md hover:bg-red-600">
171+
Theo dõi
172+
</button>
173+
</div>
174+
175+
{/* Các nút hành động */}
176+
<div className="flex items-center space-x-4">
177+
{/* Nút Theo dõi */}
178+
179+
{/* Nút Like */}
180+
<button className="flex items-center text-gray-700 hover:text-blue-600">
181+
<AiOutlineLike className="mr-1" size={20} />
182+
<span>Like</span>
183+
</button>
184+
185+
{/* Nút Share */}
186+
<button className="flex items-center text-gray-700 hover:text-green-600">
187+
<CiShare1 className="mr-1" size={20} />
188+
<span>Share</span>
189+
</button>
190+
</div>
136191
</div>
192+
</div>
193+
137194
</div>
138195

139196
{/* Chat box */}

0 commit comments

Comments
 (0)