feat: consolidate on the shadcn frontend and harden playback

Frontend
- Replace the Ant Design app with the shadcn/ui app as the single frontend,
  keeping the portfolio side-by-side revertible in this commit.
- Drop the abandoned mdui experiment and the AntD tree so there is one app,
  one router and one design system to maintain.

Live playback
- Stop racing the encoder. lowLatencyMode + liveSyncDurationCount:1 targeted a
  single 4s segment, so playback ran at up to 1.10x and the forward buffer
  bottomed out at 0.1s, re-buffering every segment. Measured over 40s:
  buffer min 0.1s -> 8.9s, rate 1.00 constant, 0 stalls.
- Remove the 落后 labels and the page-level edge-snapping timer that fought
  hls.js over two different definitions of "latency".
- Live can no longer be paused: the control is not rendered while it plays, so
  the icon can never misreport state.
- Fix autoplay: muted autoplay started silently and never unmuted, and the
  gesture that restored sound also toggled playback off. One owner now.

Source ("原画") rendition
- Publish the publisher's stream remuxed losslessly via -c:v copy alongside the
  transcoded ones, so a source option exists even when every ladder entry
  downsizes.
- Give renditions an ASCII path slug: the HLS path is part of the URL and
  MediaMTX rejects non-alphanumeric paths, so 原画 could never be served.

Backend
- Supervise MediaMTX from the backend: start it at boot and restart it on exit,
  never killing an origin it did not start.
- Clear stale HLS output before restarting an encoder; an ENDLIST-less playlist
  left by a dead encoder hangs hls.js forever.
- Mark JSON timestamps as UTC. utcnow().isoformat() emitted a naive string that
  JS read as local time, so every viewer heartbeat looked 8 hours old in UTC+8
  and the live board's active-viewer count was permanently zero.
- Rebind a viewer session when it arrives on another stream instead of failing,
  and survive the StrictMode double-heartbeat race on first insert.
- Replace the Linux-only /proc and os.getloadavg metrics with psutil.
- Complete MediaMTX's cookieCheck redirect inside /hls proxying, and hold the
  httpx client open for the streamed body.

Housekeeping
- Ignore RainOSS (it stores accessKeySecret), runtime output, TLS keys and
  .venv; remove generated screenshots, load test scripts and stray files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-09-22 18:07:56 +08:00
1 parent 186e32caf1
commit 996e3fea39
70 files changed
+4844 -3070

No files matched your search

