Files
OwnCord/Server/api/livekit_proxy.go
T
jevb bf3fada16b fix: proxy LiveKit through HTTPS to fix mixed-content block
- Add reverse proxy at /livekit/* that forwards to LiveKit server
- Server sends relative URL "/livekit" in voice_token; client
  resolves to wss://server:port/livekit using known server host
- Fix API secret minimum length (32 chars required by LiveKit)
- Pass TLS config to LiveKit process manager for TURN certs
2026-03-20 06:11:09 +01:00

41 lines
1007 B
Go

package api
import (
"net/http"
"net/http/httputil"
"net/url"
)
// NewLiveKitProxy creates a reverse proxy handler that forwards requests
// to the LiveKit server. This allows the client to reach LiveKit through
// OwnCord's existing HTTPS server, avoiding mixed-content blocks in
// WebView2 (secure page → insecure WebSocket).
//
// The client connects to wss://server:8443/livekit/ which is proxied to
// ws://localhost:7880/ on the LiveKit server.
func NewLiveKitProxy(livekitURL string) http.Handler {
target, err := url.Parse(livekitURL)
if err != nil {
// Fall back to default if URL is invalid
target, _ = url.Parse("http://localhost:7880")
}
// Convert ws:// to http:// for the proxy target
switch target.Scheme {
case "ws":
target.Scheme = "http"
case "wss":
target.Scheme = "https"
}
proxy := &httputil.ReverseProxy{
Director: func(req *http.Request) {
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.Host = target.Host
},
}
return proxy
}