From ae6d27b0831c9b62e876c09c382de34f4deac086 Mon Sep 17 00:00:00 2001
From: Pinapelz
Date: Sun, 14 Apr 2024 02:26:50 -0700
Subject: change input method to remote json url - fixes character escaping
issues with query params
---
pages/index.tsx | 92 +++++++++++++++++++++++++++++----------------------------
1 file changed, 47 insertions(+), 45 deletions(-)
(limited to 'pages/index.tsx')
diff --git a/pages/index.tsx b/pages/index.tsx
index 259776d..a008fdc 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -17,45 +17,52 @@ const CustomPlayerPage = () => {
const [urlVideo, setUrlVideo] = React.useState("");
const [urlChat, setUrlChat] = React.useState("");
const [urlYtt, setUrlYtt] = React.useState("");
- const [urlInfoJson, setUrlInfoJson] = React.useState("");
const [infoJson, setInfoJson] = React.useState({} as any);
const [showPlayer, setShowPlayer] = React.useState(false);
+ const [dataSet, setDataSet] = React.useState(false);
const { query } = router;
- const videoUrl = query.vid as string;
- const chatUrl = query.chat as string;
- const infoJsonUrl = query.info as string;
- const srv3Url = query.ytt as string;
+ const jsonDataUrl = query.jsonData as string;
+ const timeSeconds = query.time as string;
- if (videoUrl && videoUrl !== urlVideo) {
- setUrlVideo(videoUrl);
- }
- if (chatUrl && chatUrl !== urlChat) {
- setUrlChat(chatUrl);
- }
-
- if (srv3Url && srv3Url !== urlYtt) {
- setUrlYtt(srv3Url);
- }
+ useEffect(() => {
+ if (timeSeconds) {
+ setPlaybackProgress(parseFloat(timeSeconds));
+ }
+ }, [timeSeconds]);
- if (infoJsonUrl && infoJsonUrl !== urlInfoJson) {
- setUrlInfoJson(infoJsonUrl);
- }
- if (videoUrl && !showPlayer) {
- setShowPlayer(true);
+ if(jsonDataUrl && !dataSet) {
+ fetch(jsonDataUrl)
+ .then((res) => res.json())
+ .then((data) => {
+ const { info, video, chat, srv3, ts } = data;
+ if (info) {
+ fetch(info)
+ .then((res) => res.json())
+ .then((data) => {
+ setInfoJson(data);
+ });
+ }
+ if (video) {
+ setUrlVideo(video);
+ }
+ if (chat) {
+ setUrlChat(chat);
+ }
+ if (srv3) {
+ setUrlYtt(srv3);
+ }
+ setDataSet(true);
+ setShowPlayer(true);
+ })
+ .catch((error) => {
+ console.error("Error fetching JSON data:", error);
+ setDataSet(true);
+ setShowPlayer(true);
+ });
}
- useEffect(() => {
- if (urlInfoJson) {
- fetch(urlInfoJson)
- .then((res) => res.json())
- .then((data) => {
- setInfoJson(data);
- });
- }
- }),
- [urlChat];
const handleFile = (
e: React.ChangeEvent,
@@ -157,7 +164,7 @@ const CustomPlayerPage = () => {
) : null}
- {!videoUrl ? (
+ {urlVideo ? (
+
+
+ This is a specialized version of the player that allows you to pass in a json data file.
+