param( [switch]$NoFrontend, [switch]$NoMediaMTX, [switch]$InstallDeps, [string]$HostAddress = "0.0.0.0", [int]$BackendPort = 8080, [int]$FrontendPort = 5173 ) $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" $LogDir = Join-Path $RuntimeDir "logs" New-Item -ItemType Directory -Force -Path $RuntimeDir, $HlsDir, $ReplayDir, $LogDir | Out-Null if (-not $env:LS_HLS_RUNTIME_DIR) { $env:LS_HLS_RUNTIME_DIR = $HlsDir } if (-not $env:LS_REPLAY_MEDIA_DIR) { $env:LS_REPLAY_MEDIA_DIR = $ReplayDir } function Resolve-Python { $candidates = @( (Join-Path $BackendDir ".venv\Scripts\python.exe"), (Join-Path $BackendDir "venv\Scripts\python.exe"), "python", "py" ) foreach ($candidate in $candidates) { if (Test-Path $candidate) { return $candidate } $cmd = Get-Command $candidate -ErrorAction SilentlyContinue if ($cmd) { return $cmd.Source } } 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") } Write-Host "[StreamCore] Starting backend on ${HostAddress}:${BackendPort} ..." $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/" Write-Host " HLS: http://127.0.0.1:8888//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 } } }