's'
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Cable, Copy, Monitor, Radio } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { LiveProcessLiveLogCard } from "@/components/live-product/LiveProcessLiveLogCard";
|
||||
|
||||
@@ -53,15 +53,8 @@ type Props = {
|
||||
setCurrentProc: (v: string) => void;
|
||||
urlConfig: string;
|
||||
setUrlConfig: (v: string) => void;
|
||||
douyinUrl: string;
|
||||
setDouyinUrl: (v: string) => void;
|
||||
businessYoutubeKey: string;
|
||||
setBusinessYoutubeKey: (v: string) => void;
|
||||
syncYoutubeIni: boolean;
|
||||
setSyncYoutubeIni: (v: boolean) => void;
|
||||
onRunProcess: (a: "start" | "stop" | "restart") => void;
|
||||
onSaveUrlConfig: (content?: string) => void;
|
||||
onSaveBusinessMeta: () => void;
|
||||
onSaveUrlConfig: (content?: string) => void | Promise<void>;
|
||||
onCopy: (text: string) => void;
|
||||
fetchJson: <T,>(path: string, init?: RequestInit) => Promise<T>;
|
||||
};
|
||||
@@ -74,15 +67,8 @@ export function LiveTiktokHdmiView({
|
||||
setCurrentProc,
|
||||
urlConfig,
|
||||
setUrlConfig,
|
||||
douyinUrl,
|
||||
setDouyinUrl,
|
||||
businessYoutubeKey,
|
||||
setBusinessYoutubeKey,
|
||||
syncYoutubeIni,
|
||||
setSyncYoutubeIni,
|
||||
onRunProcess,
|
||||
onSaveUrlConfig,
|
||||
onSaveBusinessMeta,
|
||||
onCopy,
|
||||
fetchJson,
|
||||
}: Props) {
|
||||
@@ -91,9 +77,37 @@ export function LiveTiktokHdmiView({
|
||||
const [expanded, setExpanded] = useState<string | null>("1080p30");
|
||||
const [selectedPreset, setSelectedPreset] = useState<string>("1080p30");
|
||||
const [urlReloading, setUrlReloading] = useState(false);
|
||||
const [urlAutoRefresh, setUrlAutoRefresh] = useState(true);
|
||||
const [urlFetchNote, setUrlFetchNote] = useState<string | null>(null);
|
||||
const urlListDirtyRef = useRef(false);
|
||||
const [hdmiNotes, setHdmiNotes] = useState("");
|
||||
const [checks, setChecks] = useState<Record<string, boolean>>({});
|
||||
|
||||
useEffect(() => {
|
||||
urlListDirtyRef.current = false;
|
||||
}, [currentProc]);
|
||||
|
||||
const pullUrlConfigFromServer = useCallback(async () => {
|
||||
if (!currentProc) return;
|
||||
try {
|
||||
const data = await fetchJson<{ content?: string }>(
|
||||
`/get_url_config?process=${encodeURIComponent(currentProc)}`,
|
||||
);
|
||||
setUrlConfig(data.content ?? "");
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}, [currentProc, fetchJson, setUrlConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentProc || !urlAutoRefresh) return;
|
||||
const id = window.setInterval(() => {
|
||||
if (urlListDirtyRef.current) return;
|
||||
void pullUrlConfigFromServer();
|
||||
}, 8000);
|
||||
return () => clearInterval(id);
|
||||
}, [currentProc, urlAutoRefresh, pullUrlConfigFromServer]);
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(CHECK_KEY);
|
||||
@@ -129,18 +143,30 @@ export function LiveTiktokHdmiView({
|
||||
const reloadUrlConfig = async () => {
|
||||
if (!currentProc) return;
|
||||
setUrlReloading(true);
|
||||
setUrlFetchNote(null);
|
||||
urlListDirtyRef.current = false;
|
||||
try {
|
||||
const data = await fetchJson<{ content?: string }>(
|
||||
`/get_url_config?process=${encodeURIComponent(currentProc)}`,
|
||||
);
|
||||
setUrlConfig(data.content || "");
|
||||
} catch {
|
||||
/* parent may show via busy */
|
||||
setUrlConfig(data.content ?? "");
|
||||
setUrlFetchNote(t("已从服务器读取 URL_config", "Reloaded URL_config from server"));
|
||||
} catch (e) {
|
||||
setUrlFetchNote((e as Error).message);
|
||||
} finally {
|
||||
setUrlReloading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveUrlAndClearDirty = async () => {
|
||||
try {
|
||||
await Promise.resolve(onSaveUrlConfig());
|
||||
urlListDirtyRef.current = false;
|
||||
} catch {
|
||||
/* parent 已 toast */
|
||||
}
|
||||
};
|
||||
|
||||
const lock = busy || urlReloading;
|
||||
const presetLabel = PRESETS.find((p) => p.id === selectedPreset);
|
||||
|
||||
@@ -281,48 +307,6 @@ export function LiveTiktokHdmiView({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-2xl border border-white/[0.08] bg-zinc-950/50 p-6">
|
||||
<h3 className="text-sm font-semibold text-white">{t("业务元数据(配置中心)", "Hub business metadata")}</h3>
|
||||
<p className="mt-1 text-xs text-zinc-500">
|
||||
{t("与 YouTube 页共用一份 business JSON;HDMI/TikTok 场景可只填抖音 URL。", "Shared business JSON with YouTube page.")}
|
||||
</p>
|
||||
<label className="mt-4 block text-xs text-zinc-400">{t("抖音直播间 URL", "Douyin live URL")}</label>
|
||||
<input
|
||||
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-4 py-3 text-sm"
|
||||
value={douyinUrl}
|
||||
onChange={(e) => setDouyinUrl(e.target.value)}
|
||||
placeholder="https://live.douyin.com/..."
|
||||
/>
|
||||
<label className="mt-3 block text-xs text-zinc-400">
|
||||
{t("YouTube 串流密钥(声明式,可选)", "YouTube key (optional declarative)")}
|
||||
</label>
|
||||
<input
|
||||
className="mt-1 w-full rounded-xl border border-white/10 bg-black/40 px-4 py-3 font-mono text-sm text-zinc-200"
|
||||
spellCheck={false}
|
||||
autoComplete="off"
|
||||
value={businessYoutubeKey}
|
||||
onChange={(e) => setBusinessYoutubeKey(e.target.value)}
|
||||
placeholder="xxxx-xxxx…"
|
||||
/>
|
||||
<label className="mt-3 flex cursor-pointer items-start gap-2 text-xs text-zinc-300">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="mt-0.5 rounded border-white/20 bg-black/40"
|
||||
checked={syncYoutubeIni}
|
||||
onChange={(e) => setSyncYoutubeIni(e.target.checked)}
|
||||
/>
|
||||
<span>{t("同时写入 config/youtube.ini 的 key=", "Also sync key= to config/youtube.ini")}</span>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
disabled={lock}
|
||||
onClick={() => void onSaveBusinessMeta()}
|
||||
className="mt-3 rounded-xl bg-violet-500/25 px-4 py-2 text-sm font-medium text-violet-100 ring-1 ring-violet-500/35"
|
||||
>
|
||||
{t("保存到配置中心", "Save to hub")}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="rounded-2xl border border-white/[0.08] bg-zinc-950/50 p-6">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="text-sm font-semibold text-white">{t("直播地址列表 · URL_config.ini", "URL_config.ini")}</h3>
|
||||
@@ -335,11 +319,31 @@ export function LiveTiktokHdmiView({
|
||||
{t("复制全文", "Copy all")}
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-zinc-500">{t("一行一个地址;与 YouTube 单频道页相同维护方式。", "One URL per line; same as YouTube single.")}</p>
|
||||
<p className="mt-1 text-xs text-zinc-500">
|
||||
{t(
|
||||
"一行一个地址;可勾选自动从服务器刷新,或点「重新读取」手动同步。",
|
||||
"One URL per line; enable auto-refresh or reload from server.",
|
||||
)}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-4 text-xs text-zinc-400">
|
||||
<label className="flex cursor-pointer items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="rounded border-white/20 bg-black/40"
|
||||
checked={urlAutoRefresh}
|
||||
onChange={(e) => setUrlAutoRefresh(e.target.checked)}
|
||||
/>
|
||||
{t("每 8 秒自动从服务器刷新", "Auto-refresh from server every 8s")}
|
||||
</label>
|
||||
</div>
|
||||
{urlFetchNote ? <p className="mt-2 text-xs text-zinc-500">{urlFetchNote}</p> : null}
|
||||
<textarea
|
||||
className="mt-4 min-h-[200px] w-full resize-y rounded-xl border border-white/10 bg-black/50 p-4 font-mono text-xs text-zinc-300"
|
||||
value={urlConfig}
|
||||
onChange={(e) => setUrlConfig(e.target.value)}
|
||||
onChange={(e) => {
|
||||
urlListDirtyRef.current = true;
|
||||
setUrlConfig(e.target.value);
|
||||
}}
|
||||
spellCheck={false}
|
||||
/>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
@@ -354,7 +358,7 @@ export function LiveTiktokHdmiView({
|
||||
<button
|
||||
type="button"
|
||||
disabled={lock}
|
||||
onClick={() => onSaveUrlConfig()}
|
||||
onClick={() => void saveUrlAndClearDirty()}
|
||||
className="rounded-xl bg-cyan-500/20 px-4 py-2 text-sm font-medium text-cyan-100 ring-1 ring-cyan-500/30"
|
||||
>
|
||||
{t("保存 URL 配置", "Save URL config")}
|
||||
|
||||
Reference in New Issue
Block a user