Files
livekit-3d/scripts/start-spatial.ps1
T
arimius 909e51bc0a
Test / test (pull_request) Canceled after 0s
PR Slack Notifier / notify-devs (pull_request) Canceled after 0s
Add server-side spatial audio with HRTF, occlusion and adaptive quality
2026-10-05 17:29:30 +03:00

53 lines
3.3 KiB
PowerShell

# Copyright 2026 Sverse contributors. Licensed under the Apache License, Version 2.0.
[CmdletBinding()]
param([switch]$Restart, [switch]$SkipBuild)
$ErrorActionPreference = 'Stop'
$spatialRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$spatialRuntime = Join-Path $spatialRoot '.spatial-runtime'
$spatialOpus = Join-Path $spatialRuntime 'opus-build\Release\opus.dll'
if (!(Test-Path -LiteralPath $spatialOpus)) {
throw "Missing $spatialOpus. Run scripts/build-spatial-opus.ps1 first."
}
$spatialHRTF = Join-Path $spatialRuntime 'hrtf-build\Release\sverse_hrtf.dll'
$spatialSampleConfig = Get-Content -LiteralPath (Join-Path $spatialRoot 'config-sample-spatial.yaml') -Raw
if ($spatialSampleConfig -match '(?m)^ hrtf:\r?\n enabled: true\s*$' -and !(Test-Path -LiteralPath $spatialHRTF)) {
throw "Missing $spatialHRTF. Run scripts/build-spatial-hrtf.ps1 first for the sample HRTF configuration."
}
if ($Restart) { & (Join-Path $PSScriptRoot 'stop-spatial.ps1') }
foreach ($spatialPort in @(7880, 8899)) {
if (Get-NetTCPConnection -State Listen -LocalPort $spatialPort -ErrorAction SilentlyContinue) {
throw "Port $spatialPort is already in use. Use -Restart for this repository's running laboratory."
}
}
New-Item -ItemType Directory -Path $spatialRuntime -Force | Out-Null
Push-Location -LiteralPath $spatialRoot
try {
if (!$SkipBuild) {
& go build -o .spatial-runtime/livekit-server-current.exe ./cmd/server
if ($LASTEXITCODE -ne 0) { throw 'LiveKit build failed' }
& go build -o .spatial-runtime/spatial-test-current.exe ./cmd/spatial-test
if ($LASTEXITCODE -ne 0) { throw 'HTML laboratory build failed' }
}
foreach ($spatialName in @('livekit-server-current.exe', 'spatial-test-current.exe')) {
if (!(Test-Path -LiteralPath (Join-Path $spatialRuntime $spatialName))) { throw "Missing $spatialName" }
}
$spatialServer = Start-Process -FilePath (Join-Path $spatialRuntime 'livekit-server-current.exe') -ArgumentList '--config', 'config-sample-spatial.yaml' -WorkingDirectory $spatialRoot -WindowStyle Hidden -RedirectStandardOutput (Join-Path $spatialRuntime 'server.stdout.log') -RedirectStandardError (Join-Path $spatialRuntime 'server.stderr.log') -PassThru
$spatialPreviousKey = $env:LIVEKIT_API_KEY
$spatialPreviousSecret = $env:LIVEKIT_API_SECRET
try {
# These credentials match the public local development YAML only.
$env:LIVEKIT_API_KEY = 'devkey'
$env:LIVEKIT_API_SECRET = 'spatial-local-development-secret'
$spatialLab = Start-Process -FilePath (Join-Path $spatialRuntime 'spatial-test-current.exe') -WorkingDirectory $spatialRoot -WindowStyle Hidden -RedirectStandardOutput (Join-Path $spatialRuntime 'lab.stdout.log') -RedirectStandardError (Join-Path $spatialRuntime 'lab.stderr.log') -PassThru
} catch {
Stop-Process -Id $spatialServer.Id -ErrorAction SilentlyContinue
throw
} finally {
$env:LIVEKIT_API_KEY = $spatialPreviousKey
$env:LIVEKIT_API_SECRET = $spatialPreviousSecret
}
Write-Host "LiveKit PID: $($spatialServer.Id); HTML PID: $($spatialLab.Id)"
Write-Host 'Open http://127.0.0.1:8899/ in your browser (do not open index.html as a file).'
Write-Host "Logs: $spatialRuntime"
} finally { Pop-Location }