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) <[email protected]>
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

+7 -67
View File
@@ -1,18 +1,13 @@
param(
[switch]$NoFrontend,
[switch]$NoMediaMTX,
[switch]$InstallDeps,
[string]$HostAddress = "0.0.0.0",
[int]$BackendPort = 8080,
[int]$FrontendPort = 5173
[int]$BackendPort = 8080
)
$ErrorActionPreference = "Stop"
$Base = Split-Path -Parent $MyInvocation.MyCommand.Path
$BackendDir = Join-Path $Base "backend"
$FrontendDir = Join-Path $Base "frontend"
$MediaDir = Join-Path $Base "mediamtx"
$RuntimeDir = Join-Path $Base "runtime"
$HlsDir = Join-Path $RuntimeDir "hls"
$ReplayDir = Join-Path $RuntimeDir "replay"
@@ -37,75 +32,20 @@ function Resolve-Python {
throw "Python not found. Install Python 3.11+ or create backend\.venv."
}
function Assert-Command($Name, $Hint) {
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "$Name not found. $Hint"
}
}
$Python = Resolve-Python
Assert-Command "npm" "Install Node.js LTS and make npm available in PATH."
Assert-Command "ffmpeg" "Install FFmpeg and make ffmpeg.exe available in PATH."
if (-not $NoMediaMTX) {
Assert-Command "mediamtx" "Install MediaMTX and make mediamtx.exe available in PATH, or run with -NoMediaMTX."
}
if ($InstallDeps) {
Write-Host "[StreamCore] Installing backend dependencies..."
Push-Location $BackendDir
& $Python -m pip install -r requirements.txt
Pop-Location
if (-not $NoFrontend) {
Write-Host "[StreamCore] Installing frontend dependencies..."
Push-Location $FrontendDir
npm install
Pop-Location
}
}
$processes = @()
if (-not $NoMediaMTX) {
Write-Host "[StreamCore] Starting MediaMTX origin on RTMP :1935 and HLS :8888..."
$processes += Start-Process -FilePath "mediamtx" -ArgumentList "mediamtx.yml" -WorkingDirectory $MediaDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "mediamtx.out.log") -RedirectStandardError (Join-Path $LogDir "mediamtx.err.log")
}
# MediaMTX, the transcoders and the HLS tree are managed by the backend itself:
# it starts the media origin at boot, supervises ffmpeg, and restarts either if it
# dies. This launcher only has to bring up the process that owns all of that.
Write-Host "[StreamCore] Starting backend on ${HostAddress}:${BackendPort} ..."
Write-Host "[StreamCore] MediaMTX, transcoders and HLS are supervised by the backend."
$backendArgs = @("-m", "uvicorn", "main:app", "--host", $HostAddress, "--port", "$BackendPort")
$processes += Start-Process -FilePath $Python -ArgumentList $backendArgs -WorkingDirectory $BackendDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "backend.out.log") -RedirectStandardError (Join-Path $LogDir "backend.err.log")
if (-not $NoFrontend) {
Write-Host "[StreamCore] Starting frontend on ${HostAddress}:${FrontendPort} ..."
$frontendArgs = @("run", "dev", "--", "--host", $HostAddress, "--port", "$FrontendPort")
$processes += Start-Process -FilePath "npm" -ArgumentList $frontendArgs -WorkingDirectory $FrontendDir -PassThru -RedirectStandardOutput (Join-Path $LogDir "frontend.out.log") -RedirectStandardError (Join-Path $LogDir "frontend.err.log")
}
Start-Sleep -Seconds 3
Write-Host ""
Write-Host "[StreamCore] Windows deployment started."
Write-Host " Backend: http://127.0.0.1:$BackendPort/docs"
if (-not $NoFrontend) { Write-Host " Frontend: http://127.0.0.1:$FrontendPort/" }
if (-not $NoMediaMTX) {
Write-Host " RTMP: rtmp://127.0.0.1:1935/live/<stream_key>"
Write-Host " HLS: http://127.0.0.1:8888/<stream_key>/index.m3u8"
}
Write-Host " Runtime: $RuntimeDir"
Write-Host " HLS dir: $env:LS_HLS_RUNTIME_DIR"
Write-Host " Logs: $LogDir"
Write-Host ""
Write-Host "Press Ctrl+C to stop child processes."
try {
while ($true) {
foreach ($proc in $processes) {
if ($proc.HasExited) {
throw "Process $($proc.Id) exited with code $($proc.ExitCode). Check logs in $LogDir."
}
}
Start-Sleep -Seconds 2
}
} finally {
Write-Host "[StreamCore] Stopping child processes..."
foreach ($proc in $processes) {
if (-not $proc.HasExited) { Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue }
}
}
& $Python @backendArgs