+145 -57
View File
@@ -1,15 +1,27 @@
import { useEffect, useState } from 'react'
import { Button, Form, Input, InputNumber, Select, Switch, Typography, message } from 'antd'
import api from '../../api/client'
import './Settings.css'
import { useBrand } from '../../brand/BrandContext'
const { Title, Text } = Typography
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Switch } from '@/components/ui/switch'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { Separator } from '@/components/ui/separator'
import { Trash2, Plus } from 'lucide-react'
import api from '@/api/client'
import { useBrand } from '@/brand/BrandContext'
import { PageHeader } from '@/components/page-header'
type Quality = { label: string; width: number; height: number; bitrate: string }
type Profiles = Record<string, Quality[]>
const strategies = [
const STRATEGIES = [
{ value: 'subnet', label: '子网优先(推荐)' },
{ value: 'weighted', label: '权重均衡' },
{ value: 'round-robin', label: '轮询' },
@@ -35,7 +47,7 @@ export default function SettingsPage() {
setMulticastAvailable(nodes.data.multicast_available)
setProfiles(transcode.data.profiles || {})
})
.catch(() => message.error('系统设置加载失败'))
.catch(() => toast.error('系统设置加载失败'))
}, [])
useEffect(() => {
@@ -44,20 +56,25 @@ export default function SettingsPage() {
setBrandLogoUrl(brand.brand_logo_url)
}, [brand])
function replaceProfile(profile: string, qualities: Quality[]) {
setProfiles(current => Object.assign({}, current, Object.fromEntries([[profile, qualities]])))
}
function updateQuality(profile: string, index: number, patch: Partial<Quality>) {
replaceProfile(profile, profiles[profile].map((quality, i) => i === index ? { ...quality, ...patch } : quality))
setProfiles((current) => ({
...current,
[profile]: current[profile].map((quality, i) => (i === index ? { ...quality, ...patch } : quality)),
}))
}
function addQuality(profile: string) {
replaceProfile(profile, [...profiles[profile], { label: '新清晰度', width: 1280, height: 720, bitrate: '2000k' }])
setProfiles((current) => ({
...current,
[profile]: [...current[profile], { label: '新清晰度', width: 1280, height: 720, bitrate: '2000k' }],
}))
}
function removeQuality(profile: string, index: number) {
replaceProfile(profile, profiles[profile].filter((_, i) => i !== index))
setProfiles((current) => ({
...current,
[profile]: current[profile].filter((_, i) => i !== index),
}))
}
async function saveAll() {
@@ -69,59 +86,130 @@ export default function SettingsPage() {
api.put('/settings/transcode-profiles', { profiles }),
])
await refresh()
message.success('设置已保存')
toast.success('设置已保存')
} catch {
message.error('保存失败,请检查转码参数')
toast.error('保存失败,请检查转码参数')
} finally {
setSaving(false)
}
}
return (
<div className="settings-page">
<Title level={2}>系统设置</Title>
<Text type="secondary">配置分发策略、转码清晰度与平台品牌</Text>
<div className="space-y-6">
<PageHeader title="系统设置" kicker="Settings" description="配置分发策略、转码清晰度与平台品牌" />
<section className="settings-card">
<Title level={4}>负载均衡</Title>
<Form layout="vertical">
<Form.Item label="均衡策略"><Select value={strategy} onChange={setStrategy} options={strategies} /></Form.Item>
<Form.Item label="组播">
<Switch checked={multicastEnabled} onChange={setMulticastEnabled} />
<Text type="secondary"> {multicastAvailable ? '可用' : '不可用,将回退至单播'}</Text>
</Form.Item>
</Form>
</section>
<section className="settings-card">
<Title level={4}>自定义转码配置</Title>
{Object.entries(profiles).map(([profile, qualities]) => (
<div className="profile-block" key={profile}>
<Text strong>{profile}</Text>
{qualities.map((quality, index) => (
<div className="quality-row" key={profile + '-' + index}>
<Input value={quality.label} onChange={e => updateQuality(profile, index, { label: e.target.value })} />
<InputNumber value={quality.width} min={160} max={7680} addonAfter="宽" onChange={v => updateQuality(profile, index, { width: v || 160 })} />
<InputNumber value={quality.height} min={90} max={4320} addonAfter="高" onChange={v => updateQuality(profile, index, { height: v || 90 })} />
<Input value={quality.bitrate} placeholder="2000k" onChange={e => updateQuality(profile, index, { bitrate: e.target.value })} />
<Button danger disabled={qualities.length <= 1} onClick={() => removeQuality(profile, index)}>删除</Button>
</div>
))}
<Button onClick={() => addQuality(profile)}>添加清晰度</Button>
<Card>
<CardHeader>
<CardTitle className="text-base">负载均衡</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label>均衡策略</Label>
<Select value={strategy} onValueChange={setStrategy}>
<SelectTrigger className="max-w-xs">
<SelectValue />
</SelectTrigger>
<SelectContent>
{STRATEGIES.map((s) => (
<SelectItem key={s.value} value={s.value}>
{s.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
))}
</section>
<div className="flex items-center justify-between rounded-md border border-border p-3">
<div>
<Label>组播</Label>
<p className="text-xs text-muted-foreground">{multicastAvailable ? '可用' : '不可用,将回退至单播'}</p>
</div>
<Switch checked={multicastEnabled} onCheckedChange={setMulticastEnabled} />
</div>
</CardContent>
</Card>
<section className="settings-card">
<Title level={4}>品牌设置</Title>
<Form layout="vertical">
<Form.Item label="平台名称"><Input value={brandName} onChange={e => setBrandName(e.target.value)} /></Form.Item>
<Form.Item label="标语"><Input value={brandTagline} onChange={e => setBrandTagline(e.target.value)} /></Form.Item>
<Form.Item label="Logo 图片地址"><Input value={brandLogoUrl} onChange={e => setBrandLogoUrl(e.target.value)} /></Form.Item>
</Form>
</section>
<Card>
<CardHeader>
<CardTitle className="text-base">自定义转码配置</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
{Object.entries(profiles).map(([profile, qualities]) => (
<div key={profile} className="space-y-3">
<div className="flex items-center gap-2">
<span className="font-medium">{profile}</span>
<Separator className="flex-1" />
</div>
{qualities.map((quality, index) => (
<div key={`${profile}-${index}`} className="flex flex-wrap items-center gap-2">
<Input
value={quality.label}
onChange={(e) => updateQuality(profile, index, { label: e.target.value })}
className="w-32"
/>
<Input
type="number"
min={160}
max={7680}
value={quality.width}
onChange={(e) => updateQuality(profile, index, { width: Number(e.target.value || 160) })}
className="w-24"
/>
<Input
type="number"
min={90}
max={4320}
value={quality.height}
onChange={(e) => updateQuality(profile, index, { height: Number(e.target.value || 90) })}
className="w-24"
/>
<Input
value={quality.bitrate}
placeholder="2000k"
onChange={(e) => updateQuality(profile, index, { bitrate: e.target.value })}
className="w-28"
/>
<Button
variant="ghost"
size="icon"
disabled={qualities.length <= 1}
onClick={() => removeQuality(profile, index)}
>
<Trash2 className="h-4 w-4 text-destructive" />
</Button>
</div>
))}
<Button variant="outline" size="sm" onClick={() => addQuality(profile)}>
<Plus className="h-4 w-4" />
添加清晰度
</Button>
</div>
))}
</CardContent>
</Card>
<Button type="primary" size="large" loading={saving} onClick={saveAll}>保存全部设置</Button>
<Card>
<CardHeader>
<CardTitle className="text-base">品牌设置</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label>平台名称</Label>
<Input value={brandName} onChange={(e) => setBrandName(e.target.value)} />
</div>
<div className="space-y-2">
<Label>标语</Label>
<Input value={brandTagline} onChange={(e) => setBrandTagline(e.target.value)} />
</div>
<div className="space-y-2">
<Label>Logo 图片地址</Label>
<Input value={brandLogoUrl} onChange={(e) => setBrandLogoUrl(e.target.value)} />
</div>
</CardContent>
</Card>
<Button size="lg" onClick={saveAll} disabled={saving}>
{saving ? '保存中…' : '保存全部设置'}
</Button>
</div>
)
}