host our own shit

This commit is contained in:
KingKDot
2026-07-17 16:01:48 -05:00
parent 9a274811e8
commit f404f22b29
16 changed files with 462 additions and 17 deletions
+19 -1
View File
@@ -34,7 +34,8 @@ export class WhepClient {
async start() {
if (this.pc) await this.stop();
const pc = new RTCPeerConnection({});
const iceServers = await this.resolveIceServers();
const pc = new RTCPeerConnection({ iceServers });
this.pc = pc;
this.statsSampler = new WebRTCStatsSampler(pc, this.onStats);
if (this.videoEl) pc.addTransceiver("video", { direction: "recvonly" });
@@ -80,6 +81,23 @@ export class WhepClient {
await pc.setRemoteDescription({ type: "answer", sdp: answerSDP });
}
async resolveIceServers() {
const clientId = new URLSearchParams(window.location.search).get("clientId");
if (!clientId) return [];
try {
const response = await fetch(`/api/webrtc/ice-config?clientId=${encodeURIComponent(clientId)}`, {
credentials: "same-origin",
cache: "no-store",
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const body = await response.json();
return Array.isArray(body?.iceServers) ? body.iceServers : [];
} catch (error) {
console.warn("whep: failed to load self-hosted ICE configuration; using host candidates only", error);
return [];
}
}
async stop() {
const pc = this.pc;
const url = this.resourceURL;