feat(webrtc): add configurable STUN and TURN servers

Add backend config, RPC handlers, and an HTTP endpoint for WebRTC ICE servers. Replace hardcoded frontend STUN usage with server-provided ICE server configuration, and add access settings UI for STUN and TURN entries.
This commit is contained in:
Augtons
2026-05-03 16:43:29 +08:00
parent d5bfaffd86
commit f1a6c75fc0
12 changed files with 354 additions and 31 deletions

View File

@@ -363,6 +363,18 @@ export default function PCHome() {
try {
console.log("[setupPeerConnection] Creating peer connection");
setLoadingMessage("Creating peer connection...");
let fetchedIceServers: RTCIceServer[] = [];
if (!iceConfig?.iceServers) {
try {
const res = await api.GET("/api/ice-servers");
const data = await res.json();
fetchedIceServers = data.iceServers ?? [];
} catch (e) {
console.error("failed to fetch ICE servers, fallback", e);
fetchedIceServers = [{ urls: ["stun:stun.l.google.com:19302"] }];
}
}
pc = new RTCPeerConnection({
// We only use STUN or TURN servers if we're in the cloud
//...(isInCloud && iceConfig?.iceServers
@@ -370,13 +382,7 @@ export default function PCHome() {
// : {}),
...(iceConfig?.iceServers
? { iceServers: [iceConfig?.iceServers] }
: {
iceServers: [
{
urls: ['stun:stun.l.google.com:19302']
}
]
}),
: { iceServers: fetchedIceServers }),
});
setPeerConnectionState(pc.connectionState);