- 键盘控制:数字按名次选车、方向键移动光标、出/收字幕、圈数 +/-、计时器、 名次脚本、快捷键总表;在输入框里打字时不触发,每次按键都有 Toast 反馈 - 车手名单编辑器(E):姓名/缩写/车号/国籍/车队/性能/黄T摄/头像均可改, 支持调整发车顺位、单条重置、全部重置、JSON 导入导出,localStorage 持久化 - LAP 可手动 +/-,LAP 旁新增 mm:ss.mmm 计时器(零点=计时榜出现的瞬间) - 名次脚本(J):JSON 预设,以计时器为零点,支持 swap/move/retire/restore/lap 与 order * 改脚本即时生效并从零重播,修掉"改完之后过期事件被一次性爆发"的问题 * order 立即铺回赛道;写错会在状态条里报出具体原因,不再静默失败 * localStorage 持久化,刷新不再丢失 - 合并 feature/standalone-output:OBS 透明输出页 /output 与 WebSocket 中继 server/relayServer.js * 修复中继晚连接的输出页只能收到最后一片补丁(缓存改为合并累加) - 修复 react-spring 缺少 deps 导致进场动画被每次渲染重启 (chyron、百叶窗、wipe、计时塔名次描边) - 界面中文化(上屏的转播图形保持英文),F1 字体栈补 CJK 回退 - 新增「启动开发服务器.cmd」一键启动,.gitignore 排除本地工具目录
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { useEffect } from "react";
|
|
import { useStore } from "react-redux";
|
|
|
|
import { RootState } from "../../types/state";
|
|
import {
|
|
createOutputChannel,
|
|
createSnapshotCollector,
|
|
} from "../../features/outputChannel/outputChannel";
|
|
|
|
/**
|
|
* Controller-side publisher. Mounted once in the app shell, it mirrors the
|
|
* broadcast slices of the store to the relay (see server/relayServer.js) so any
|
|
* number of output pages stay in sync. Add "?bridge=0" to a URL to opt out.
|
|
*
|
|
* Two rules keep it from disturbing the UI it is mirroring:
|
|
* - nothing is read or sent while no relay is attached;
|
|
* - every state transition is flushed on a microtask so the output sees the
|
|
* same sequence of states the controller rendered. A time-based throttle
|
|
* would merge them (e.g. the chyron's "closed" and "open" states) and the
|
|
* output would mount already-open, skipping the enter animation entirely.
|
|
*/
|
|
export function BroadcastBridge() {
|
|
const store = useStore<RootState>();
|
|
|
|
useEffect(() => {
|
|
const params = new URLSearchParams(window.location.search);
|
|
if (params.get("bridge") === "0") return undefined;
|
|
|
|
const collector = createSnapshotCollector();
|
|
let scheduled = false;
|
|
|
|
const flush = () => {
|
|
scheduled = false;
|
|
if (channel.getStatus() !== "open") return;
|
|
const patch = collector.collect(store.getState());
|
|
if (patch != null) channel.sendState(patch);
|
|
};
|
|
|
|
const schedule = () => {
|
|
if (scheduled) return;
|
|
scheduled = true;
|
|
queueMicrotask(flush);
|
|
};
|
|
|
|
const channel = createOutputChannel({
|
|
role: "controller",
|
|
onStatus: (status) => {
|
|
// A fresh (or reconnected) output needs the whole picture.
|
|
if (status !== "open") return;
|
|
collector.reset();
|
|
schedule();
|
|
},
|
|
});
|
|
|
|
const unsubscribe = store.subscribe(schedule);
|
|
schedule();
|
|
|
|
return () => {
|
|
unsubscribe();
|
|
channel.close();
|
|
};
|
|
}, [store]);
|
|
|
|
return null;
|
|
}
|