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>
216 lines
7.9 KiB
TypeScript
216 lines
7.9 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
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 = [
|
|
{ value: 'subnet', label: '子网优先(推荐)' },
|
|
{ value: 'weighted', label: '权重均衡' },
|
|
{ value: 'round-robin', label: '轮询' },
|
|
{ value: 'least-conn', label: '最少连接' },
|
|
]
|
|
|
|
export default function SettingsPage() {
|
|
const { brand, refresh } = useBrand()
|
|
const [strategy, setStrategy] = useState('subnet')
|
|
const [multicastEnabled, setMulticastEnabled] = useState(true)
|
|
const [multicastAvailable, setMulticastAvailable] = useState(false)
|
|
const [brandName, setBrandName] = useState(brand.brand_name)
|
|
const [brandTagline, setBrandTagline] = useState(brand.brand_tagline)
|
|
const [brandLogoUrl, setBrandLogoUrl] = useState(brand.brand_logo_url)
|
|
const [profiles, setProfiles] = useState<Profiles>({})
|
|
const [saving, setSaving] = useState(false)
|
|
|
|
useEffect(() => {
|
|
void Promise.all([api.get('/nodes/strategy'), api.get('/settings/transcode-profiles')])
|
|
.then(([nodes, transcode]) => {
|
|
setStrategy(nodes.data.strategy)
|
|
setMulticastEnabled(nodes.data.multicast_enabled)
|
|
setMulticastAvailable(nodes.data.multicast_available)
|
|
setProfiles(transcode.data.profiles || {})
|
|
})
|
|
.catch(() => toast.error('系统设置加载失败'))
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
setBrandName(brand.brand_name)
|
|
setBrandTagline(brand.brand_tagline)
|
|
setBrandLogoUrl(brand.brand_logo_url)
|
|
}, [brand])
|
|
|
|
function updateQuality(profile: string, index: number, patch: Partial<Quality>) {
|
|
setProfiles((current) => ({
|
|
...current,
|
|
[profile]: current[profile].map((quality, i) => (i === index ? { ...quality, ...patch } : quality)),
|
|
}))
|
|
}
|
|
|
|
function addQuality(profile: string) {
|
|
setProfiles((current) => ({
|
|
...current,
|
|
[profile]: [...current[profile], { label: '新清晰度', width: 1280, height: 720, bitrate: '2000k' }],
|
|
}))
|
|
}
|
|
|
|
function removeQuality(profile: string, index: number) {
|
|
setProfiles((current) => ({
|
|
...current,
|
|
[profile]: current[profile].filter((_, i) => i !== index),
|
|
}))
|
|
}
|
|
|
|
async function saveAll() {
|
|
setSaving(true)
|
|
try {
|
|
await Promise.all([
|
|
api.put('/nodes/strategy', { strategy, multicast_enabled: multicastEnabled }),
|
|
api.put('/settings/brand', { brand_name: brandName, brand_tagline: brandTagline, brand_logo_url: brandLogoUrl }),
|
|
api.put('/settings/transcode-profiles', { profiles }),
|
|
])
|
|
await refresh()
|
|
toast.success('设置已保存')
|
|
} catch {
|
|
toast.error('保存失败,请检查转码参数')
|
|
} finally {
|
|
setSaving(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<PageHeader title="系统设置" kicker="Settings" description="配置分发策略、转码清晰度与平台品牌" />
|
|
|
|
<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>
|
|
<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>
|
|
|
|
<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>
|
|
|
|
<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>
|
|
)
|
|
}
|