FEAT: Add functionality to update ongoing stream on frontend
This commit is contained in:
@@ -6,7 +6,7 @@ import ListItem from "../components/Layout/ListItem";
|
||||
import { X as XIcon, Eye as ShowIcon, EyeOff as HideIcon } from "lucide-react";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import { debounce } from "lodash";
|
||||
import VideoPlayer from "../components/Video/VideoPlayer";
|
||||
import VideoPlayer from "../components/Stream/VideoPlayer";
|
||||
|
||||
interface StreamData {
|
||||
title: string;
|
||||
@@ -66,6 +66,10 @@ const StreamDashboardPage: React.FC = () => {
|
||||
}, [categories, thumbnailPreview.isCustom]);
|
||||
|
||||
useEffect(() => {
|
||||
checkStreamStatus();
|
||||
fetchCategories();
|
||||
}, [username]);
|
||||
|
||||
const checkStreamStatus = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/user/${username}/status`);
|
||||
@@ -102,14 +106,13 @@ const StreamDashboardPage: React.FC = () => {
|
||||
}m ago`
|
||||
);
|
||||
} else {
|
||||
// Just need the stream key if not streaming
|
||||
const response = await fetch(`/api/user/${username}/stream_key`);
|
||||
const keyData = await response.json();
|
||||
setStreamData((prev) => ({
|
||||
...prev,
|
||||
stream_key: keyData.stream_key,
|
||||
}));
|
||||
|
||||
console.log("Stream key:", keyData.stream_key);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error checking stream status:", error);
|
||||
@@ -127,10 +130,6 @@ const StreamDashboardPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
checkStreamStatus();
|
||||
fetchCategories();
|
||||
}, [username]);
|
||||
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setStreamData((prev) => ({ ...prev, [name]: value }));
|
||||
@@ -201,11 +200,11 @@ const StreamDashboardPage: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const handleStartStream = async () => {
|
||||
const handlePublishStream = async () => {
|
||||
console.log("Starting stream with data:", streamData);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("key", streamData.stream_key);
|
||||
formData.append("data", JSON.stringify(streamData));
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/publish_stream", {
|
||||
@@ -228,6 +227,30 @@ const StreamDashboardPage: React.FC = () => {
|
||||
|
||||
const handleUpdateStream = async () => {
|
||||
console.log("Updating stream with data:", streamData);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("key", streamData.stream_key);
|
||||
formData.append("title", streamData.title);
|
||||
formData.append("category_name", streamData.category_name);
|
||||
if (thumbnail) {
|
||||
formData.append("thumbnail", thumbnail);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/update_stream", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log("Stream updated successfully");
|
||||
window.location.reload();
|
||||
} else {
|
||||
console.error("Failed to update stream");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error updating stream:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEndStream = async () => {
|
||||
@@ -392,7 +415,7 @@ const StreamDashboardPage: React.FC = () => {
|
||||
<div className="flex gap-8">
|
||||
<Button
|
||||
onClick={
|
||||
isStreaming ? handleUpdateStream : handleStartStream
|
||||
isStreaming ? handleUpdateStream : handlePublishStream
|
||||
}
|
||||
disabled={!isFormValid()}
|
||||
extraClasses="text-2xl px-8 py-4 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
|
||||
Reference in New Issue
Block a user