- Added Chat frontend, interfaces with backend;
- Updated styles for VideoPage; - Added StreamerRoute component; - Remove unused Login and Signup pages; - Update to Navbar and Logo components for new structure on different pages; - Update to auth flow to display error messages to user;
This commit is contained in:
41
frontend/src/components/Stream/StreamerRoute.tsx
Normal file
41
frontend/src/components/Stream/StreamerRoute.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import VideoPage from "../../pages/VideoPage";
|
||||
import UserPage from "../../pages/UserPage";
|
||||
|
||||
const StreamerRoute: React.FC = () => {
|
||||
const { streamerName } = useParams<{ streamerName: string }>();
|
||||
const [isLive, setIsLive] = useState<boolean>(false);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||
|
||||
useEffect(() => {
|
||||
const checkStreamStatus = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/streamer/${streamerName}/status`);
|
||||
const data = await response.json();
|
||||
console.log("Stream status:", data);
|
||||
setIsLive(data.status === "live");
|
||||
} catch (error) {
|
||||
console.error("Error checking stream status:", error);
|
||||
setIsLive(false);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
checkStreamStatus();
|
||||
|
||||
// Poll for live status changes
|
||||
const interval = setInterval(checkStreamStatus, 90000); // Check every 90 seconds
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [streamerName]);
|
||||
|
||||
if (isLoading) {
|
||||
return <div>Loading...</div>; // Or your loading component
|
||||
}
|
||||
|
||||
return isLive ? <VideoPage streamId={1} /> : <UserPage />;
|
||||
};
|
||||
|
||||
export default StreamerRoute;
|
||||
@@ -7,12 +7,12 @@ interface ThumbnailProps {
|
||||
|
||||
const Thumbnail = ({ path, alt }: ThumbnailProps) => {
|
||||
return (
|
||||
<div>
|
||||
<div id='stream-thumbnail'>
|
||||
<img
|
||||
width={300}
|
||||
src={path}
|
||||
alt={alt}
|
||||
className="stream-thumbnail rounded-md"
|
||||
className="rounded-md"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user